config.builders.foundation.basic: Add vars to the derivation type

This commit is contained in:
Ross Smyth 2025-10-30 18:07:47 -04:00
parent 2523a43663
commit 93eeee8024

View file

@ -39,6 +39,44 @@ in
name = "BashString";
description = "A Bash-compatible string";
};
# Lists in Bash cannot be nested, just hold numbers and strings.
bashList =
(lib.types.list.of (
lib.types.one [
lib.types.number
lib.types.bashString
]
))
// {
name = "BashList";
description = "A bash-compatible list";
};
# Hashmaps/attrset/associated lists in Bash cannot be nested or hold lists. They just map
# strings to numbers or strings to strings.
bashMap =
(lib.types.attrs.of (
lib.types.one [
lib.types.number
lib.types.bashString
]
))
// {
name = "BashMap";
description = "A bash-compatible attrset/associated list";
};
# Any arbitrary Bash variable
bashVar =
(lib.types.one [
lib.types.bashList
lib.types.bashMap
])
// {
name = "BashVar";
description = "A bash-compatible variable";
};
license =
let
type = lib.types.submodule (
@ -797,6 +835,26 @@ in
default.value = { };
};
# TOTHINK: Currently this only validates for Bash variables.
# In the future we could/should allow users to have JSON exports
# as well, which have relaxes requirements compared to Bash.
#
# Either relaxing this var, or adding another var.
vars = lib.options.create {
description = "Bash variables set in the derivation";
type = lib.types.withCheck (lib.types.attrs.of lib.types.bashVar) (
lib.fp.pipe [
# TODO: Better errors, these suck right now.
builtins.attrNames
# Cannot be a reservd name, and cannot be an environment variable
(builtins.all (
name: (notReservedVar name) && !(builtins.elem name (builtins.attrNames config.env))
))
]
);
default.value = { };
};
package = lib.options.create {
description = "The built derivation.";
type = lib.types.derivation;