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/sh.rs | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'pkgs/populate/src/sh.rs') 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 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 for this run\n' \ + "$missing" + if ! out=$(nix-build --no-out-link --arg attrs "[$attrs ]" -E ' + { attrs }: let pkgs = import {}; in + map (attr: pkgs.lib.getBin pkgs.${attr}) attrs + '); then + >&2 printf 'error: the target lacks %s, and nix-build cannot get it from \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" -- cgit v1.3.1