about summary refs log tree commit diff
path: root/perl/lib/Nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-07-10T18·43+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-07-10T18·43+0200
commit7bb632b02464febd8806ef4bd3fa0ac107f52650 (patch)
tree369be5e1ce1976ac4f8886bbb1c376614600c19e /perl/lib/Nix
parent7c3a5090bff4e9cfe70f1d89619563b55af13d89 (diff)
nix-copy-closure -s: Do substitutions via ‘nix-store --serve’
This means we no longer need an SSH master connection, since we only
execute a single command on the remote host.
Diffstat (limited to 'perl/lib/Nix')
-rw-r--r--perl/lib/Nix/CopyClosure.pm19
1 files changed, 11 insertions, 8 deletions
diff --git a/perl/lib/Nix/CopyClosure.pm b/perl/lib/Nix/CopyClosure.pm
index 53da72038d64..779d7439f677 100644
--- a/perl/lib/Nix/CopyClosure.pm
+++ b/perl/lib/Nix/CopyClosure.pm
@@ -29,16 +29,12 @@ sub copyTo {
     my ($sshHost, $sshOpts, $storePaths, $compressor, $decompressor,
         $includeOutputs, $dryRun, $sign, $progressViewer, $useSubstitutes) = @_;
 
+    $useSubstitutes = 0 if $dryRun;
+
     # Get the closure of this path.
     my @closure = reverse(topoSortPaths(computeFSClosure(0, $includeOutputs,
         map { followLinksToStorePath $_ } @{$storePaths})));
 
-    # Optionally use substitutes on the remote host.
-    if (!$dryRun && $useSubstitutes) {
-        system "ssh $sshHost @{$sshOpts} nix-store -r --ignore-unknown @closure";
-        # Ignore exit status because this is just an optimisation.
-    }
-
     # Start ‘nix-store --serve’ on the remote host.
     my ($from, $to);
     my $pid = open2($from, $to, "ssh $sshHost @{$sshOpts} nix-store --serve --write");
@@ -60,8 +56,9 @@ sub copyTo {
 
     # Send the "query valid paths" command with the "lock" option
     # enabled. This prevents a race where the remote host
-    # garbage-collect paths that are already there.
-    syswrite($to, pack("L<x4L<x4L<x4", 1, 1, scalar @closure)) or die;
+    # garbage-collect paths that are already there. Optionally, ask
+    # the remote host to substitute missing paths.
+    syswrite($to, pack("L<x4L<x4L<x4L<x4", 1, 1, $useSubstitutes, scalar @closure)) or die;
     writeString($_, $to) foreach @closure;
 
     # Get back the set of paths that are already valid on the remote host.
@@ -119,6 +116,12 @@ sub oldCopyTo {
     my ($closure, $sshHost, $sshOpts, $storePaths, $compressor, $decompressor,
         $includeOutputs, $dryRun, $sign, $progressViewer, $useSubstitutes) = @_;
 
+    # Optionally use substitutes on the remote host.
+    if (!$dryRun && $useSubstitutes) {
+        system "ssh $sshHost @{$sshOpts} nix-store -r --ignore-unknown @$closure";
+        # Ignore exit status because this is just an optimisation.
+    }
+
     # Ask the remote host which paths are invalid.  Because of limits
     # to the command line length, do this in chunks.  Eventually,
     # we'll want to use ‘--from-stdin’, but we can't rely on the