Compare commits

..

2 commits

Author SHA1 Message Date
9ba5ddfeda
swap out nixops4 from implementation 2025-07-22 15:10:24 +02:00
46f1497531
test proper expectation 2025-07-22 14:58:24 +02:00
2 changed files with 39 additions and 48 deletions

View file

@ -35,7 +35,7 @@ in
};
policy =
{ ... }:
{ config, ... }:
{
_class = "fediversity-resource-policy";
@ -45,7 +45,7 @@ in
};
apply = mkOption {
type = with types; functionTo raw;
default = policy: requests: lib.mkMerge (requests ++ [ policy.extra-config ]);
default = requests: lib.mkMerge (requests ++ [ config.extra-config ]);
};
};
};
@ -70,8 +70,7 @@ in
};
};
policy =
{ ... }:
{ config, ... }:
{
_class = "fediversity-resource-policy";
options = {
@ -87,16 +86,16 @@ in
apply = mkOption {
type = with types; functionTo raw; # TODO: splice out the user type from NixOS
default =
policy: requests:
requests:
let
# Filter out requests that need wheel if policy doesn't allow it
validRequests = lib.filterAttrs (_name: req: !req.wheel || policy.wheel) requests;
validRequests = lib.filterAttrs (_name: req: !req.wheel || config.wheel) requests;
in
lib.optionalAttrs (validRequests != { }) {
${policy.username} = {
${config.username} = {
isNormalUser = true;
packages = with lib; concatMap (request: attrValues request.packages) (attrValues validRequests);
extraGroups = lib.optional policy.wheel "wheel";
packages = with lib; concatMapAttrs (_name: request: attrValues request.packages) validRequests;
extraGroups = lib.optional config.wheel "wheel";
};
};
};
@ -122,23 +121,15 @@ in
dummy.login-shell.packages.hello = pkgs.hello;
};
};
environments.single-nixos-vm = environment: {
environments.single-nixos-vm =
{ ... }:
{
_class = "fediversity-environment";
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?
};
resources.shell.login-shell.username = "operator";
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
)
users.users = config.resources.login-shell.policy.apply (
lib.filterAttrs (_name: value: value ? login-shell) requests
);
};
};
@ -165,15 +156,20 @@ in
{
inherit (fediversity)
example-configuration
example-deployment
;
num-packages = lib.lists.length fediversity.example-deployment.users.users.operator.packages;
};
expected = {
example-configuration = {
enable = true;
applications.hello.enable = true;
};
num-packages = 1;
example-deployment = {
_class = "nixos";
users.users.operator = {
isNormalUser = true;
};
};
};
};
}

View file

@ -133,24 +133,19 @@ in
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
# # FIXME: error: The option `environments.single-nixos-vm.resources.shell.login-shell.apply' does not exist. Definition values:
# # - In `<unknown-file>': <function>
# # However there are no options defined in `environments.single-nixos-vm.resources.shell.login-shell'. Are you sure you've
# # declared your options properly? This can happen if you e.g. declared your options in `types.submodule'
# # under `config' rather than `options'.
# type = attrsOf (
# attrTag (
# lib.mapAttrs (
# _name: resource:
# mkOption {
# type = submoduleWith {
# class = "fediversity-resource-policy";
# modules = [ resource.policy ];
# };
# }
# ) config.resources
# )
# );
type = attrsOf (
attrTag (
lib.mapAttrs (
_name: resource:
mkOption {
type = submoduleWith {
class = "fediversity-resource-policy";
modules = [ resource.policy ];
};
}
) config.resources
)
);
};
implementation = mkOption {
description = "Mapping of resources required by applications to available resources; the result can be deployed";