turn function.nix into a reflective type

This commit is contained in:
Kiara Grouwstra 2025-08-17 17:51:23 +02:00
parent 9c219341b1
commit 2e91782d7e
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU
2 changed files with 29 additions and 26 deletions

View file

@ -15,7 +15,7 @@ let
functionTo functionTo
; ;
functionType = import ./function.nix; functionType = import ./function.nix { inherit lib; };
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
@ -110,7 +110,7 @@ in
# TODO(@fricklerhandwerk): this needs a better name, it's just the type # 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 = functionType;
readOnly = true; readOnly = true;
default = { default = {
input-type = submodule application.config.module; input-type = submodule application.config.module;
@ -146,7 +146,7 @@ in
}; };
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 = functionType;
readOnly = true; readOnly = true;
default = { default = {
input-type = application-resources; input-type = application-resources;

View file

@ -1,7 +1,7 @@
/** /**
Modular function type Modular function type
*/ */
{ config, lib, ... }: { lib, ... }:
let let
inherit (lib) mkOption types; inherit (lib) mkOption types;
inherit (types) inherit (types)
@ -10,27 +10,30 @@ let
optionType optionType
; ;
in in
{ submodule (
options = { { config, ... }:
input-type = mkOption { {
type = optionType; options = {
}; input-type = mkOption {
output-type = mkOption { type = optionType;
type = optionType; };
}; output-type = mkOption {
function-type = mkOption { type = optionType;
type = optionType; };
readOnly = true; function-type = mkOption {
default = functionTo (submodule { type = optionType;
options = { readOnly = true;
input = mkOption { default = functionTo (submodule {
type = config.input-type; options = {
input = mkOption {
type = config.input-type;
};
output = mkOption {
type = config.output-type;
};
}; };
output = mkOption { });
type = config.output-type; };
};
};
});
}; };
}; }
} )