allow use of readOnly attributes in modular function output types

Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
Kiara Grouwstra 2025-11-07 13:47:46 +01:00
parent c0024739b2
commit da724b3511
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU
4 changed files with 59 additions and 10 deletions

View file

@ -140,6 +140,7 @@ in
type = functionType;
readOnly = true;
default = {
type-output = false;
input-type = submodule {
options = {
deployment-name = mkOption {
@ -159,6 +160,7 @@ in
type = functionType;
readOnly = true;
default = {
type-output = false;
input-type = submodule {
options = {
deployment-name = mkOption {

View file

@ -105,4 +105,48 @@ in
value = false;
};
};
test-read-only = {
expr =
tryEval
(lib.evalModules {
modules = [
(
{ config, ... }:
{
options = {
fn = mkOption {
type = functionType;
};
call = mkOption {
default = config.fn.apply { };
};
};
config.fn =
let
sub = submodule {
options.foo = mkOption {
type = int;
readOnly = true;
default = 1;
};
};
in
{
implementation = x: x;
input-type = sub;
output-type = sub;
type-output = false;
};
}
)
];
}).config.call;
expected = {
success = true;
value = {
foo = 1;
};
};
};
}

View file

@ -45,6 +45,11 @@ let
in
{
options = {
type-output = mkOption {
type = types.bool;
description = "Whether to type function output. This may need to be disabled if the output type contains read-only attributes.";
default = true;
};
input-type = mkOption {
type = optionType;
};
@ -54,7 +59,7 @@ in
function-type = mkOption {
type = optionType;
readOnly = true;
default = functionTo config.output-type;
default = functionTo (if config.type-output then config.output-type else types.unspecified);
};
wrapper-type = mkOption {
type = optionType;
@ -65,7 +70,7 @@ in
type = config.input-type;
};
output = mkOption {
type = config.output-type;
type = if config.type-output then config.output-type else types.unspecified;
};
};
});

View file

@ -202,8 +202,7 @@ in
};
run = mkOption {
type = types.package;
# error: The option `ssh-deployment.ssh-host.run' is read-only, but it's set multiple times.
# readOnly = true;
readOnly = true;
default =
let
inherit (ssh-host.config)
@ -282,8 +281,7 @@ in
};
run = mkOption {
type = types.package;
# error: The option `tf-deployment.tf-host.run' is read-only, but it's set multiple times.
# readOnly = true;
readOnly = true;
default =
let
inherit (tf-host.config)
@ -354,8 +352,7 @@ in
};
run = mkOption {
type = types.package;
# error: The option `tf-deployment.tf-host.run' is read-only, but it's set multiple times.
# readOnly = true;
readOnly = true;
default =
let
inherit (tf-host.config)
@ -499,8 +496,7 @@ in
};
run = mkOption {
type = types.package;
# error: The option `tf-deployment.tf-host.run' is read-only, but it's set multiple times.
# readOnly = true;
readOnly = true;
default =
let
inherit (tf-host.config)
@ -587,6 +583,7 @@ in
};
run = mkOption {
type = types.package;
readOnly = true;
default =
let
inherit (tf-netbox-store-ips.config)
@ -614,6 +611,7 @@ in
inherit httpBackend;
run = mkOption {
type = types.package;
readOnly = true;
default =
let
inherit (tf-netbox-get-ip.config)