factor out function wrapper to module function (#503)
All checks were successful
deploy-infra / deploy (push) Successful in 2m11s
/ check-pre-commit (push) Successful in 12s
/ check-data-model (push) Successful in 31s
/ check-mastodon (push) Successful in 22s
/ check-peertube (push) Successful in 23s
/ check-panel (push) Successful in 1m29s
/ check-proxmox-basic (push) Successful in 35s
/ check-deployment-basic (push) Successful in 34s
/ check-deployment-cli (push) Successful in 44s
/ check-deployment-panel (push) Successful in 1m53s
/ check-resources (push) Successful in 4m6s
All checks were successful
deploy-infra / deploy (push) Successful in 2m11s
/ check-pre-commit (push) Successful in 12s
/ check-data-model (push) Successful in 31s
/ check-mastodon (push) Successful in 22s
/ check-peertube (push) Successful in 23s
/ check-panel (push) Successful in 1m29s
/ check-proxmox-basic (push) Successful in 35s
/ check-deployment-basic (push) Successful in 34s
/ check-deployment-cli (push) Successful in 44s
/ check-deployment-panel (push) Successful in 1m53s
/ check-resources (push) Successful in 4m6s
lifts the `{ input output }` function wrapper out of the user interface to `function.nix`, simplifying usage. Reviewed-on: #503
This commit is contained in:
parent
c3027eb7d1
commit
09db4d6217
3 changed files with 53 additions and 21 deletions
|
@ -98,20 +98,18 @@ in
|
|||
{
|
||||
options.enable = lib.mkEnableOption "Hello in the shell";
|
||||
};
|
||||
implementation = cfg: {
|
||||
input = cfg;
|
||||
output = lib.optionalAttrs cfg.enable {
|
||||
implementation =
|
||||
cfg:
|
||||
lib.optionalAttrs cfg.enable {
|
||||
resources.hello.login-shell.packages.hello = pkgs.hello;
|
||||
};
|
||||
};
|
||||
};
|
||||
environments.single-nixos-vm =
|
||||
{ config, ... }:
|
||||
{
|
||||
resources.operator-environment.login-shell.username = "operator";
|
||||
implementation = requests: {
|
||||
input = requests;
|
||||
output.nixops4 =
|
||||
nixops4 = (
|
||||
{ providers, ... }:
|
||||
{
|
||||
providers = {
|
||||
|
@ -130,7 +128,8 @@ in
|
|||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -109,11 +109,11 @@ in
|
|||
};
|
||||
resources = mkOption {
|
||||
description = "Compute resources required by an application";
|
||||
type = functionTo application.config.config-mapping.output-type;
|
||||
type = application.config.config-mapping.function-type;
|
||||
readOnly = true;
|
||||
default = input: (application.config.implementation input).output;
|
||||
default = application.config.config-mapping.apply;
|
||||
};
|
||||
# TODO(@fricklerhandwerk): this needs a better name, it's just the type
|
||||
# TODO(@fricklerhandwerk): this needs a better name
|
||||
config-mapping = mkOption {
|
||||
description = "Function type for the mapping from application configuration to required resources";
|
||||
type = functionType;
|
||||
|
@ -121,6 +121,7 @@ in
|
|||
default = {
|
||||
input-type = submodule application.config.module;
|
||||
output-type = application-resources;
|
||||
implementation = application.config.implementation;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -157,6 +158,25 @@ in
|
|||
default = {
|
||||
input-type = application-resources;
|
||||
output-type = deployment;
|
||||
implementation = environment.config.implementation;
|
||||
};
|
||||
};
|
||||
config-mapping = mkOption {
|
||||
description = "Mapping from a configuration to a deployment";
|
||||
type = submodule functionType;
|
||||
readOnly = true;
|
||||
default = {
|
||||
input-type = config.configuration;
|
||||
output-type = nixops4Deployment;
|
||||
implementation =
|
||||
cfg:
|
||||
# TODO: check cfg.enable.true
|
||||
let
|
||||
required-resources = lib.mapAttrs (
|
||||
name: application-settings: config.applications.${name}.resources application-settings
|
||||
) cfg.applications;
|
||||
in
|
||||
environment.config.resource-mapping.apply required-resources;
|
||||
};
|
||||
};
|
||||
# TODO(@fricklerhandwerk): maybe this should be a separate thing such as `fediversity-setup`,
|
||||
|
@ -164,18 +184,9 @@ in
|
|||
# then the deployments can simply be the result of the function application baked into this module.
|
||||
deployment = mkOption {
|
||||
description = "Generate a deployment from a configuration, by applying an environment's resource policies to the applications' resource mappings";
|
||||
type = functionTo (environment.config.resource-mapping.output-type);
|
||||
type = environment.config.config-mapping.function-type;
|
||||
readOnly = true;
|
||||
default =
|
||||
cfg:
|
||||
# TODO: check cfg.enable.true
|
||||
let
|
||||
required-resources = lib.mapAttrs (
|
||||
name: application-settings: config.applications.${name}.resources application-settings
|
||||
) cfg.applications;
|
||||
in
|
||||
(environment.config.implementation required-resources).output;
|
||||
|
||||
default = environment.config.config-mapping.apply;
|
||||
};
|
||||
};
|
||||
})
|
||||
|
|
|
@ -19,6 +19,11 @@ in
|
|||
type = optionType;
|
||||
};
|
||||
function-type = mkOption {
|
||||
type = optionType;
|
||||
readOnly = true;
|
||||
default = functionTo config.output-type;
|
||||
};
|
||||
wrapper-type = mkOption {
|
||||
type = optionType;
|
||||
readOnly = true;
|
||||
default = functionTo (submodule {
|
||||
|
@ -32,5 +37,22 @@ in
|
|||
};
|
||||
});
|
||||
};
|
||||
implementation = mkOption {
|
||||
type = config.function-type;
|
||||
default = _: { };
|
||||
};
|
||||
wrapper = mkOption {
|
||||
type = config.wrapper-type;
|
||||
readOnly = true;
|
||||
default = input: fn: {
|
||||
inherit input;
|
||||
output = config.implementation fn.config.input;
|
||||
};
|
||||
};
|
||||
apply = mkOption {
|
||||
type = config.function-type;
|
||||
readOnly = true;
|
||||
default = input: (config.wrapper input).output;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue