diff options
| author | tv <tv@krebsco.de> | 2026-11-20 01:48:55 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-20 01:48:55 +0000 |
| commit | 7837a236e728988fcd501917444828b790c367f9 (patch) | |
| tree | f2f3b91ffe0fd7f60f71f12c5f4f871c92916665 /pkgs/populate/src/populate.rs | |
| parent | f02b09eae7e806f2fe9caa26b4975b94351d7e27 (diff) | |
populate: lock files rewritten in place change only if they differ
A file or git source whose lock file the flakes step rewrites in place
gets the original back from delivering it, on every run, from rsync, or
from git reset, which also printed HEAD is now at, and Nix printed that
it updates the lock file, so the record said the source changed on every
run. Populate keeps a copy of the rewritten lock file in
.populate/locks/<name>, and the flakes step compares with it, printing
what Nix says about the lock file, and changed, only if it differs.
Delivering such a source doesn't count bringing back the lock file:
rsync returns the paths of what it changed, and the git source's script
takes the lock file's path, and resets quietly if that's all that
differs.
relock also checks that the second, unchanged, run prints nothing about
lock files, and says nothing changed, now for rewriting in place too.
Diffstat (limited to 'pkgs/populate/src/populate.rs')
| -rw-r--r-- | pkgs/populate/src/populate.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/pkgs/populate/src/populate.rs b/pkgs/populate/src/populate.rs index 617d39f..efcf5c3 100644 --- a/pkgs/populate/src/populate.rs +++ b/pkgs/populate/src/populate.rs @@ -135,7 +135,7 @@ impl Delivery<'_> { &source_path.to_string_lossy(), self.path, )?; - Ok(Outcome::changed(changed)) + Ok(Outcome::changed(!changed.is_empty())) } } @@ -188,6 +188,12 @@ fn string<'a>(settings: &'a Map<String, Value>, key: &str) -> Result<&'a str> { .ok_or_else(|| Failure::Message(format!("populate: the source has no {key}"))) } +/// The path, relative to the source, of the lock file of the flake in a +/// source, if the flakes step rewrites it in place, see flake::rewrite. +fn in_place_lock(source: &Source) -> Option<&'static str> { + flake::rewrites_lock(source).then_some("flake.lock") +} + /// A Nix expression, built on the target, delivered as a link to the result. struct Derivation; @@ -221,7 +227,12 @@ impl Kind for File { ..Config::from_settings(settings) }; let changed = rsync::transfer(d.context, &config, source_path, d.path)?; - Ok(Outcome::changed(changed)) + // The lock file the flakes step rewrites, which delivering brings + // back, changed if the flakes step says so. + let lock = in_place_lock(d.source); + Ok(Outcome::changed( + changed.iter().any(|path| Some(path.as_str()) != lock), + )) } } @@ -250,7 +261,7 @@ impl Kind for Pipe { ..Config::default() }; let changed = rsync::transfer(d.context, &config, &out.to_string_lossy(), d.path)?; - Ok(Outcome::changed(changed)) + Ok(Outcome::changed(!changed.is_empty())) } } @@ -289,6 +300,7 @@ impl Kind for Git { flag("shallow"), flag("fetchAlways"), flag("reclone"), + in_place_lock(d.source).unwrap_or_default(), ]; args.extend(excludes); // With standard input, which Git may ask for credentials on. |
