aboutsummaryrefslogtreecommitdiffstats
path: root/lib/default.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-12 18:24:47 +0000
committertv <tv@krebsco.de>2026-11-13 03:23:49 +0100
commit333144080f4a03f1adc1eb7ded0a9d3ae1bfa9ee (patch)
tree2bd8f7b80c3bfc2ad2ff59e393005d06b5e732c7 /lib/default.nix
parent9359951b4470542049ceb63ad04b7526a4c6c9e8 (diff)
populate: draw inputs by rewriting lock files, add materialize and patches
Sources drawing inputs from other sources get the lock file of their flake rewritten with nix flake lock --override-input, so the flake in the source itself uses the other sources, and needs no generated flake to be found. file and git sources get their lock file rewritten in place. flake and flake-input sources get delivered as a copy with the rewritten lock file, which gets added to the store with nix-store --add-fixed, and the target path links to that. With rewriteLock set to false, and for symlink sources, the source stays as it is and gets a generated flake in .populate/flakes/<name>, which writeDeploy's flake parameter uses. flake and flake-input sources get two more options: - patches: patches on the deploying machine, which get uploaded to .populate/patches/<name> and applied in order with patch -p1 on the target, in the directory the target path shows. - materialize: the target path becomes a writable copy instead of a link into the store. Sources that get patched, rewritten, or materialized get delivered to .populate/derived/<name>/original, which also roots the delivered store path, and the flakes step derives the target path from there. Copies get made again only if what they derive from changes, which a key in .populate/derived/<name> records. The matrices of the file, flake, flake-input, and git tests cover both ways of drawing inputs, those of flake and flake-input materialize, the deploy test a source with a rewritten lock file, and features and edge cases run the scenarios drawing inputs both ways. New features cover patches, a patch that doesn't apply, patches in a subdirectory, reusing copies, and materializing.
Diffstat (limited to 'lib/default.nix')
-rw-r--r--lib/default.nix17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix
index f720a08..0a99f97 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -42,6 +42,23 @@ let {
in
flatten [] (source.${source.type}.inputs or {});
+ # Tells whether a source's inputs get drawn from other sources by a
+ # generated flake in .populate/flakes, instead of by rewriting the lock
+ # file of the flake in the source. Symlink sources point at other
+ # sources, whose lock files stay as they are.
+ hasGeneratedFlake = source:
+ lib.flakeFollows source != [] &&
+ (source.type == "symlink" || !(source.${source.type}.rewriteLock or true));
+
+ # Tells whether a flake or flake-input source gets delivered as a copy,
+ # which gets patched, gets its lock file rewritten, or is materialized.
+ derivesFlake = source: let
+ source' = source.${source.type};
+ in
+ lib.elem source.type [ "flake" "flake-input" ] &&
+ (source'.materialize or false || source'.patches or [] != [] ||
+ (source'.rewriteLock or true && lib.flakeFollows source != []));
+
maybeHostName = default: let
# We're parsing /etc/hostname here because reading
# /proc/sys/kernel/hostname yields ""