forked from fediversity/fediversity
Compare commits
5 commits
5709d4acc8
...
f80ef23ca1
| Author | SHA1 | Date | |
|---|---|---|---|
| f80ef23ca1 | |||
| b5f6a023f0 | |||
| 777045aae9 | |||
| baee8f1ec0 | |||
| f2a492ff1a |
3 changed files with 49 additions and 91 deletions
|
|
@ -7,15 +7,12 @@ let
|
|||
(lib.evalModules {
|
||||
specialArgs = {
|
||||
inherit inputs;
|
||||
# to be passed to nixops4Deployment
|
||||
resourceProviderSystem = builtins.currentSystem;
|
||||
};
|
||||
modules = [
|
||||
module
|
||||
./data-model.nix
|
||||
];
|
||||
}).config;
|
||||
nixops4Deployment = import ./deployment.nix { inherit inputs; };
|
||||
in
|
||||
{
|
||||
test-eval = {
|
||||
|
|
@ -38,7 +35,7 @@ in
|
|||
};
|
||||
|
||||
policy =
|
||||
{ config, ... }:
|
||||
{ ... }:
|
||||
{
|
||||
_class = "fediversity-resource-policy";
|
||||
|
||||
|
|
@ -48,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 ]);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -73,7 +70,7 @@ in
|
|||
};
|
||||
};
|
||||
policy =
|
||||
{ config, ... }:
|
||||
{ ... }:
|
||||
{
|
||||
_class = "fediversity-resource-policy";
|
||||
options = {
|
||||
|
|
@ -89,16 +86,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; concatMap (request: attrValues request.packages) (attrValues validRequests);
|
||||
extraGroups = lib.optional config.wheel "wheel";
|
||||
extraGroups = lib.optional policy.wheel "wheel";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -124,48 +121,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.login-shell.policy.apply (
|
||||
lib.concatMapAttrs (
|
||||
_application: resources:
|
||||
lib.mapAttrs (_k: lib.getAttr "login-shell") (
|
||||
lib.filterAttrs (_name: value: value ? login-shell) resources
|
||||
)
|
||||
) 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 {
|
||||
|
|
@ -178,10 +153,7 @@ in
|
|||
};
|
||||
};
|
||||
example-deployment = mkOption {
|
||||
type = types.submoduleWith {
|
||||
class = "nixops4Deployment";
|
||||
modules = [ nixops4Deployment ];
|
||||
};
|
||||
type = types.raw;
|
||||
readOnly = true;
|
||||
default = config.environments.single-nixos-vm.deployment config.example-configuration;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
|
|
@ -13,10 +12,10 @@ let
|
|||
submoduleWith
|
||||
optionType
|
||||
functionTo
|
||||
raw
|
||||
;
|
||||
|
||||
functionType = import ./function.nix;
|
||||
nixops4Deployment = import ./deployment.nix { inherit lib inputs; };
|
||||
|
||||
configuration = mkOption {
|
||||
description = "Configuration type declaring options to be set by operators";
|
||||
|
|
@ -130,26 +129,28 @@ 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";
|
||||
type = functionTo (submoduleWith {
|
||||
class = "nixops4Deployment";
|
||||
modules = [ environment.config.resource-mapping.output-type ];
|
||||
});
|
||||
type = functionTo raw;
|
||||
};
|
||||
resource-mapping = mkOption {
|
||||
description = "Function type for the mapping from resources to a (NixOps4) deployment";
|
||||
|
|
@ -160,15 +161,12 @@ in
|
|||
readOnly = true;
|
||||
default = {
|
||||
input-type = configuration;
|
||||
output-type = nixops4Deployment;
|
||||
output-type = raw;
|
||||
};
|
||||
};
|
||||
deployment = mkOption {
|
||||
description = "Generate a deployment from a configuration";
|
||||
type = functionTo (submoduleWith {
|
||||
class = "nixops4Deployment";
|
||||
modules = [ environment.config.resource-mapping.output-type ];
|
||||
});
|
||||
type = functionTo raw;
|
||||
readOnly = true;
|
||||
default =
|
||||
cfg:
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
|
||||
inputs.nixops4.modules.nixops4Deployment.default
|
||||
|
||||
# inherit lib config resources;
|
||||
# # config = {
|
||||
# # type providers provider inputs outputsSkeleton resourceType
|
||||
# # };
|
||||
# }
|
||||
Loading…
Add table
Reference in a new issue