diff options
| author | tv <tv@krebsco.de> | 2026-11-14 02:07:52 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-14 02:07:52 +0000 |
| commit | 4742c6de2c532e6b1be145a5544d815fc95199b4 (patch) | |
| tree | 51f4ae386ce4f3ce37d72bc7e2584b3d2c5c8c40 /pkgs/populate | |
| parent | 06f3ddfd3a32e9038ea36c6e196d71adf1753391 (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')
| -rw-r--r-- | pkgs/populate/README.md | 4 | ||||
| -rw-r--r-- | pkgs/populate/src/flake_input.rs | 17 |
2 files changed, 16 insertions, 5 deletions
diff --git a/pkgs/populate/README.md b/pkgs/populate/README.md index 63ec6bd..fd7de6d 100644 --- a/pkgs/populate/README.md +++ b/pkgs/populate/README.md @@ -253,8 +253,8 @@ The flake source type delivers a flake to the target. The flake gets archived locally using `nix flake archive`, which includes only files tracked by Git, so use a `file` source for work trees with untracked files. The flake and its inputs get copied into the target's Nix store using `nix copy`, -and the target path becomes a symlink to the flake's store path, registered -as garbage collector root. For flakes in a subdirectory, e.g. +if it lacks any of them, and the target path becomes a symlink to the +flake's store path, registered as garbage collector root. For flakes in a subdirectory, e.g. `git+file:/src/mono?dir=sub`, the symlink points at that subdirectory of the store path. The inputs get garbage collector roots in `.populate/flake-inputs/<name>`, which turns the sentinel file into a 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) } |
