aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/src/run.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-20 02:33:17 +0000
committertv <tv@krebsco.de>2026-11-20 02:33:17 +0000
commit7e4597a38a29f66fd8bbc7415973caeaa9442bde (patch)
treed730cc0db0bb3fdb5db9e977a996dbccc5fedbfc /pkgs/populate/src/run.rs
parent7837a236e728988fcd501917444828b790c367f9 (diff)
populate: file sources' record setting, for provenance in the run record
A consumer recording what a build used gets the commit of git sources, and the store paths of flake, flake-input, and derivation sources, but nothing for file sources, which often hold the configuration, taken from work trees on the deploying machine. Recording nothing about them stays the default, since they may hold secrets, whose hash could give them away. file sources' record setting, with flags that default to false, adds to the source's entry in the record: - commit: if path is in a Git work tree, the commit HEAD names, and dirty, whether git status lists anything in path. Git runs on the deploying machine, without hooks, file system monitors, and writing the index, on every run, which is cheap: a new commit can change HEAD without changing any file. - digest: what nix-hash --type sha256 --sri prints for the target path, after the flakes step, which may have rewritten its lock file. That takes reading all of it, so populate only computes it if the source changed since the last record, and else takes it from that record, which the command taking the lock prints, so a run that changes nothing reads nothing more. The record's format stays version 0: the fields are optional additions. The README documents that the record tells what populate delivered, which something changing the target directory meanwhile would make it miss, and how rsync can leave out much of what Git ignores, with :- .gitignore in a .rsync-filter file, and what that misses. record-file checks the commit, dirty, and the digest, also taken from the last record.
Diffstat (limited to 'pkgs/populate/src/run.rs')
-rw-r--r--pkgs/populate/src/run.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/pkgs/populate/src/run.rs b/pkgs/populate/src/run.rs
index acbf279..9817b78 100644
--- a/pkgs/populate/src/run.rs
+++ b/pkgs/populate/src/run.rs
@@ -281,8 +281,12 @@ impl Context {
/// Takes the lock on the target directory, whose sentinel is sentinel,
/// adding entry to the journal, which entries go to from now on, until
/// unlock. Returns the lines that runs that didn't finish left in the
- /// journal.
- pub fn lock(&self, sentinel: &str, entry: serde_json::Value) -> Result<Vec<String>> {
+ /// journal, and the lines of the last run's record.
+ pub fn lock(
+ &self,
+ sentinel: &str,
+ entry: serde_json::Value,
+ ) -> Result<(Vec<String>, Vec<String>)> {
let mut command = self.shell(
crate::sh::LOCK,
&[sentinel, &self.name(sentinel), &entry.to_string()],
@@ -293,7 +297,8 @@ impl Context {
.stderr(Stdio::inherit());
let mut child = command.spawn().map_err(|e| spawn_error(&command, e))?;
let stdout = child.stdout.take().expect("piped");
- let mut previous = Vec::new();
+ let mut journal = Vec::new();
+ let mut record = None;
let mut locked = false;
for line in BufReader::new(stdout).lines() {
let line = line.map_err(|e| {
@@ -305,7 +310,11 @@ impl Context {
locked = true;
break;
}
- previous.push(line);
+ match &mut record {
+ None if line == "record" => record = Some(Vec::new()),
+ None => journal.push(line),
+ Some(record) => record.push(line),
+ }
}
if !locked {
drop(child.stdin.take());
@@ -322,7 +331,7 @@ impl Context {
*self.journal.borrow_mut() = Some(format!("{sentinel}/journal"));
self.entries.borrow_mut().0.push(entry);
self.entries.borrow_mut().1 = 1;
- Ok(previous)
+ Ok((journal, record.unwrap_or_default()))
}
/// Fails if the command holding the lock ended, e.g. killed on the