Compare commits

...

18 commits

Author SHA1 Message Date
41624cc59b
[HACK] comment environment resources type, making the test go through 2025-07-22 19:05:38 +02:00
fe7cc67c6b
[HACK] explicitly set resource options, as defaults seem insufficient 2025-07-22 19:05:38 +02:00
574dea2d99
[HACK] explicitly pass instantiated policy to apply 2025-07-22 19:05:38 +02:00
d3d892bcfc
[HACK] unwire deployment resource-mapping output-type, fixes error: Expected a module, but found a value of type "option-type" 2025-07-22 19:05:38 +02:00
6625e94b2d
[HACK] swap out nixops4 deployments for raw nixos modules
rm deployment

rm imports
2025-07-22 19:05:38 +02:00
c486682657
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:05:38 +02:00
7240bb455f
swap out dummy module for actual import
clean deployment module a bit

simplify imports
2025-07-22 19:05:38 +02:00
55483570e0
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:05:38 +02:00
7185c04ddd
environment: fix implementation type 2025-07-22 19:05:38 +02:00
c528135040
pass resourceProviderSystem to nixops4Deployment 2025-07-22 19:05:38 +02:00
4952c65af1
resolve resource mapping input discrepancy according to actual implementation, adjusting the type accordingly 2025-07-22 19:05:38 +02:00
218802214e
properly flatten out application layer at users.users 2025-07-22 19:05:38 +02:00
f43ef615dd
fix application resource type 2025-07-22 19:05:38 +02:00
7cf873e789
fix application-requirements 2025-07-22 19:05:38 +02:00
25006c149d
untangle applications from function type, as they seem to not need the introspection (and may type-check input without it) 2025-07-22 19:05:38 +02:00
0b56a3f197
make packages filter return a list 2025-07-22 19:05:38 +02:00
458058be55
add trivial unit test for deployment - now to find how to make it work!
test proper expectation

test proper expectation

settle for counting packages over comparing them, solves an infinite recursion
2025-07-22 19:05:38 +02:00
75ad6e691e
fix environment deployment 2025-07-22 19:05:38 +02:00
3 changed files with 96 additions and 125 deletions

View file

@ -11,7 +11,6 @@ let
; ;
inherit (pkgs) lib; inherit (pkgs) lib;
inherit (import sources.flake-inputs) import-flake; inherit (import sources.flake-inputs) import-flake;
inputs = (import-flake { src = ./.; }).inputs;
inherit ((import-flake { src = ./.; }).inputs) nixops4; inherit ((import-flake { src = ./.; }).inputs) nixops4;
panel = import ./panel { inherit sources system; }; panel = import ./panel { inherit sources system; };
pre-commit-check = pre-commit-check =
@ -79,7 +78,6 @@ in
# re-export inputs so they can be overridden granularly # re-export inputs so they can be overridden granularly
# (they can't be accessed from the outside any other way) # (they can't be accessed from the outside any other way)
inherit inherit
inputs
sources sources
system system
pkgs pkgs

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; concatMapAttrs (_name: request: attrValues request.packages) validRequests; packages = with lib; concatMap (request: attrValues request.packages) (attrValues validRequests);
extraGroups = lib.optional config.wheel "wheel"; extraGroups = lib.optional policy.wheel "wheel";
}; };
}; };
}; };
@ -116,42 +115,32 @@ in
enable = lib.mkEnableOption "Hello in the shell"; enable = lib.mkEnableOption "Hello in the shell";
}; };
}; };
implementation = resources =
cfg: cfg:
lib.optionalAttrs cfg.enable { lib.optionalAttrs cfg.enable {
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";
{ resources.shell.login-shell = {
_class = "fediversity-environment"; username = "operator";
resources.shell.login-shell.username = "operator"; wheel = false; # FIXME: why do i need to make this explicit, if a default was supposed to be set?
implementation =
requests:
{ providers, ... }:
{
_class = "nixops4Deployment";
providers = {
inherit (inputs.nixops4.modules.nixops4Provider) local;
};
resources.the-machine = {
_class = "nixops4Resource";
type = providers.local.exec;
imports = [
inputs.nixops4-nixos.modules.nixops4Resource.nixos
];
nixos.module =
{ ... }:
{
_class = "nixos";
users.users = config.resources.shell.login-shell.apply (
lib.filterAttrs (_name: value: value ? login-shell) requests
);
};
};
};
}; };
implementation = requests: {
_class = "nixos";
users.users = (
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 {
@ -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;
}; };
@ -179,12 +165,14 @@ in
inherit (fediversity) inherit (fediversity)
example-configuration example-configuration
; ;
num-packages = lib.lists.length fediversity.example-deployment.users.users.operator.packages;
}; };
expected = { expected = {
example-configuration = { example-configuration = {
enable = true; enable = true;
applications.hello.enable = true; applications.hello.enable = true;
}; };
num-packages = 1;
}; };
}; };
} }

View file

@ -1,7 +1,6 @@
{ {
lib, lib,
config, config,
inputs,
... ...
}: }:
let let
@ -13,23 +12,44 @@ let
submoduleWith submoduleWith
optionType optionType
functionTo functionTo
raw
; ;
functionType = import ./function.nix; functionType = import ./function.nix;
application-requirements = {
_class = "fediversity-application-requirements"; configuration = mkOption {
options.resources = mkOption { description = "Configuration type declaring options to be set by operators";
# TODO: maybe transpose, and group the resources by type instead type = optionType;
type = attrsOf ( readOnly = true;
attrTag (lib.mapAttrs (_name: resource: mkOption { type = resource.request; }) config.resources) 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;
};
}
];
}; };
}; };
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
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 {
@ -71,7 +91,7 @@ in
type = attrsOf (submoduleWith { type = attrsOf (submoduleWith {
class = "fediversity-application"; class = "fediversity-application";
modules = [ modules = [
(application: { {
options = { options = {
description = mkOption { description = mkOption {
description = "Description to be shown in the application overview"; description = "Description to be shown in the application overview";
@ -81,30 +101,21 @@ in
description = "Operator-facing configuration options for the application"; description = "Operator-facing configuration options for the application";
type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; }; type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; };
}; };
implementation = mkOption {
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
type = application.config.config-mapping.function-type;
};
resources = mkOption { resources = mkOption {
description = "Compute resources required by an application"; description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
type = functionTo application.config.config-mapping.output-type; # TODO: maybe transpose, and group the resources by type instead
readOnly = true; type = functionTo (
default = input: (application.config.implementation input).output; attrsOf (
}; attrTag (
config-mapping = mkOption { lib.mapAttrs (
description = "Function type for the mapping from application configuration to required resources"; _name: resource: mkOption { type = types.submodule resource.request; }
type = submoduleWith { ) config.resources
class = "module-function"; )
modules = [ functionType ]; )
}; );
readOnly = true;
default = {
input-type = application.config.module;
output-type = application-requirements;
};
}; };
}; };
}) }
]; ];
}); });
}; };
@ -122,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";
@ -148,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:
@ -167,7 +180,7 @@ in
name: application-settings: config.applications.${name}.resources application-settings name: application-settings: config.applications.${name}.resources application-settings
) cfg.applications; ) cfg.applications;
in in
(environment.config.implementation required-resources).output; (environment.config.implementation required-resources);
}; };
}; };
@ -175,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;
};
}
];
};
};
}; };
} }