From a3d6585c5a1006d4f9ebd2163d06f86ab71a4a3e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 23 Nov 2012 16:20:16 +0100 Subject: [PATCH] =?UTF-8?q?nix-copy-closure:=20Add=20flag=20=E2=80=98--use?= =?UTF-8?q?-substitutes=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/manual/nix-copy-closure.xml | 26 ++++++++++++++++++++------ doc/manual/release-notes.xml | 7 +++++++ perl/lib/Nix/CopyClosure.pm | 9 ++++++++- scripts/nix-copy-closure.in | 23 +++++++++++++---------- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/doc/manual/nix-copy-closure.xml b/doc/manual/nix-copy-closure.xml index 4b5ce755c..30b3aaee3 100644 --- a/doc/manual/nix-copy-closure.xml +++ b/doc/manual/nix-copy-closure.xml @@ -28,6 +28,8 @@ + + user@machine @@ -65,7 +67,7 @@ those paths. If this bothers you, use Options - + Copy the closure of @@ -119,10 +121,22 @@ those paths. If this bothers you, use - - Also copy the outputs of store derivations included - in the closure. - + + Also copy the outputs of store derivations + included in the closure. + + + + / + + Attempt to download missing paths on the target + machine using Nix’s substitute mechanism. Any paths that cannot + be substituted on the target are still copied normally from the + source. This is useful, for instance, if the connection between + the source and target machine is slow, but the connection between + the target machine and nixos.org (the default + binary cache server) is fast. + @@ -140,7 +154,7 @@ those paths. If this bothers you, use ssh on the command line. - + diff --git a/doc/manual/release-notes.xml b/doc/manual/release-notes.xml index c1dc6166d..ea28436b8 100644 --- a/doc/manual/release-notes.xml +++ b/doc/manual/release-notes.xml @@ -81,6 +81,13 @@ $ mount -o remount,ro,bind /nix/store modifications. + + The command nix-copy-closure has a new + flag () to + download missing paths on the target machine using the substitute + mechanism. + + The command nix-worker has been renamed to nix-daemon. Support for running the Nix diff --git a/perl/lib/Nix/CopyClosure.pm b/perl/lib/Nix/CopyClosure.pm index 79c6dfccc..931057e9f 100644 --- a/perl/lib/Nix/CopyClosure.pm +++ b/perl/lib/Nix/CopyClosure.pm @@ -6,7 +6,8 @@ use Nix::Store; sub copyTo { - my ($sshHost, $sshOpts, $storePaths, $compressor, $decompressor, $includeOutputs, $dryRun, $sign, $progressViewer) = @_; + my ($sshHost, $sshOpts, $storePaths, $compressor, $decompressor, + $includeOutputs, $dryRun, $sign, $progressViewer, $useSubstitutes) = @_; $compressor = "$compressor |" if $compressor ne ""; $decompressor = "$decompressor |" if $decompressor ne ""; @@ -16,6 +17,12 @@ sub copyTo { 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. + } + # 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 diff --git a/scripts/nix-copy-closure.in b/scripts/nix-copy-closure.in index 0eb7a4ed0..1a1684ed0 100755 --- a/scripts/nix-copy-closure.in +++ b/scripts/nix-copy-closure.in @@ -17,19 +17,14 @@ EOF # Get the target host. my $sshHost; - my $sign = 0; - my $compressor = ""; my $decompressor = ""; - my $progressViewer = ""; - my $toMode = 1; - my $includeOutputs = 0; - my $dryRun = 0; +my $useSubstitutes = 0; # !!! Copied from nix-pack-closure, should put this in a module. @@ -71,6 +66,9 @@ while (@ARGV) { elsif ($arg eq "--dry-run") { $dryRun = 1; } + elsif ($arg eq "--use-substitutes" || $arg eq "-s") { + $useSubstitutes = 1; + } elsif (!defined $sshHost) { $sshHost = $arg; } @@ -84,7 +82,9 @@ openSSHConnection $sshHost or die "$0: unable to start SSH\n"; if ($toMode) { # Copy TO the remote machine. - Nix::CopyClosure::copyTo($sshHost, [ @sshOpts ], [ @storePaths ], $compressor, $decompressor, $includeOutputs, $dryRun, $sign, $progressViewer); + Nix::CopyClosure::copyTo( + $sshHost, [ @sshOpts ], [ @storePaths ], $compressor, $decompressor, + $includeOutputs, $dryRun, $sign, $progressViewer, $useSubstitutes); } else { # Copy FROM the remote machine. @@ -107,10 +107,13 @@ else { # Copy FROM the remote machine. # 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"; - $compressor = "| $compressor" if $compressor ne ""; - $decompressor = "$decompressor |" if $decompressor ne ""; - $progressViewer = "$progressViewer |" if $progressViewer ne ""; 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 |" if $progressViewer ne ""; my $extraOpts = $sign ? "--sign" : ""; system("set -f; ssh $sshHost @sshOpts 'nix-store --export $extraOpts @missing $compressor' | $progressViewer $decompressor $Nix::Config::binDir/nix-store --import > /dev/null") == 0 or die "copying store paths from remote machine `$sshHost' failed: $?";