aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/src
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-14 02:07:52 +0000
committertv <tv@krebsco.de>2026-11-14 02:07:52 +0000
commit4742c6de2c532e6b1be145a5544d815fc95199b4 (patch)
tree51f4ae386ce4f3ce37d72bc7e2584b3d2c5c8c40 /pkgs/populate/src
parent06f3ddfd3a32e9038ea36c6e196d71adf1753391 (diff)
populate: copy flakes only if the target lacks some of their store paths
nix copy connects anew, without the shared connection, also when the target has all of a flake's store paths already, and then copies nothing. The shared connection tells which store paths the target lacks, and nix copy only copies those, if any.
Diffstat (limited to 'pkgs/populate/src')
-rw-r--r--pkgs/populate/src/flake_input.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/pkgs/populate/src/flake_input.rs b/pkgs/populate/src/flake_input.rs
index 0084689..c611371 100644
--- a/pkgs/populate/src/flake_input.rs
+++ b/pkgs/populate/src/flake_input.rs
@@ -509,9 +509,17 @@ fn nix_config() -> String {
format!("{config}\nextra-experimental-features = nix-command flakes")
}
-/// Copies store paths to the target with nix copy, which runs ssh from
-/// PATH, so that's the ssh for Nix's ssh:// store there.
+/// Copies the store paths the target lacks to the target with nix copy,
+/// which runs ssh from PATH, so that's the ssh for Nix's ssh:// store
+/// there. It connects anew, which the shared connection spares if the
+/// target has all of them.
fn copy(context: &Context, workdir: &Path, paths: &[String]) -> Result<()> {
+ let args: Vec<&str> = paths.iter().map(String::as_str).collect();
+ let invalid = context.output("nix-store --check-validity --print-invalid \"$@\"\n", &args)?;
+ let missing: Vec<&str> = invalid.lines().filter(|line| !line.is_empty()).collect();
+ if missing.is_empty() {
+ return Ok(());
+ }
let bin = workdir.join("bin");
let link = bin.join("ssh");
let prepare = || -> std::io::Result<()> {
@@ -528,7 +536,10 @@ fn copy(context: &Context, workdir: &Path, paths: &[String]) -> Result<()> {
std::env::join_paths(std::iter::once(bin.clone()).chain(std::env::split_paths(&path)))
.map_err(|e| Failure::Message(format!("error: can't extend PATH: {e}")))?;
let mut command = nix(&["copy", "--to", &format!("ssh://{}", context.target.host)]);
- command.args(paths).env("PATH", path).stdout(run::stderr());
+ command
+ .args(missing)
+ .env("PATH", path)
+ .stdout(run::stderr());
run::status(&mut command)
}