forked from Fediversity/Fediversity
factor out function wrapper to module function #9
3 changed files with 112 additions and 72 deletions
|
@ -99,7 +99,7 @@ in
|
||||||
{
|
{
|
||||||
options.enable = lib.mkEnableOption "Hello in the shell";
|
options.enable = lib.mkEnableOption "Hello in the shell";
|
||||||
};
|
};
|
||||||
implementation =
|
config-mapping.implementation =
|
||||||
cfg:
|
cfg:
|
||||||
lib.optionalAttrs cfg.enable {
|
lib.optionalAttrs cfg.enable {
|
||||||
resources.hello.login-shell.packages.hello = pkgs.hello;
|
resources.hello.login-shell.packages.hello = pkgs.hello;
|
||||||
|
@ -109,7 +109,7 @@ in
|
||||||
{ config, ... }:
|
{ config, ... }:
|
||||||
{
|
{
|
||||||
resources.operator-environment.login-shell.username = "operator";
|
resources.operator-environment.login-shell.username = "operator";
|
||||||
implementation =
|
resource-mapping.implementation =
|
||||||
requests:
|
requests:
|
||||||
{ providers, ... }:
|
{ providers, ... }:
|
||||||
{
|
{
|
||||||
|
@ -149,7 +149,7 @@ in
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
resources = fediversity.applications.hello.resources fediversity.example-configuration.applications.hello;
|
resources = fediversity.applications.hello.config-mapping.apply fediversity.example-configuration.applications.hello;
|
||||||
hello-shell = resources.resources.hello.login-shell;
|
hello-shell = resources.resources.hello.login-shell;
|
||||||
environment = fediversity.environments.single-nixos-vm.resources.operator-environment.login-shell;
|
environment = fediversity.environments.single-nixos-vm.resources.operator-environment.login-shell;
|
||||||
result = mkDeployment {
|
result = mkDeployment {
|
||||||
|
|
|
@ -15,7 +15,6 @@ let
|
||||||
functionTo
|
functionTo
|
||||||
;
|
;
|
||||||
|
|
||||||
functionType = import ./function.nix;
|
|
||||||
application-resources = submodule {
|
application-resources = submodule {
|
||||||
options.resources = mkOption {
|
options.resources = mkOption {
|
||||||
# TODO: maybe transpose, and group the resources by type instead
|
# TODO: maybe transpose, and group the resources by type instead
|
||||||
|
@ -97,25 +96,63 @@ in
|
||||||
description = "Operator-facing configuration options for the application";
|
description = "Operator-facing configuration options for the application";
|
||||||
type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; };
|
type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; };
|
||||||
};
|
};
|
||||||
implementation = mkOption {
|
# TODO(@fricklerhandwerk): this needs a better name
|
||||||
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
|
|
||||||
type = application.config.config-mapping.implementation-type;
|
|
||||||
};
|
|
||||||
resources = mkOption {
|
|
||||||
description = "Compute resources required by an application";
|
|
||||||
type = functionTo application.config.config-mapping.output-type;
|
|
||||||
readOnly = true;
|
|
||||||
default = application.config.implementation;
|
|
||||||
};
|
|
||||||
# TODO(@fricklerhandwerk): this needs a better name, it's just the type
|
|
||||||
config-mapping = mkOption {
|
config-mapping = mkOption {
|
||||||
description = "Function type for the mapping from application configuration to required resources";
|
description = "Function type for the mapping from application configuration to required resources";
|
||||||
type = submodule functionType;
|
type = submodule (
|
||||||
readOnly = true;
|
{ config, ... }:
|
||||||
default = {
|
{
|
||||||
input-type = submodule application.config.module;
|
options = {
|
||||||
output-type = application-resources;
|
input-type = mkOption {
|
||||||
};
|
type = optionType;
|
||||||
|
default = submodule application.config.module;
|
||||||
|
# default = types.int;
|
||||||
|
};
|
||||||
|
output-type = mkOption {
|
||||||
|
type = optionType;
|
||||||
|
default = application-resources;
|
||||||
|
};
|
||||||
|
function-type = mkOption {
|
||||||
|
type = optionType;
|
||||||
|
readOnly = true;
|
||||||
|
default = functionTo config.output-type;
|
||||||
|
};
|
||||||
|
wrapper-type = mkOption {
|
||||||
|
type = optionType;
|
||||||
|
readOnly = true;
|
||||||
|
default = functionTo (submodule {
|
||||||
|
options = {
|
||||||
|
input = mkOption {
|
||||||
|
type = config.input-type;
|
||||||
|
};
|
||||||
|
output = mkOption {
|
||||||
|
type = config.output-type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
implementation = mkOption {
|
||||||
|
type = config.function-type;
|
||||||
|
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
default = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
@ -140,18 +177,62 @@ in
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
implementation = mkOption {
|
|
||||||
description = "Mapping of resources required by applications to available resources; the result can be deployed";
|
|
||||||
type = environment.config.resource-mapping.implementation-type;
|
|
||||||
};
|
|
||||||
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";
|
||||||
type = submodule functionType;
|
type = submodule (
|
||||||
readOnly = true;
|
{ config, ... }:
|
||||||
default = {
|
{
|
||||||
input-type = application-resources;
|
options = {
|
||||||
output-type = nixops4Deployment;
|
input-type = mkOption {
|
||||||
};
|
type = optionType;
|
||||||
|
default = submodule application-resources;
|
||||||
|
# default = types.int;
|
||||||
|
};
|
||||||
|
output-type = mkOption {
|
||||||
|
type = optionType;
|
||||||
|
default = nixops4Deployment;
|
||||||
|
};
|
||||||
|
function-type = mkOption {
|
||||||
|
type = optionType;
|
||||||
|
readOnly = true;
|
||||||
|
default = functionTo config.output-type;
|
||||||
|
};
|
||||||
|
wrapper-type = mkOption {
|
||||||
|
type = optionType;
|
||||||
|
readOnly = true;
|
||||||
|
default = functionTo (submodule {
|
||||||
|
options = {
|
||||||
|
input = mkOption {
|
||||||
|
type = config.input-type;
|
||||||
|
};
|
||||||
|
output = mkOption {
|
||||||
|
type = config.output-type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
implementation = mkOption {
|
||||||
|
type = config.function-type;
|
||||||
|
description = "Mapping of resources required by applications to available resources; the result can be deployed";
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
default = { };
|
||||||
};
|
};
|
||||||
# TODO(@fricklerhandwerk): maybe this should be a separate thing such as `fediversity-setup`,
|
# TODO(@fricklerhandwerk): maybe this should be a separate thing such as `fediversity-setup`,
|
||||||
# which makes explicit which applications and environments are available.
|
# which makes explicit which applications and environments are available.
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
/**
|
|
||||||
Modular function type
|
|
||||||
*/
|
|
||||||
{ config, lib, ... }:
|
|
||||||
let
|
|
||||||
inherit (lib) mkOption types;
|
|
||||||
inherit (types)
|
|
||||||
submodule
|
|
||||||
functionTo
|
|
||||||
optionType
|
|
||||||
;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
input-type = mkOption {
|
|
||||||
type = optionType;
|
|
||||||
};
|
|
||||||
output-type = mkOption {
|
|
||||||
type = optionType;
|
|
||||||
};
|
|
||||||
implementation-type = mkOption {
|
|
||||||
type = optionType;
|
|
||||||
readOnly = true;
|
|
||||||
default = functionTo config.output-type;
|
|
||||||
};
|
|
||||||
function-type = mkOption {
|
|
||||||
type = optionType;
|
|
||||||
readOnly = true;
|
|
||||||
default = functionTo (submodule {
|
|
||||||
options = {
|
|
||||||
input = mkOption {
|
|
||||||
type = config.input-type;
|
|
||||||
};
|
|
||||||
output = mkOption {
|
|
||||||
type = config.output-type;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue