generalize function type

This commit is contained in:
Valentin Gagarin 2025-07-29 17:06:32 +02:00
parent 4509d277d3
commit 16d3c512e0
2 changed files with 10 additions and 8 deletions

View file

@ -15,11 +15,13 @@ let
; ;
functionType = import ./function.nix; functionType = import ./function.nix;
application-resources = { 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
type = attrsOf ( type = attrsOf (
attrTag (lib.mapAttrs (_name: resource: mkOption { type = resource.request; }) config.resources) attrTag (
lib.mapAttrs (_name: resource: mkOption { type = submodule resource.request; }) config.resources
)
); );
}; };
}; };
@ -52,12 +54,13 @@ in
readOnly = true; readOnly = true;
default = input: (application.config.implementation input).output; default = input: (application.config.implementation input).output;
}; };
# 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 functionType;
readOnly = true; readOnly = true;
default = { default = {
input-type = application.config.module; input-type = submodule application.config.module;
output-type = application-resources; output-type = application-resources;
}; };
}; };

View file

@ -5,7 +5,6 @@
let let
inherit (lib) mkOption types; inherit (lib) mkOption types;
inherit (types) inherit (types)
deferredModule
submodule submodule
functionTo functionTo
optionType optionType
@ -14,10 +13,10 @@ in
{ {
options = { options = {
input-type = mkOption { input-type = mkOption {
type = deferredModule; type = optionType;
}; };
output-type = mkOption { output-type = mkOption {
type = deferredModule; type = optionType;
}; };
function-type = mkOption { function-type = mkOption {
type = optionType; type = optionType;
@ -25,10 +24,10 @@ in
default = functionTo (submodule { default = functionTo (submodule {
options = { options = {
input = mkOption { input = mkOption {
type = submodule config.input-type; type = config.input-type;
}; };
output = mkOption { output = mkOption {
type = submodule config.output-type; type = config.output-type;
}; };
}; };
}); });