forked from fediversity/fediversity
Compare commits
4 commits
1b898264e4
...
aa877b7678
| Author | SHA1 | Date | |
|---|---|---|---|
| aa877b7678 | |||
| 39f39c3ff7 | |||
| cc8f55b193 | |||
| ce51aa6809 |
2 changed files with 79 additions and 59 deletions
|
|
@ -37,7 +37,7 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
policy =
|
policy =
|
||||||
{ config, ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
_class = "fediversity-resource-policy";
|
_class = "fediversity-resource-policy";
|
||||||
|
|
||||||
|
|
@ -45,10 +45,10 @@ in
|
||||||
extra-config = mkOption {
|
extra-config = mkOption {
|
||||||
description = "Any options from NixOS";
|
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 =
|
policy =
|
||||||
{ config, ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
_class = "fediversity-resource-policy";
|
_class = "fediversity-resource-policy";
|
||||||
options = {
|
options = {
|
||||||
|
|
@ -85,20 +85,20 @@ in
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
};
|
};
|
||||||
apply = mkOption {
|
};
|
||||||
type = with types; functionTo raw; # TODO: splice out the user type from NixOS
|
config = {
|
||||||
default =
|
resource-type = types.raw; # TODO: splice out the user type from NixOS
|
||||||
requests:
|
apply =
|
||||||
|
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";
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -125,15 +125,16 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
environments.single-nixos-vm =
|
environments.single-nixos-vm = environment: {
|
||||||
{ ... }:
|
|
||||||
{
|
|
||||||
_class = "fediversity-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: {
|
implementation = requests: {
|
||||||
_class = "nixos";
|
_class = "nixos";
|
||||||
users.users = (
|
users.users = (
|
||||||
config.resources.login-shell.policy.apply (
|
config.resources.login-shell.policy.apply environment.config.resources.shell.login-shell (
|
||||||
lib.concatMapAttrs (
|
lib.concatMapAttrs (
|
||||||
_application: resources:
|
_application: resources:
|
||||||
lib.mapAttrs (_k: lib.getAttr "login-shell") (
|
lib.mapAttrs (_k: lib.getAttr "login-shell") (
|
||||||
|
|
@ -142,7 +143,6 @@ in
|
||||||
) requests
|
) requests
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -72,11 +72,26 @@ in
|
||||||
type = submoduleWith {
|
type = submoduleWith {
|
||||||
class = "fediversity-resource-policy";
|
class = "fediversity-resource-policy";
|
||||||
modules = [
|
modules = [
|
||||||
{
|
(policy: {
|
||||||
options.apply = mkOption {
|
_class = "fediversity-resource-policy";
|
||||||
description = "Apply the policy to a request";
|
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,23 +148,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 = functionTo environment.config.resource-mapping.output-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";
|
||||||
|
|
@ -165,7 +185,7 @@ in
|
||||||
};
|
};
|
||||||
deployment = mkOption {
|
deployment = mkOption {
|
||||||
description = "Generate a deployment from a configuration";
|
description = "Generate a deployment from a configuration";
|
||||||
type = functionTo (submodule environment.config.resource-mapping.output-type);
|
type = functionTo raw;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default =
|
default =
|
||||||
cfg:
|
cfg:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue