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 39 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 = requests: lib.mkMerge (requests ++ [ config.extra-config ]);
|
default = policy: requests: lib.mkMerge (requests ++ [ policy.extra-config ]);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -70,7 +70,8 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
policy =
|
policy =
|
||||||
{ config, ... }:
|
{ ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
_class = "fediversity-resource-policy";
|
_class = "fediversity-resource-policy";
|
||||||
options = {
|
options = {
|
||||||
|
|
@ -86,16 +87,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 =
|
||||||
requests:
|
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; concatMapAttrs (_name: request: attrValues request.packages) validRequests;
|
packages = with lib; concatMap (request: attrValues request.packages) (attrValues validRequests);
|
||||||
extraGroups = lib.optional config.wheel "wheel";
|
extraGroups = lib.optional policy.wheel "wheel";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -121,15 +122,23 @@ in
|
||||||
dummy.login-shell.packages.hello = pkgs.hello;
|
dummy.login-shell.packages.hello = pkgs.hello;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
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: why do i need to make this explicit, if a default was supposed to be set?
|
||||||
|
};
|
||||||
implementation = requests: {
|
implementation = requests: {
|
||||||
_class = "nixos";
|
_class = "nixos";
|
||||||
users.users = config.resources.login-shell.policy.apply (
|
users.users = (
|
||||||
lib.filterAttrs (_name: value: value ? login-shell) requests
|
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
|
||||||
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -156,20 +165,15 @@ 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;
|
||||||
};
|
};
|
||||||
example-deployment = {
|
num-packages = 1;
|
||||||
_class = "nixos";
|
|
||||||
users.users.operator = {
|
|
||||||
isNormalUser = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,19 +133,24 @@ 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";
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue