aboutsummaryrefslogtreecommitdiffstats
path: root/nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 12:53:18 +0000
committertv <tv@krebsco.de>2026-12-01 14:40:21 +0100
commit12ecf6015bc2bec3110c89be7eebe871463cdf5c (patch)
tree9b5a2fb9ff4b6b16e7dae7f59741becce03ae26e /nix
parent63311f0741d543093e083b9c6004aef6bf2a8421 (diff)
nix: source lists from the slots' sources
A slot's source says where a deployment gets its entry, on the deploying host: a source, or { location = NAME; VAR = …; }. enstate.locations holds locations for every source list, and enstate.sourceLists, read only, gives a source list per channel from the slots with a source, complete if every slot of the channel has one: for the deploying host to evaluate and pack, not part of the system. As hrm's own module had it, so hrm can use this instead.
Diffstat (limited to 'nix')
-rw-r--r--nix/module.nix57
1 files changed, 57 insertions, 0 deletions
diff --git a/nix/module.nix b/nix/module.nix
index f7a51a9..a4b0ea7 100644
--- a/nix/module.nix
+++ b/nix/module.nix
@@ -75,6 +75,18 @@ let
default = true;
description = "Whether the slot is its own view, `CHANNEL.SLOT`.";
};
+ source = mkOption {
+ type = types.nullOr types.raw;
+ default = null;
+ description = ''
+ Where a deployment gets the slot's entry, on the deploying host: a source
+ in enstate's syntax (`cmd:…`, `{ command = [ … ]; }`, …), or
+ `{ location = NAME; VAR = …; }`, a location with its variables. Not part
+ of the system: the deploying host reads it from `sourceLists`. Commands
+ and paths only, never a secret itself.
+ '';
+ example = lib.literalExpression ''{ location = "secrets"; key = "retiolum.ed25519_key.priv"; }'';
+ };
path = mkOption {
type = types.nullOr types.str;
readOnly = true;
@@ -269,6 +281,51 @@ in
description = "Views made by renderers.";
};
+ locations = mkOption {
+ type = types.attrsOf types.raw;
+ default = { };
+ description = ''
+ Locations for every source list (`sourceLists`): sources declared once,
+ which slots' `source` use by name, with variables. A deployment may add its
+ own (a location that names the deploying host's tools, say). A source list
+ is packed on the deploying host, so `$(env:…)` there are its: write the
+ host's own name in by Nix (`config.networking.hostName`), or as a variable.
+ '';
+ example = lib.literalExpression ''
+ { secrets.source.command = [ "secrets" config.networking.hostName "show" "$(var:key)" ]; }
+ '';
+ };
+
+ sourceLists = mkOption {
+ type = types.attrsOf types.raw;
+ readOnly = true;
+ description = ''
+ A source list for `enstate --pack` per channel, from the slots that have a
+ `source`, complete if every slot of the channel has one, with `locations`.
+ For the deploying host to evaluate (and to write as JSON, e.g. with
+ `pkgs.writers.writeJSON`): not part of the system.
+ '';
+ default = lib.mapAttrs (
+ channel: channelCfg:
+ let
+ sourced = lib.filterAttrs (_: slotCfg: slotCfg.source != null) channelCfg.slots;
+ in
+ {
+ inherit channel;
+ complete = lib.attrNames sourced == lib.attrNames channelCfg.slots;
+ items = lib.mapAttrs (
+ _: slotCfg:
+ if lib.isAttrs slotCfg.source && slotCfg.source ? location then
+ slotCfg.source
+ else
+ { inherit (slotCfg) source; }
+ ) sourced;
+ }
+ // lib.optionalAttrs (cfg.locations != { }) { inherit (cfg) locations; }
+ ) (lib.filterAttrs (_: channelCfg: lib.any (slotCfg: slotCfg.source != null) (lib.attrValues channelCfg.slots)) cfg.channels);
+ defaultText = lib.literalExpression "a source list per channel with sources";
+ };
+
incomingDir = mkOption {
type = types.str;
readOnly = true;