diff options
| author | tv <tv@krebsco.de> | 2026-11-12 18:24:47 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-13 03:23:49 +0100 |
| commit | 333144080f4a03f1adc1eb7ded0a9d3ae1bfa9ee (patch) | |
| tree | 2bd8f7b80c3bfc2ad2ff59e393005d06b5e732c7 /lib | |
| parent | 9359951b4470542049ceb63ad04b7526a4c6c9e8 (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')
| -rw-r--r-- | lib/default.nix | 17 | ||||
| -rw-r--r-- | lib/types/populate.nix | 34 |
2 files changed, 51 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 "" diff --git a/lib/types/populate.nix b/lib/types/populate.nix index 4523dad..a278ffd 100644 --- a/lib/types/populate.nix +++ b/lib/types/populate.nix @@ -125,6 +125,10 @@ path = lib.mkOption { type = lib.types.absolute-pathname; }; + rewriteLock = lib.mkOption { + default = true; + type = lib.types.bool; + }; useChecksum = lib.mkOption { default = false; type = lib.types.bool; @@ -185,6 +189,19 @@ default = {}; type = flake-inputs; }; + materialize = lib.mkOption { + default = false; + type = lib.types.bool; + }; + patches = lib.mkOption { + apply = map toString; + default = []; + type = lib.types.listOf lib.types.path; + }; + rewriteLock = lib.mkOption { + default = true; + type = lib.types.bool; + }; }; }; flake-input = lib.types.submodule { @@ -200,6 +217,19 @@ default = {}; type = flake-inputs; }; + materialize = lib.mkOption { + default = false; + type = lib.types.bool; + }; + patches = lib.mkOption { + apply = map toString; + default = []; + type = lib.types.listOf lib.types.path; + }; + rewriteLock = lib.mkOption { + default = true; + type = lib.types.bool; + }; name = lib.mkOption { type = lib.types.str; }; @@ -224,6 +254,10 @@ ref = lib.mkOption { type = lib.types.str; # TODO lib.types.git.ref }; + rewriteLock = lib.mkOption { + default = true; + type = lib.types.bool; + }; url = lib.mkOption { type = lib.types.str; # TODO lib.types.git.url }; |
