aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/flake-jq.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-13 03:41:54 +0000
committertv <tv@krebsco.de>2026-11-13 03:41:54 +0000
commite90426e9abf1370851cd24557ae7ac897cdef297 (patch)
tree4a7ab50874f6771e137a5799e1e870228484918e /pkgs/populate/flake-jq.nix
parent0842652921304ba76fbd321756b6b545abc81b01 (diff)
populate: fail on inputs drawn that the flake doesn't have
Nix ignores an input that --override-input names but the flake doesn't have, with a warning, so a misspelt input name in inputs draws nothing, and the source keeps using its own input. Before changing anything, populate locks the flake of each source that draws inputs, with an empty flake in place of each input drawn, which may be unreachable, and fails, naming the source and the input, unless the flake has each input drawn. Below an input drawn from a source, the path continues in the flake of that source. An edge case misspells an input of the source's flake, and one below an input drawn from a source, both ways of drawing inputs.
Diffstat (limited to 'pkgs/populate/flake-jq.nix')
-rw-r--r--pkgs/populate/flake-jq.nix23
1 files changed, 23 insertions, 0 deletions
diff --git a/pkgs/populate/flake-jq.nix b/pkgs/populate/flake-jq.nix
index 63afa9d..446b2ef 100644
--- a/pkgs/populate/flake-jq.nix
+++ b/pkgs/populate/flake-jq.nix
@@ -2,6 +2,29 @@
# their own, so tests can run them: jq programs, which run on the deploying
# machine, and a Nix function for the target, which may lack jq.
rec {
+ # Nix function returning 1 if the lock file locks has an input at path, a
+ # list of input names, resolving inputs that follow others, and else 0.
+ lockHasInput = /* nix */ ''
+ locks: path: let
+ nodes = locks.nodes;
+ input = key: name: (nodes.''${key}.inputs or {}).''${name} or null;
+ # The node an input refers to, following follows from the root.
+ node = ref:
+ if ref == null then null
+ else if builtins.isList ref then
+ builtins.foldl'
+ (key: name: if key == null then null else node (input key name))
+ locks.root
+ ref
+ else ref;
+ has = key: path:
+ if path == [] then true
+ else let next = node (input key (builtins.head path)); in
+ next != null && has next (builtins.tail path);
+ in
+ if has locks.root path then "1" else "0"
+ '';
+
# Nix function returning the subdirectory containing the flake that nix
# flake metadata describes, like subdirOf does in jq.
metadataSubdir = /* nix */ ''