forked from fediversity/fediversity
Compare commits
2 commits
dd542cdfae
...
9ba5ddfeda
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ba5ddfeda | |||
| 46f1497531 |
2 changed files with 39 additions and 48 deletions
|
|
@ -35,7 +35,7 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
policy =
|
policy =
|
||||||
{ ... }:
|
{ config, ... }:
|
||||||
{
|
{
|
||||||
_class = "fediversity-resource-policy";
|
_class = "fediversity-resource-policy";
|
||||||
|
|
||||||
|
|
@ -45,7 +45,7 @@ in
|
||||||
};
|
};
|
||||||
apply = mkOption {
|
apply = mkOption {
|
||||||
type = with types; functionTo raw;
|
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 =
|
policy =
|
||||||
{ ... }:
|
{ config, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
_class = "fediversity-resource-policy";
|
_class = "fediversity-resource-policy";
|
||||||
options = {
|
options = {
|
||||||
|
|
@ -87,16 +86,16 @@ in
|
||||||
apply = mkOption {
|
apply = mkOption {
|
||||||
type = with types; functionTo raw; # TODO: splice out the user type from NixOS
|
type = with types; functionTo raw; # TODO: splice out the user type from NixOS
|
||||||
default =
|
default =
|
||||||
policy: requests:
|
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 || policy.wheel) requests;
|
validRequests = lib.filterAttrs (_name: req: !req.wheel || config.wheel) requests;
|
||||||
in
|
in
|
||||||
lib.optionalAttrs (validRequests != { }) {
|
lib.optionalAttrs (validRequests != { }) {
|
||||||
${policy.username} = {
|
${config.username} = {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
packages = with lib; concatMap (request: attrValues request.packages) (attrValues validRequests);
|
packages = with lib; concatMapAttrs (_name: request: attrValues request.packages) validRequests;
|
||||||
extraGroups = lib.optional policy.wheel "wheel";
|
extraGroups = lib.optional config.wheel "wheel";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -122,26 +121,18 @@ in
|
||||||
dummy.login-shell.packages.hello = pkgs.hello;
|
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";
|
_class = "fediversity-environment";
|
||||||
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 (
|
||||||
|
lib.filterAttrs (_name: value: value ? login-shell) requests
|
||||||
|
);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
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 = {
|
options = {
|
||||||
example-configuration = mkOption {
|
example-configuration = mkOption {
|
||||||
|
|
@ -165,15 +156,20 @@ in
|
||||||
{
|
{
|
||||||
inherit (fediversity)
|
inherit (fediversity)
|
||||||
example-configuration
|
example-configuration
|
||||||
|
example-deployment
|
||||||
;
|
;
|
||||||
num-packages = lib.lists.length fediversity.example-deployment.users.users.operator.packages;
|
|
||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
example-configuration = {
|
example-configuration = {
|
||||||
enable = true;
|
enable = true;
|
||||||
applications.hello.enable = true;
|
applications.hello.enable = true;
|
||||||
};
|
};
|
||||||
num-packages = 1;
|
example-deployment = {
|
||||||
|
_class = "nixos";
|
||||||
|
users.users.operator = {
|
||||||
|
isNormalUser = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,24 +133,19 @@ 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
|
||||||
# # FIXME: error: The option `environments.single-nixos-vm.resources.shell.login-shell.apply' does not exist. Definition values:
|
type = attrsOf (
|
||||||
# # - In `<unknown-file>': <function>
|
attrTag (
|
||||||
# # However there are no options defined in `environments.single-nixos-vm.resources.shell.login-shell'. Are you sure you've
|
lib.mapAttrs (
|
||||||
# # declared your options properly? This can happen if you e.g. declared your options in `types.submodule'
|
_name: resource:
|
||||||
# # under `config' rather than `options'.
|
mkOption {
|
||||||
# type = attrsOf (
|
type = submoduleWith {
|
||||||
# attrTag (
|
class = "fediversity-resource-policy";
|
||||||
# lib.mapAttrs (
|
modules = [ resource.policy ];
|
||||||
# _name: resource:
|
};
|
||||||
# mkOption {
|
}
|
||||||
# type = submoduleWith {
|
) config.resources
|
||||||
# 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";
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue