From 93eeee8024fdcc928e72404758cf6c2aa4356e27 Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Thu, 30 Oct 2025 18:07:47 -0400 Subject: [PATCH] config.builders.foundation.basic: Add `vars` to the derivation type --- tidepool/src/lib/types.nix | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tidepool/src/lib/types.nix b/tidepool/src/lib/types.nix index 1a9efe4..b827661 100644 --- a/tidepool/src/lib/types.nix +++ b/tidepool/src/lib/types.nix @@ -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;