From e81592e76f48c850a0ef35b8048260c21306a4b2 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 20 Nov 2026 05:19:21 +0000 Subject: populate: get what the target lacks from its populate runs findutils, flock, rsync, patch, and Git on the target, as the sources need them. check looks for those first, and if any isn't there, it warns, and gets their packages from the target's with one nix-build, whose bin directories commands on the target, and rsync's remote end, find commands in before those in their PATH, for the rest of the run. If the target is the machine populate runs on, that goes for populate as well. --- pkgs/populate/src/run.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'pkgs/populate/src/run.rs') diff --git a/pkgs/populate/src/run.rs b/pkgs/populate/src/run.rs index 113bcf9..cf6364d 100644 --- a/pkgs/populate/src/run.rs +++ b/pkgs/populate/src/run.rs @@ -123,6 +123,9 @@ pub struct Context { /// The command holding the lock on the target directory, see lock, and /// the lock file's name in messages. lock: std::cell::RefCell>, + /// Directories on the target that commands there find commands in + /// before those in their PATH, see add_path. + path: std::cell::RefCell>, } impl Context { @@ -151,6 +154,7 @@ impl Context { git_checked: Default::default(), journal: Default::default(), entries: Default::default(), + path: Default::default(), lock: Default::default(), }; context.write_ssh(&context.ssh, &context.ssh_options(true))?; @@ -249,10 +253,14 @@ impl Context { *flushed = entries.len(); } } + let path = match &*self.path.borrow() { + Some(path) => format!("PATH={path}:$PATH\nexport PATH\n"), + None => String::new(), + }; let script = if lines.is_empty() { - format!("set -efu\n{script}") + format!("set -efu\n{path}{script}") } else { - format!("set -efu\n{}{script}", crate::sh::JOURNAL) + format!("set -efu\n{path}{}{script}", crate::sh::JOURNAL) }; let args: Vec<&str> = lines .iter() @@ -281,6 +289,29 @@ impl Context { } } + /// Has commands on the target find commands in path, a list of + /// directories like PATH, before those in their PATH. If the target + /// is the machine populate runs on, that goes for populate as well. + pub fn add_path(&self, path: &str) { + if self.local { + let old = std::env::var_os("PATH").unwrap_or_default(); + let mut new = std::ffi::OsString::from(path); + if !old.is_empty() { + new.push(":"); + new.push(old); + } + std::env::set_var("PATH", new); + } else { + *self.path.borrow_mut() = Some(path.to_string()); + } + } + + /// The directories add_path added for commands on the target, unless + /// the target is the machine populate runs on. + pub fn path(&self) -> Option { + self.path.borrow().clone() + } + /// 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 -- cgit v1.3.1