Compare commits

..

2 commits

Author SHA1 Message Date
d713083feb
WIP: more type-safe policy application 2025-07-27 11:42:33 +02:00
4194d72f56
readability 2025-07-27 11:05:18 +02:00
2 changed files with 41 additions and 24 deletions

View file

@ -45,10 +45,10 @@ in
extra-config = mkOption {
description = "Any options from NixOS";
};
apply = mkOption {
type = with types; functionTo raw;
default = policy: requests: lib.mkMerge (requests ++ [ policy.extra-config ]);
};
config = {
resource-type = types.raw; # TODO: what's the type of a NixOS configuration?
apply = policy: requests: lib.mkMerge (requests ++ [ policy.extra-config ]);
};
};
};
@ -85,9 +85,10 @@ in
type = types.bool;
default = false;
};
apply = mkOption {
type = with types; functionTo raw; # TODO: splice out the user type from NixOS
default =
};
config = {
resource-type = types.raw; # TODO: splice out the user type from NixOS
apply =
policy: requests:
let
# Filter out requests that need wheel if policy doesn't allow it
@ -103,7 +104,6 @@ in
};
};
};
};
applications.hello =
{ ... }:
{
@ -120,7 +120,9 @@ in
resources =
cfg:
lib.optionalAttrs cfg.enable {
dummy.login-shell.packages.hello = pkgs.hello;
hello.login-shell.packages = {
inherit (pkgs) hello;
};
};
};
environments.single-nixos-vm = environment: {

View file

@ -72,11 +72,26 @@ in
type = submoduleWith {
class = "fediversity-resource-policy";
modules = [
{
options.apply = mkOption {
description = "Apply the policy to a request";
(policy: {
_class = "fediversity-resource-policy";
options = {
# TODO(@fricklerhandwerk): not sure it can be made
# sensible syntactically, but essentially we want to
# ensure that `apply` is defined, but since its output
# depends on the specific policy we also need to
# determine that somehow.
# hopefully this also helps with correct composition down the line.
resource-type = mkOption {
description = "The type of resource this policy configures";
type = types.optionType;
};
}
# TODO(@fricklerhandwerk): do we need a function type here as well, or is it in the way?
apply = mkOption {
description = "Apply the policy to a request";
type = functionTo policy.config.resource-type;
};
};
})
];
};
};