aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/src/populate.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-20 05:19:21 +0000
committertv <tv@krebsco.de>2026-11-20 05:19:21 +0000
commite81592e76f48c850a0ef35b8048260c21306a4b2 (patch)
tree91ed172c077c7532ee39757578ec8630f6833600 /pkgs/populate/src/populate.rs
parent2aa54d9cb0399371a72a768cb5657a2bfebfde9e (diff)
populate: get what the target lacks from its <nixpkgs>krops-2
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 <nixpkgs> 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.
Diffstat (limited to 'pkgs/populate/src/populate.rs')
-rw-r--r--pkgs/populate/src/populate.rs37
1 files changed, 32 insertions, 5 deletions
diff --git a/pkgs/populate/src/populate.rs b/pkgs/populate/src/populate.rs
index 0366c53..322708a 100644
--- a/pkgs/populate/src/populate.rs
+++ b/pkgs/populate/src/populate.rs
@@ -12,7 +12,31 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
-/// Checks the sentinel, takes the lock on the target directory, makes a
+/// The commands populate runs on the target to deliver spec's sources, each
+/// followed by the attribute name in nixpkgs of the package that has it.
+fn tools(spec: &Spec) -> Vec<&'static str> {
+ let sources = || spec.source.values();
+ let mut tools = vec!["find", "findutils", "flock", "util-linux"];
+ if sources().any(|s| !matches!(s.kind.as_str(), "derivation" | "git" | "symlink")) {
+ tools.extend(["rsync", "rsync"]);
+ }
+ if sources().any(|s| s.kind == "git") {
+ tools.extend(["git", "git"]);
+ }
+ let patched = |s: &&Source| {
+ s.settings
+ .get("patches")
+ .and_then(Value::as_array)
+ .is_some_and(|patches| !patches.is_empty())
+ };
+ if sources().any(|s| patched(&s)) {
+ tools.extend(["patch", "gnupatch"]);
+ }
+ tools
+}
+
+/// Checks the sentinel, gets what the target lacks of the commands
+/// populate runs there from nixpkgs, takes the lock on the target directory, makes a
/// backup if asked, delivers each source, prunes if asked, and writes the
/// record of the run, see the record module.
pub fn populate(context: &Context, spec: &Spec) -> Result<()> {
@@ -20,10 +44,13 @@ pub fn populate(context: &Context, spec: &Spec) -> Result<()> {
refuse_copying_with_sudo(context, spec)?;
let sentinel = format!("{dir}/.populate");
let force = if spec.force { "1" } else { "" };
- context.run(
- sh::CHECK,
- &[&sentinel, &context.name(&sentinel), dir, force],
- )?;
+ let name = context.name(&sentinel);
+ let mut args = vec![sentinel.as_str(), &name, dir, force];
+ args.extend(tools(spec));
+ let output = context.output(sh::CHECK, &args)?;
+ if let Some(path) = output.lines().find_map(|line| line.strip_prefix("path ")) {
+ context.add_path(path);
+ }
let started = record::now();
let (previous, last) = context.lock(&sentinel, json!({ "run": started }))?;
if spec.backup {