forked from fediversity/fediversity
Compare commits
4 commits
aa877b7678
...
1b898264e4
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b898264e4 | |||
| f90e8d0932 | |||
| 8bae65c4c4 | |||
| 119620eb5e |
3 changed files with 84 additions and 64 deletions
|
|
@ -37,7 +37,7 @@ in
|
|||
};
|
||||
|
||||
policy =
|
||||
{ config, ... }:
|
||||
{ ... }:
|
||||
{
|
||||
_class = "fediversity-resource-policy";
|
||||
|
||||
|
|
@ -45,10 +45,10 @@ in
|
|||
extra-config = mkOption {
|
||||
description = "Any options from NixOS";
|
||||
};
|
||||
apply = mkOption {
|
||||
type = with types; functionTo raw;
|
||||
default = requests: lib.mkMerge (requests ++ [ config.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 ]);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -72,7 +72,7 @@ in
|
|||
};
|
||||
};
|
||||
policy =
|
||||
{ config, ... }:
|
||||
{ ... }:
|
||||
{
|
||||
_class = "fediversity-resource-policy";
|
||||
options = {
|
||||
|
|
@ -85,20 +85,20 @@ in
|
|||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
apply = mkOption {
|
||||
type = with types; functionTo raw; # TODO: splice out the user type from NixOS
|
||||
default =
|
||||
requests:
|
||||
};
|
||||
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
|
||||
validRequests = lib.filterAttrs (_name: req: !req.wheel || config.wheel) requests;
|
||||
validRequests = lib.filterAttrs (_name: req: !req.wheel || policy.wheel) requests;
|
||||
in
|
||||
lib.optionalAttrs (validRequests != { }) {
|
||||
${config.username} = {
|
||||
${policy.username} = {
|
||||
isNormalUser = true;
|
||||
packages = with lib; concatMap (request: attrValues request.packages) (attrValues validRequests);
|
||||
extraGroups = lib.optional config.wheel "wheel";
|
||||
};
|
||||
extraGroups = lib.optional policy.wheel "wheel";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -125,15 +125,16 @@ in
|
|||
};
|
||||
};
|
||||
};
|
||||
environments.single-nixos-vm =
|
||||
{ ... }:
|
||||
{
|
||||
environments.single-nixos-vm = environment: {
|
||||
_class = "fediversity-environment";
|
||||
resources.shell.login-shell.username = "operator";
|
||||
resources.shell.login-shell = {
|
||||
username = "operator";
|
||||
wheel = false; # FIXME: default needs the type uncommented
|
||||
};
|
||||
implementation = requests: {
|
||||
_class = "nixos";
|
||||
users.users = (
|
||||
config.resources.login-shell.policy.apply (
|
||||
config.resources.login-shell.policy.apply environment.config.resources.shell.login-shell (
|
||||
lib.concatMapAttrs (
|
||||
_application: resources:
|
||||
lib.mapAttrs (_k: lib.getAttr "login-shell") (
|
||||
|
|
@ -142,7 +143,6 @@ in
|
|||
) requests
|
||||
)
|
||||
);
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ let
|
|||
attrsOf
|
||||
attrTag
|
||||
deferredModuleWith
|
||||
submodule
|
||||
submoduleWith
|
||||
optionType
|
||||
functionTo
|
||||
|
|
@ -72,11 +73,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;
|
||||
};
|
||||
};
|
||||
})
|
||||
];
|
||||
};
|
||||
};
|
||||
|
|
@ -133,19 +149,24 @@ 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
|
||||
type = attrsOf (
|
||||
attrTag (
|
||||
lib.mapAttrs (
|
||||
_name: resource:
|
||||
mkOption {
|
||||
type = submoduleWith {
|
||||
class = "fediversity-resource-policy";
|
||||
modules = [ resource.policy ];
|
||||
};
|
||||
}
|
||||
) config.resources
|
||||
)
|
||||
);
|
||||
# # 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
|
||||
# )
|
||||
# );
|
||||
};
|
||||
implementation = mkOption {
|
||||
description = "Mapping of resources required by applications to available resources; the result can be deployed";
|
||||
|
|
@ -159,13 +180,13 @@ in
|
|||
};
|
||||
readOnly = true;
|
||||
default = {
|
||||
input-type = configuration;
|
||||
input-type = submodule configuration;
|
||||
output-type = raw;
|
||||
};
|
||||
};
|
||||
deployment = mkOption {
|
||||
description = "Generate a deployment from a configuration";
|
||||
type = functionTo (submodule environment.config.resource-mapping.output-type);
|
||||
type = functionTo environment.config.resource-mapping.output-type;
|
||||
readOnly = true;
|
||||
default =
|
||||
cfg:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
let
|
||||
inherit (lib) mkOption types;
|
||||
inherit (types)
|
||||
deferredModule
|
||||
submodule
|
||||
functionTo
|
||||
optionType
|
||||
|
|
@ -14,10 +13,10 @@ in
|
|||
{
|
||||
options = {
|
||||
input-type = mkOption {
|
||||
type = deferredModule;
|
||||
type = optionType;
|
||||
};
|
||||
output-type = mkOption {
|
||||
type = deferredModule;
|
||||
type = optionType;
|
||||
};
|
||||
function-type = mkOption {
|
||||
type = optionType;
|
||||
|
|
@ -25,10 +24,10 @@ in
|
|||
default = functionTo (submodule {
|
||||
options = {
|
||||
input = mkOption {
|
||||
type = submodule config.input-type;
|
||||
type = config.input-type;
|
||||
};
|
||||
output = mkOption {
|
||||
type = submodule config.output-type;
|
||||
type = config.output-type;
|
||||
};
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue