Compare commits

...

13 commits

Author SHA1 Message Date
1f2b2da9c2
[HACK] comment environment resources type, making the test go through 2025-07-22 19:01:10 +02:00
b8fbd42e8d
[HACK] explicitly set resource options, as defaults seem insufficient 2025-07-22 19:01:10 +02:00
96e0f97dd8
[HACK] explicitly pass instantiated policy to apply 2025-07-22 19:01:10 +02:00
4527ed6824
[HACK] unwire deployment resource-mapping output-type, fixes error: Expected a module, but found a value of type "option-type" 2025-07-22 19:01:10 +02:00
c0e0589f37
[HACK] swap out nixops4 deployments for raw nixos modules
rm deployment
2025-07-22 19:01:10 +02:00
ce81b0cbd1
reproduce nixops4-nixos importing issue: The option environments.single-nixos-vm.deployment.<function body>.resources.the-machine.nixos' does not exist`
add comment explaining our nixops4 type problem
2025-07-22 19:01:10 +02:00
aabd96dbce
swap out dummy module for actual import
clean deployment module a bit

simplify imports
2025-07-22 19:01:10 +02:00
a750388afd
model: [DUMMY] use mock deployment to temporarily simplify the problem
type policy.apply

remove `apply`'s optionType, fixes duplicate definition error
2025-07-22 19:01:10 +02:00
ec66534992
environment: fix implementation type 2025-07-22 19:01:10 +02:00
42a275d7fe
pass resourceProviderSystem to nixops4Deployment 2025-07-22 19:01:10 +02:00
2c0910427a
resolve resource mapping input discrepancy according to actual implementation, adjusting the type accordingly 2025-07-22 19:01:10 +02:00
3faa47570b
properly flatten out application layer at users.users 2025-07-22 19:01:10 +02:00
439ca6d13c
fix application resource type 2025-07-22 19:01:10 +02:00
2 changed files with 85 additions and 92 deletions

View file

@ -13,7 +13,6 @@ let
./data-model.nix ./data-model.nix
]; ];
}).config; }).config;
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
in in
{ {
test-eval = { test-eval = {
@ -36,7 +35,7 @@ in
}; };
policy = policy =
{ config, ... }: { ... }:
{ {
_class = "fediversity-resource-policy"; _class = "fediversity-resource-policy";
@ -46,7 +45,7 @@ in
}; };
apply = mkOption { apply = mkOption {
type = with types; functionTo raw; type = with types; functionTo raw;
default = requests: lib.mkMerge (requests ++ [ config.extra-config ]); default = policy: requests: lib.mkMerge (requests ++ [ policy.extra-config ]);
}; };
}; };
}; };
@ -71,7 +70,7 @@ in
}; };
}; };
policy = policy =
{ config, ... }: { ... }:
{ {
_class = "fediversity-resource-policy"; _class = "fediversity-resource-policy";
options = { options = {
@ -87,16 +86,16 @@ in
apply = mkOption { apply = mkOption {
type = with types; functionTo raw; # TODO: splice out the user type from NixOS type = with types; functionTo raw; # TODO: splice out the user type from NixOS
default = default =
requests: policy: requests:
let let
# Filter out requests that need wheel if policy doesn't allow it # Filter out requests that need wheel if policy doesn't allow it
validRequests = lib.filterAttrs (_name: req: !req.wheel || config.wheel) requests; validRequests = lib.filterAttrs (_name: req: !req.wheel || policy.wheel) requests;
in in
lib.optionalAttrs (validRequests != { }) { lib.optionalAttrs (validRequests != { }) {
${config.username} = { ${policy.username} = {
isNormalUser = true; isNormalUser = true;
packages = with lib; concatMap (request: attrValues request.packages) (attrValues validRequests); packages = with lib; concatMap (request: attrValues request.packages) (attrValues validRequests);
extraGroups = lib.optional config.wheel "wheel"; extraGroups = lib.optional policy.wheel "wheel";
}; };
}; };
}; };
@ -122,37 +121,27 @@ in
dummy.login-shell.packages.hello = pkgs.hello; dummy.login-shell.packages.hello = pkgs.hello;
}; };
}; };
environments.single-nixos-vm = environments.single-nixos-vm = environment: {
{ config, ... }:
{
_class = "fediversity-environment"; _class = "fediversity-environment";
resources.shell.login-shell.username = "operator"; resources.shell.login-shell = {
implementation = username = "operator";
requests: wheel = false; # FIXME: why do i need to make this explicit, if a default was supposed to be set?
{ providers, ... }:
{
_class = "nixops4Deployment";
providers = {
inherit (inputs.nixops4.modules.nixops4Provider) local;
}; };
resources.the-machine = { implementation = requests: {
_class = "nixops4Resource";
type = providers.local.exec;
imports = [
inputs.nixops4-nixos.modules.nixops4Resource.nixos
];
nixos.module =
{ ... }:
{
_class = "nixos"; _class = "nixos";
users.users = config.resources.shell.login-shell.apply ( users.users = (
lib.filterAttrs (_name: value: value ? login-shell) requests config.resources.login-shell.policy.apply environment.config.resources.shell.login-shell (
lib.concatMapAttrs (
_application: resources:
lib.mapAttrs (_k: lib.getAttr "login-shell") (
lib.filterAttrs (_name: value: value ? login-shell) resources
)
) requests
)
); );
}; };
}; };
}; };
};
};
options = { options = {
example-configuration = mkOption { example-configuration = mkOption {
type = config.configuration; type = config.configuration;
@ -164,10 +153,7 @@ in
}; };
}; };
example-deployment = mkOption { example-deployment = mkOption {
type = types.submoduleWith { type = types.raw;
class = "nixops4Deployment";
modules = [ nixops4Deployment ];
};
readOnly = true; readOnly = true;
default = config.environments.single-nixos-vm.deployment config.example-configuration; default = config.environments.single-nixos-vm.deployment config.example-configuration;
}; };

