aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/src/sh.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/sh.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/sh.rs')
-rw-r--r--pkgs/populate/src/sh.rs40
1 files changed, 36 insertions, 4 deletions
diff --git a/pkgs/populate/src/sh.rs b/pkgs/populate/src/sh.rs
index 7a61d92..71f5ebf 100644
--- a/pkgs/populate/src/sh.rs
+++ b/pkgs/populate/src/sh.rs
@@ -125,12 +125,44 @@ remove_others() {
}
"#;
-/// check SENTINEL NAME DIR FORCE: fails unless the sentinel exists, creating
-/// it and the target directory DIR first if FORCE isn't empty. A sentinel
-/// file becomes a directory, which populate keeps its state in. NAME is
-/// the sentinel's name in messages.
+/// check SENTINEL NAME DIR FORCE [COMMAND ATTR]...: fails unless the
+/// sentinel exists, creating it and the target directory DIR first if FORCE
+/// isn't empty. A sentinel file becomes a directory, which populate keeps
+/// its state in. NAME is the sentinel's name in messages. If any COMMAND
+/// isn't there, it warns, gets the packages with the attribute names ATTR
+/// of those from <nixpkgs> with nix-build, and prints path and where their
+/// commands are, like PATH.
pub const CHECK: &str = r#"
sentinel=$1 name=$2 dir=$3 force=$4
+shift 4
+# The commands that aren't there, of those that follow, each followed by
+# the attribute name of its package in nixpkgs, which nix-build gets, once,
+# for all of them.
+missing= attrs=
+while test $# -gt 0; do
+ if ! command -v "$1" >/dev/null; then
+ missing=$missing${missing:+, }$1
+ attrs="$attrs \"$2\""
+ fi
+ shift 2
+done
+if test -n "$missing"; then
+ >&2 printf 'warning: the target lacks %s, which populate gets from <nixpkgs> for this run\n' \
+ "$missing"
+ if ! out=$(nix-build --no-out-link --arg attrs "[$attrs ]" -E '
+ { attrs }: let pkgs = import <nixpkgs> {}; in
+ map (attr: pkgs.lib.getBin pkgs.${attr}) attrs
+ '); then
+ >&2 printf 'error: the target lacks %s, and nix-build cannot get it from <nixpkgs>\n' \
+ "$missing"
+ exit 1
+ fi
+ path=
+ for out in $out; do
+ path=$path${path:+:}$out/bin
+ done
+ printf 'path %s\n' "$path"
+fi
# Before anything touches it, which would touch what it points to.
if test -L "$sentinel"; then
>&2 printf 'error: sentinel file is a symlink: %s\n' "$name"