forked from fediversity/fediversity
Compare commits
18 commits
1f2b2da9c2
...
41624cc59b
| Author | SHA1 | Date | |
|---|---|---|---|
| 41624cc59b | |||
| fe7cc67c6b | |||
| 574dea2d99 | |||
| d3d892bcfc | |||
| 6625e94b2d | |||
| c486682657 | |||
| 7240bb455f | |||
| 55483570e0 | |||
| 7185c04ddd | |||
| c528135040 | |||
| 4952c65af1 | |||
| 218802214e | |||
| f43ef615dd | |||
| 7cf873e789 | |||
| 25006c149d | |||
| 0b56a3f197 | |||
| 458058be55 | |||
| 75ad6e691e |
3 changed files with 96 additions and 125 deletions
|
|
@ -11,7 +11,6 @@ let
|
|||
;
|
||||
inherit (pkgs) lib;
|
||||
inherit (import sources.flake-inputs) import-flake;
|
||||
inputs = (import-flake { src = ./.; }).inputs;
|
||||
inherit ((import-flake { src = ./.; }).inputs) nixops4;
|
||||
panel = import ./panel { inherit sources system; };
|
||||
pre-commit-check =
|
||||
|
|
@ -79,7 +78,6 @@ in
|
|||
# re-export inputs so they can be overridden granularly
|
||||
# (they can't be accessed from the outside any other way)
|
||||
inherit
|
||||
inputs
|
||||
sources
|
||||
system
|
||||
pkgs
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ let
|
|||
./data-model.nix
|
||||
];
|
||||
}).config;
|
||||
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
|
||||
in
|
||||
{
|
||||
test-eval = {
|
||||
|
|
@ -36,7 +35,7 @@ in
|
|||
};
|
||||
|
||||
policy =
|
||||
{ config, ... }:
|
||||
{ ... }:
|
||||
{
|
||||
_class = "fediversity-resource-policy";
|
||||
|
||||
|
|
@ -46,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 ]);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -71,7 +70,7 @@ in
|
|||
};
|
||||
};
|
||||
policy =
|
||||
{ config, ... }:
|
||||
{ ... }:
|
||||
{
|
||||
_class = "fediversity-resource-policy";
|
||||
options = {
|
||||
|
|
@ -87,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; 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";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -116,42 +115,32 @@ in
|
|||
enable = lib.mkEnableOption "Hello in the shell";
|
||||
};
|
||||
};
|
||||
implementation =
|
||||
resources =
|
||||
cfg:
|
||||
lib.optionalAttrs cfg.enable {
|
||||
dummy.login-shell.packages.hello = pkgs.hello;
|
||||
};
|
||||
};
|
||||
environments.single-nixos-vm =
|
||||
{ config, ... }:
|
||||
{
|
||||
_class = "fediversity-environment";
|
||||
resources.shell.login-shell.username = "operator";
|
||||
implementation =
|
||||
requests:
|
||||
{ providers, ... }:
|
||||
{
|
||||
_class = "nixops4Deployment";
|
||||
providers = {
|
||||
inherit (inputs.nixops4.modules.nixops4Provider) local;
|
||||
};
|
||||
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 {
|
||||
|
|
@ -164,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;
|
||||
};
|
||||
|
|
@ -179,12 +165,14 @@ in
|
|||
inherit (fediversity)
|
||||
example-configuration
|
||||
;
|
||||
num-packages = lib.lists.length fediversity.example-deployment.users.users.operator.packages;
|
||||
};
|
||||
expected = {
|
||||
example-configuration = {
|
||||
enable = true;
|
||||
applications.hello.enable = true;
|
||||
};
|
||||
num-packages = 1;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
|
|
@ -13,23 +12,44 @@ let
|
|||
submoduleWith
|
||||
optionType
|
||||
functionTo
|
||||
raw
|
||||
;
|
||||
|
||||
functionType = import ./function.nix;
|
||||
application-requirements = {
|
||||
_class = "fediversity-application-requirements";
|
||||
options.resources = mkOption {
|
||||
# TODO: maybe transpose, and group the resources by type instead
|
||||
type = attrsOf (
|
||||
attrTag (lib.mapAttrs (_name: resource: mkOption { type = resource.request; }) config.resources)
|
||||
);
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
|
||||
in
|
||||
{
|
||||
_class = "fediversity-settings";
|
||||
options = {
|
||||
inherit configuration;
|
||||
resources = mkOption {
|
||||
description = "Collection of deployment resources that can be required by applications and policed by hosting providers";
|
||||
type = attrsOf (submoduleWith {
|
||||
|
|
@ -71,7 +91,7 @@ in
|
|||
type = attrsOf (submoduleWith {
|
||||
class = "fediversity-application";
|
||||
modules = [
|
||||
(application: {
|
||||
{
|
||||
options = {
|
||||
description = mkOption {
|
||||
description = "Description to be shown in the application overview";
|
||||
|
|
@ -81,30 +101,21 @@ in
|
|||
description = "Operator-facing configuration options for the application";
|
||||
type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; };
|
||||
};
|
||||
implementation = mkOption {
|
||||
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
|
||||
type = application.config.config-mapping.function-type;
|
||||
};
|
||||
resources = mkOption {
|
||||
description = "Compute resources required by an application";
|
||||
type = functionTo application.config.config-mapping.output-type;
|
||||
readOnly = true;
|
||||
default = input: (application.config.implementation input).output;
|
||||
};
|
||||
config-mapping = mkOption {
|
||||
description = "Function type for the mapping from application configuration to required resources";
|
||||
type = submoduleWith {
|
||||
class = "module-function";
|
||||
modules = [ functionType ];
|
||||
};
|
||||
readOnly = true;
|
||||
default = {
|
||||
input-type = application.config.module;
|
||||
output-type = application-requirements;
|
||||
};
|
||||
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
|
||||
# TODO: maybe transpose, and group the resources by type instead
|
||||
type = functionTo (
|
||||
attrsOf (
|
||||
attrTag (
|
||||
lib.mapAttrs (
|
||||
_name: resource: mkOption { type = types.submodule resource.request; }
|
||||
) config.resources
|
||||
)
|
||||
)
|
||||
);
|
||||
};
|
||||
};
|
||||
})
|
||||
}
|
||||
];
|
||||
});
|
||||
};
|
||||
|
|
@ -122,23 +133,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 = environment.config.resource-mapping.function-type;
|
||||
type = functionTo raw;
|
||||
};
|
||||
resource-mapping = mkOption {
|
||||
description = "Function type for the mapping from resources to a (NixOps4) deployment";
|
||||
|
|
@ -148,16 +164,13 @@ in
|
|||
};
|
||||
readOnly = true;
|
||||
default = {
|
||||
input-type = application-requirements;
|
||||
output-type = nixops4Deployment;
|
||||
input-type = configuration;
|
||||
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:
|
||||
|
|
@ -167,7 +180,7 @@ in
|
|||
name: application-settings: config.applications.${name}.resources application-settings
|
||||
) cfg.applications;
|
||||
in
|
||||
(environment.config.implementation required-resources).output;
|
||||
(environment.config.implementation required-resources);
|
||||
|
||||
};
|
||||
};
|
||||
|
|
@ -175,33 +188,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