forked from fediversity/fediversity
Compare commits
8 commits
9ba5ddfeda
...
dd542cdfae
| Author | SHA1 | Date | |
|---|---|---|---|
| dd542cdfae | |||
| 7bdbaf61d8 | |||
| 864010a4be | |||
| 4d69cd6024 | |||
| 76ee37c10e | |||
| 55546b50b1 | |||
| 4a7b9f0f72 | |||
| 0c1628e8e1 |
2 changed files with 48 additions and 57 deletions
|
|
@ -35,7 +35,7 @@ in
|
|||
};
|
||||
|
||||
policy =
|
||||
{ config, ... }:
|
||||
{ ... }:
|
||||
{
|
||||
_class = "fediversity-resource-policy";
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ in
|
|||
};
|
||||
apply = mkOption {
|
||||
type = with types; functionTo raw;
|
||||
default = requests: lib.mkMerge (requests ++ [ config.extra-config ]);
|
||||
default = policy: requests: lib.mkMerge (requests ++ [ policy.extra-config ]);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -70,7 +70,8 @@ in
|
|||
};
|
||||
};
|
||||
policy =
|
||||
{ config, ... }:
|
||||
{ ... }:
|
||||
|
||||
{
|
||||
_class = "fediversity-resource-policy";
|
||||
options = {
|
||||
|
|
@ -86,16 +87,16 @@ in
|
|||
apply = mkOption {
|
||||
type = with types; functionTo raw; # TODO: splice out the user type from NixOS
|
||||
default =
|
||||
requests:
|
||||
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; concatMapAttrs (_name: request: attrValues request.packages) validRequests;
|
||||
extraGroups = lib.optional config.wheel "wheel";
|
||||
packages = with lib; concatMap (request: attrValues request.packages) (attrValues validRequests);
|
||||
extraGroups = lib.optional policy.wheel "wheel";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -121,41 +122,26 @@ in
|
|||
dummy.login-shell.packages.hello = pkgs.hello;
|
||||
};
|
||||
};
|
||||
environments.single-nixos-vm =
|
||||
{ ... }:
|
||||
{
|
||||
_class = "fediversity-environment";
|
||||
resources.shell.login-shell.username = "operator";
|
||||
implementation =
|
||||
_requests:
|
||||
{ providers, ... }:
|
||||
{
|
||||
_class = "nixops4Deployment";
|
||||
providers = {
|
||||
inherit (inputs.nixops4.modules.nixops4Provider) local;
|
||||
};
|
||||
# this seems checked according to {providers,resources,resource}.nix,
|
||||
# values will not eagerly get checked, matching `providers.nix`'s `lazyAttrsOf`,
|
||||
# whereas allowed keys seem to match those defined in `resource.nix`.
|
||||
# the content of `resources.the-machine` however, follows `nixops4-nixos`,
|
||||
# which is not allowed through our `type` yet.
|
||||
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
|
||||
# );
|
||||
# };
|
||||
};
|
||||
};
|
||||
environments.single-nixos-vm = environment: {
|
||||
_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?
|
||||
};
|
||||
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 = {
|
||||
example-configuration = mkOption {
|
||||
|
|
@ -180,14 +166,14 @@ in
|
|||
inherit (fediversity)
|
||||
example-configuration
|
||||
;
|
||||
has-deployment = lib.isAttrs fediversity.example-deployment.resources.the-machine;
|
||||
num-packages = lib.lists.length fediversity.example-deployment.users.users.operator.packages;
|
||||
};
|
||||
expected = {
|
||||
example-configuration = {
|
||||
enable = true;
|
||||
applications.hello.enable = true;
|
||||
};
|
||||
has-deployment = true;
|
||||
num-packages = 1;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,19 +133,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";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue