about summary refs log tree commit diff
path: root/scripts/nix-copy-closure.in
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-07-24T14·00+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-07-24T14·19+0200
commit03103c0a36cc94238542de2bdf6eedcb679cca49 (patch)
tree04ab7ba5b8568937df7331f2347ab5c982517cef /scripts/nix-copy-closure.in
parent62309a2c56206821370b87285fcacacba1cb3566 (diff)
Implement nix-copy-closure --from via nix-store --serve
Diffstat (limited to 'scripts/nix-copy-closure.in')
-rwxr-xr-xscripts/nix-copy-closure.in36
1 files changed, 8 insertions, 28 deletions
diff --git a/scripts/nix-copy-closure.in b/scripts/nix-copy-closure.in
index 05faa63917da..3dde6e1574ad 100755
--- a/scripts/nix-copy-closure.in
+++ b/scripts/nix-copy-closure.in
@@ -89,42 +89,22 @@ if ($toMode) { # Copy TO the remote machine.
 
 else { # Copy FROM the remote machine.
 
-    openSSHConnection $sshHost or die "$0: unable to start SSH\n";
+    my ($from, $to) = connectToRemoteNix($sshHost, [ @sshOpts ]);
 
     # Query the closure of the given store paths on the remote
     # machine.  Paths are assumed to be store paths; there is no
     # resolution (following of symlinks).
-    my $extraOpts = $includeOutputs ? "--include-outputs" : "";
-    my $pid = open(READ,
-        "set -f; ssh @sshOpts $sshHost nix-store --query --requisites $extraOpts @storePaths|") or die;
-
-    while (<READ>) {
-        chomp;
-        die "bad: $_" unless /^\//;
-        push @missing, $_ unless isValidPath($_);
-    }
-
-    close READ or die "nix-store on remote machine `$sshHost' failed: $?";
-
-    my $missingSize = 0;
-    if ($progressViewer ne "") {
-        $missingSize = sum (split ' ', `set -f; ssh @sshOpts $sshHost nix-store -q --size @missing`) or die;
-    }
+    syswrite($to, pack("L<x4L<x4", 7, $includeOutputs ? 1 : 0)) or die;
+    writeStrings(\@storePaths, $to);
+    my @missing = grep { !isValidPath($_) } readStrings($from);
 
     # Export the store paths on the remote machine and import them locally.
     if (scalar @missing > 0) {
         print STDERR "copying ", scalar @missing, " missing paths from ‘$sshHost’...\n";
-        unless ($dryRun) {
-            if ($useSubstitutes) {
-                system "$Nix::Config::binDir/nix-store -r --ignore-unknown @missing";
-            }
-            $compressor = "| $compressor" if $compressor ne "";
-            $decompressor = "$decompressor |" if $decompressor ne "";
-            $progressViewer = "$progressViewer -s $missingSize |" if $progressViewer ne "";
-            my $extraOpts = $sign ? "--sign" : "";
-            system("set -f; ssh $sshHost @sshOpts 'nix-store --export $extraOpts @missing $compressor' | $decompressor $progressViewer $Nix::Config::binDir/nix-store --import > /dev/null") == 0
-                or die "copying store paths from remote machine `$sshHost' failed: $?";
-        }
+        writeInt(5, $to); # == cmdExportPaths
+        writeInt($sign ? 1 : 0, $to);
+        writeStrings(\@missing, $to);
+        importPaths(fileno($from));
     }
 
 }