WIP: implement mappings

This commit is contained in:
Valentin Gagarin 2025-07-02 01:20:35 +02:00 committed by Kiara Grouwstra
parent 5b1993c800
commit 37df0f370d
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU
3 changed files with 34 additions and 60 deletions

View file

@ -13,6 +13,7 @@ let
./data-model.nix
];
}).config;
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
in
{
test-eval = {

View file

@ -102,35 +102,57 @@ in
)
);
};
resource-mapping = mkOption {
implementation = mkOption {
description = "Mapping of resources required by applications to available resources; the result can be deployed";
type = environment.config.function.implementation;
type = environment.config.resource-mapping.function-type;
};
# TODO: somewhere we still need to
# - apply = { implementation = resource-mapping; input = <resource requirements of configured applications>; }
# - apply.output (deployment)
function = mkOption {
resource-mapping = mkOption {
description = "Function type for the mapping from resources to a (NixOps4) deployment";
type = submodule functionType;
readOnly = true;
default = {
input-type = application-resources;
output-type = submodule nixops4Deployment;
output-type = nixops4Deployment;
};
};
deployment = mkOption {
description = "Generate a deployment from a configuration";
type = functionTo environment.config.resource-mapping.output-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;
};
};
})
);
};
configurations = mkOption {
description = "Application configurations set by operators";
type = attrsOf (submodule {
configuration = mkOption {
description = "Configuration type declaring options to be set by operators";
type = optionType;
readOnly = true;
default = submodule (configuration: {
options = {
enable = mkOption {
description = "Whether to enable the configuration";
type = types.bool;
default = false;
};
applications = mapAttrs (name: application: submodule application.module) config.applications;
applications = lib.mapAttrs (
name: application:
mkOption {
description = application.description;
type = submodule application.module;
default = { };
}
) config.applications;
};
});
};

View file

@ -1,49 +0,0 @@
/**
Modular function type
*/
{ config, ... }:
{
options = {
input-type = mkOption {
type = deferredModule;
};
output-type = mkOption {
type = deferredModule;
};
implementation = mkOption {
type = optionType;
readOnly = true;
default = implementationTo (
submodule (implementation: {
options = {
input = mkOption {
type = submodule config.input-type;
};
output = mkOption {
type = submodule config.output-type;
};
};
})
);
};
apply = mkOption {
type = optionType;
readOnly = true;
default = submodule (apply: {
options = {
implementation = mkOption {
type = config.implementation;
};
input = mkOption {
type = submodule config.input-type;
};
output = mkOption {
type = submodule config.output-type;
readOnly = true;
default = (apply.config.implementation apply.config.input).output;
};
};
});
};
};
}