View file

@ -1,7 +1,6 @@
{ {
lib, lib,
config, config,
inputs,
... ...
}: }:
let let
@ -13,14 +12,44 @@ let
submoduleWith submoduleWith
optionType optionType
functionTo functionTo
raw
; ;
functionType = import ./function.nix; functionType = import ./function.nix;
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
configuration = mkOption {
description = "Configuration type declaring options to be set by operators";
type = optionType;
readOnly = true;
default = submoduleWith {
class = "fediversity-configuration";
modules = [
{
options = {
enable = lib.mkEnableOption {
description = "your Fediversity configuration";
};
applications = lib.mapAttrs (
_name: application:
mkOption {
description = application.description;
type = submoduleWith {
class = "fediversity-application-config";
modules = [ application.module ];
};
default = { };
}
) config.applications;
};
}
];
};
};
in in
{ {
_class = "fediversity-settings"; _class = "fediversity-settings";
options = { options = {
inherit configuration;
resources = mkOption { resources = mkOption {
description = "Collection of deployment resources that can be required by applications and policed by hosting providers"; description = "Collection of deployment resources that can be required by applications and policed by hosting providers";
type = attrsOf (submoduleWith { type = attrsOf (submoduleWith {
@ -77,7 +106,11 @@ in
# TODO: maybe transpose, and group the resources by type instead # TODO: maybe transpose, and group the resources by type instead
type = functionTo ( type = functionTo (
attrsOf ( attrsOf (
attrTag (lib.mapAttrs (_name: resource: mkOption { type = resource.request; }) config.resources) attrTag (
lib.mapAttrs (
_name: resource: mkOption { type = types.submodule resource.request; }
) config.resources
)
) )
); );
}; };
@ -100,23 +133,28 @@ in
Setting this is optional, but provides a place to declare that information for programmatic use in the resource mapping. Setting this is optional, but provides a place to declare that information for programmatic use in the resource mapping.
''; '';
# TODO: maybe transpose, and group the resources by type instead # TODO: maybe transpose, and group the resources by type instead
type = attrsOf ( # # FIXME: error: The option `environments.single-nixos-vm.resources.shell.login-shell.apply' does not exist. Definition values:
attrTag ( # # - In `<unknown-file>': <function>
lib.mapAttrs ( # # However there are no options defined in `environments.single-nixos-vm.resources.shell.login-shell'. Are you sure you've
_name: resource: # # declared your options properly? This can happen if you e.g. declared your options in `types.submodule'
mkOption { # # under `config' rather than `options'.
type = submoduleWith { # type = attrsOf (
class = "fediversity-resource-policy"; # attrTag (
modules = [ resource.policy ]; # lib.mapAttrs (
}; # _name: resource:
} # mkOption {
) config.resources # type = submoduleWith {
) # class = "fediversity-resource-policy";
); # modules = [ resource.policy ];
# };
# }
# ) config.resources
# )
# );
}; };
implementation = mkOption { implementation = mkOption {
description = "Mapping of resources required by applications to available resources; the result can be deployed"; description = "Mapping of resources required by applications to available resources; the result can be deployed";
type = environment.config.resource-mapping.function-type; type = functionTo raw;
}; };
resource-mapping = mkOption { resource-mapping = mkOption {
description = "Function type for the mapping from resources to a (NixOps4) deployment"; description = "Function type for the mapping from resources to a (NixOps4) deployment";
@ -126,16 +164,13 @@ in
}; };
readOnly = true; readOnly = true;
default = { default = {
input-type = application-requirements; input-type = configuration;
output-type = nixops4Deployment; output-type = raw;
}; };
}; };
deployment = mkOption { deployment = mkOption {
description = "Generate a deployment from a configuration"; description = "Generate a deployment from a configuration";
type = functionTo (submoduleWith { type = functionTo raw;
class = "nixops4Deployment";
modules = [ environment.config.resource-mapping.output-type ];
});
readOnly = true; readOnly = true;
default = default =
cfg: cfg:
@ -153,33 +188,5 @@ in
]; ];
}); });
}; };
configuration = mkOption {
description = "Configuration type declaring options to be set by operators";
type = optionType;
readOnly = true;
default = submoduleWith {
class = "fediversity-configuration";
modules = [
{
options = {
enable = lib.mkEnableOption {
description = "your Fediversity configuration";
};
applications = lib.mapAttrs (
_name: application:
mkOption {
description = application.description;
type = submoduleWith {
class = "fediversity-application-config";
modules = [ application.module ];
};
default = { };
}
) config.applications;
};
}
];
};
};
}; };
} }