diff options
| author | tv <tv@krebsco.de> | 2026-11-20 00:51:27 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-20 00:51:27 +0000 |
| commit | 61840ec59bc13b9b2ae6d29fff7276c849684941 (patch) | |
| tree | 0b5299e337758b34cd4982ed4e0c2d8eb3655f0f /pkgs/populate/src/flake_input.rs | |
| parent | 275b9f6102e6f3011099752ec1023a11b326fc45 (diff) | |
populate: a lock, a journal, and a record of each run
For consumers of the target directory on the target, e.g. a CI service,
which should act after a run that delivered everything, and know what it
delivered.
Populate holds an exclusive flock on .populate/lock from right after
checking the sentinel until it's done. The command holding it runs over
the shared connection, or directly, keeping the lock until its input
ends, which populate's ending ends as well, so no lock stays behind.
Runs wait for each other, and for consumers holding a shared lock,
saying so. The sentinel is a directory, which a sentinel file becomes,
since there's always state to keep now, and the target needs flock.
Populate keeps a journal in .populate/journal, a line of JSON for each
entry: a run starting, beginning to deliver or change a source, what
that changed, and pruning. The entries go with the next command on the
target, before what that changes, so the journal needs no commands of
its own. After delivering everything, populate replaces
.populate/run.json with the record of the run, which sums up the
journal, and removes the journal. A run that doesn't finish leaves it,
so changed in the record means changed since the last record: a source
the journal tells began changing, without what it changed, counts as
changed. The record has, for each source, its type, whether it changed,
and what got delivered: the commit of a git source, the store path of a
flake, flake-input, or derivation source, and the derived one, and a
symlink's target. Nothing about secrets, nor files.
Each source type is a Kind, whose deliver returns the Outcome: whether
anything changed, and what got delivered. rsync tells changes by what
it itemizes, the snippets by printing changed: the git source if it
cloned, reset, or submodule updates or cleaning printed anything, links
if they point elsewhere, and lock files and generated flakes if they
differ. Symlinks in place of the lock or the journal get refused.
A file or git source whose lock file populate rewrites in place counts
as changed on every run, since delivering it brings back the original.
Diffstat (limited to 'pkgs/populate/src/flake_input.rs')
| -rw-r--r-- | pkgs/populate/src/flake_input.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/pkgs/populate/src/flake_input.rs b/pkgs/populate/src/flake_input.rs index 8d3a218..b38965d 100644 --- a/pkgs/populate/src/flake_input.rs +++ b/pkgs/populate/src/flake_input.rs @@ -3,6 +3,7 @@ //! collector roots for its own inputs. use crate::flake::derives_flake; +use crate::populate::Outcome; use crate::rsync::{self, Config}; use crate::run::{self, Context, Failure, Result}; use crate::sh; @@ -273,14 +274,15 @@ fn flag(settings: &Map<String, Value>, key: &str, default: bool) -> bool { } /// Delivers the flake or flake-input source named name to path, preparing -/// what it needs on the deploying machine in workdir. +/// what it needs on the deploying machine in workdir. What a derived +/// source's target path gets, the flakes step tells, see flake::derive. pub fn deliver( context: &Context, name: &str, path: &str, source: &Source, workdir: &Path, -) -> Result<()> { +) -> Result<Outcome> { let settings = &source.settings; let url = setting(settings, "url") .and_then(Value::as_str) @@ -344,7 +346,7 @@ pub fn deliver( } Ok::<_, Failure>(paths) }; - let link = |subdir: &str, paths: &[String]| -> Result<()> { + let link = |subdir: &str, paths: &[String]| -> Result<Outcome> { let link_name = context.name(&link_path); let mut args = vec![ sentinel.as_str(), @@ -355,7 +357,9 @@ pub fn deliver( subdir, ]; args.extend(paths.iter().map(String::as_str)); - context.run(&on_target(sh::flake::LINK, None), &args) + let output = context.output(&on_target(sh::flake::LINK, None), &args)?; + let changed = !derived && output.contains("changed"); + Ok(Outcome::changed(changed).with("storePath", &paths[0])) }; let on_target_output = |what: &'static str| { move |snippet: &str, args: &[&str]| context.output(&on_target(snippet, Some(what)), args) @@ -591,6 +595,7 @@ fn upload_patches( &dir.to_string_lossy(), &format!("{sentinel}/patches/{name}"), ) + .map(|_| ()) } /// Uploads the flake itself to a target that can't fetch it, unless the @@ -610,7 +615,7 @@ fn upload_self(context: &Context, name: &str, sentinel: &str, self_path: &str) - .join("flake-uploads") .join(name) .join("tree"); - rsync::transfer(context, &config, self_path, &upload.to_string_lossy()) + rsync::transfer(context, &config, self_path, &upload.to_string_lossy()).map(|_| ()) } #[cfg(test)] |
