diff options
-rw-r--r-- | doc/manual/nix-copy-closure.xml | 26 | ||||
-rw-r--r-- | doc/manual/release-notes.xml | 7 | ||||
-rw-r--r-- | perl/lib/Nix/CopyClosure.pm | 9 | ||||
-rwxr-xr-x | 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 @@ <arg><option>--xz</option></arg> <arg><option>--show-progress</option></arg> <arg><option>--include-outputs</option></arg> + <arg><option>--use-substitutes</option></arg> + <arg><option>-s</option></arg> <arg choice='plain'> <replaceable>user@</replaceable><replaceable>machine</replaceable> </arg> @@ -65,7 +67,7 @@ those paths. If this bothers you, use <refsection><title>Options</title> <variablelist> - + <varlistentry><term><option>--to</option></term> <listitem><para>Copy the closure of @@ -119,10 +121,22 @@ those paths. If this bothers you, use </varlistentry> <varlistentry><term><option>--include-outputs</option></term> - - <listitem><para>Also copy the outputs of store derivations included - in the closure.</para></listitem> - + + <listitem><para>Also copy the outputs of store derivations + included in the closure.</para></listitem> + + </varlistentry> + + <varlistentry><term><option>--use-substitutes</option> / <option>-s</option></term> + + <listitem><para>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 <literal>nixos.org</literal> (the default + binary cache server) is fast.</para></listitem> + </varlistentry> </variablelist> @@ -140,7 +154,7 @@ those paths. If this bothers you, use <command>ssh</command> on the command line.</para></listitem> </varlistentry> - + </variablelist> </refsection> 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 @@ -82,6 +82,13 @@ $ mount -o remount,ro,bind /nix/store </listitem> <listitem> + <para>The command <command>nix-copy-closure</command> has a new + flag <option>--use-substitutes</option> (<option>-s</option>) to + download missing paths on the target machine using the substitute + mechanism.</para> + </listitem> + + <listitem> <para>The command <command>nix-worker</command> has been renamed to <command>nix-daemon</command>. Support for running the Nix worker in “slave” mode has been removed.</para> 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: $?"; |