forked from fediversity/fediversity
Compare commits
12 commits
1f2b2da9c2
...
f80ef23ca1
| Author | SHA1 | Date | |
|---|---|---|---|
| f80ef23ca1 | |||
| b5f6a023f0 | |||
| 777045aae9 | |||
| baee8f1ec0 | |||
| f2a492ff1a | |||
| ccbe6d9e83 | |||
| d836e2294f | |||
| 4b9cf35e88 | |||
| 532f87b2ff | |||
| a3b5b8b2fe | |||
| cbfdeb0cd7 | |||
| e8551f2cc3 |
2 changed files with 80 additions and 91 deletions
|
|
@ -13,7 +13,6 @@ let
|
||||||
./data-model.nix
|
./data-model.nix
|
||||||
];
|
];
|
||||||
}).config;
|
}).config;
|
||||||
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
test-eval = {
|
test-eval = {
|
||||||
|
|
@ -36,7 +35,7 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
policy =
|
policy =
|
||||||
{ config, ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
_class = "fediversity-resource-policy";
|
_class = "fediversity-resource-policy";
|
||||||
|
|
||||||
|
|
@ -46,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 ]);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -71,7 +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 =
|
||||||
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; 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";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -122,37 +121,27 @@ in
|
||||||
dummy.login-shell.packages.hello = pkgs.hello;
|
dummy.login-shell.packages.hello = pkgs.hello;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
environments.single-nixos-vm =
|
environments.single-nixos-vm = environment: {
|
||||||
{ config, ... }:
|
|
||||||
{
|
|
||||||
_class = "fediversity-environment";
|
_class = "fediversity-environment";
|
||||||
resources.shell.login-shell.username = "operator";
|
resources.shell.login-shell = {
|
||||||
implementation =
|
username = "operator";
|
||||||
requests:
|
wheel = false; # FIXME: why do i need to make this explicit, if a default was supposed to be set?
|
||||||
{ providers, ... }:
|
|
||||||
{
|
|
||||||
_class = "nixops4Deployment";
|
|
||||||
providers = {
|
|
||||||
inherit (inputs.nixops4.modules.nixops4Provider) local;
|
|
||||||
};
|
};
|
||||||
resources.the-machine = {
|
implementation = requests: {
|
||||||
_class = "nixops4Resource";
|
|
||||||
type = providers.local.exec;
|
|
||||||
imports = [
|
|
||||||
inputs.nixops4-nixos.modules.nixops4Resource.nixos
|
|
||||||
];
|
|
||||||
nixos.module =
|
|
||||||
{ ... }:
|
|
||||||
{
|
|
||||||
_class = "nixos";
|
_class = "nixos";
|
||||||
users.users = config.resources.shell.login-shell.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
|
||||||
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
};
|
|
||||||
options = {
|
options = {
|
||||||
example-configuration = mkOption {
|
example-configuration = mkOption {
|
||||||
type = config.configuration;
|
type = config.configuration;
|
||||||
|
|
@ -164,10 +153,7 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
example-deployment = mkOption {
|
example-deployment = mkOption {
|
||||||
type = types.submoduleWith {
|
type = types.raw;
|
||||||
class = "nixops4Deployment";
|
|
||||||
modules = [ nixops4Deployment ];
|
|
||||||
};
|
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default = config.environments.single-nixos-vm.deployment config.example-configuration;
|
default = config.environments.single-nixos-vm.deployment config.example-configuration;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
config,
|
config,
|
||||||
inputs,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
|
@ -13,14 +12,44 @@ let
|
||||||
submoduleWith
|
submoduleWith
|
||||||
optionType
|
optionType
|
||||||
functionTo
|
functionTo
|
||||||
|
raw
|
||||||
;
|
;
|
||||||
|
|
||||||
functionType = import ./function.nix;
|
functionType = import ./function.nix;
|
||||||
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
|
|
||||||
|
configuration = mkOption {
|
||||||
|
description = "Configuration type declaring options to be set by operators";
|
||||||
|
type = optionType;
|
||||||
|
readOnly = true;
|
||||||
|
default = submoduleWith {
|
||||||
|
class = "fediversity-configuration";
|
||||||
|
modules = [
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
enable = lib.mkEnableOption {
|
||||||
|
description = "your Fediversity configuration";
|
||||||
|
};
|
||||||
|
applications = lib.mapAttrs (
|
||||||
|
_name: application:
|
||||||
|
mkOption {
|
||||||
|
description = application.description;
|
||||||
|
type = submoduleWith {
|
||||||
|
class = "fediversity-application-config";
|
||||||
|
modules = [ application.module ];
|
||||||
|
};
|
||||||
|
default = { };
|
||||||
|
}
|
||||||
|
) config.applications;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
_class = "fediversity-settings";
|
_class = "fediversity-settings";
|
||||||
options = {
|
options = {
|
||||||
|
inherit configuration;
|
||||||
resources = mkOption {
|
resources = mkOption {
|
||||||
description = "Collection of deployment resources that can be required by applications and policed by hosting providers";
|
description = "Collection of deployment resources that can be required by applications and policed by hosting providers";
|
||||||
type = attrsOf (submoduleWith {
|
type = attrsOf (submoduleWith {
|
||||||
|
|
@ -100,23 +129,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 = environment.config.resource-mapping.function-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";
|
||||||
|
|
@ -126,16 +160,13 @@ in
|
||||||
};
|
};
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default = {
|
default = {
|
||||||
input-type = application-requirements;
|
input-type = configuration;
|
||||||
output-type = nixops4Deployment;
|
output-type = raw;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
deployment = mkOption {
|
deployment = mkOption {
|
||||||
description = "Generate a deployment from a configuration";
|
description = "Generate a deployment from a configuration";
|
||||||
type = functionTo (submoduleWith {
|
type = functionTo raw;
|
||||||
class = "nixops4Deployment";
|
|
||||||
modules = [ environment.config.resource-mapping.output-type ];
|
|
||||||
});
|
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default =
|
default =
|
||||||
cfg:
|
cfg:
|
||||||
|
|
@ -153,33 +184,5 @@ in
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
configuration = mkOption {
|
|
||||||
description = "Configuration type declaring options to be set by operators";
|
|
||||||
type = optionType;
|
|
||||||
readOnly = true;
|
|
||||||
default = submoduleWith {
|
|
||||||
class = "fediversity-configuration";
|
|
||||||
modules = [
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
enable = lib.mkEnableOption {
|
|
||||||
description = "your Fediversity configuration";
|
|
||||||
};
|
|
||||||
applications = lib.mapAttrs (
|
|
||||||
_name: application:
|
|
||||||
mkOption {
|
|
||||||
description = application.description;
|
|
||||||
type = submoduleWith {
|
|
||||||
class = "fediversity-application-config";
|
|
||||||
modules = [ application.module ];
|
|
||||||
};
|
|
||||||
default = { };
|
|
||||||
}
|
|
||||||
) config.applications;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue