Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the '--show-progress' flag to nix-copy-closure #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/manual/nix-copy-closure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<arg><option>--gzip</option></arg>
<arg><option>--bzip2</option></arg>
<arg><option>--xz</option></arg>
<arg><option>--show-progress</option></arg>
<arg><option>--include-outputs</option></arg>
<arg choice='plain'>
<replaceable>user@</replaceable><replaceable>machine</replaceable>
Expand Down Expand Up @@ -110,6 +111,13 @@ those paths. If this bothers you, use

</varlistentry>

<varlistentry><term><option>--show-progress</option></term>

<listitem><para>Show the progress of each path's transfer as it's made.
This requires the <command>pv</command> utility to be in <envar>PATH</envar>.</para></listitem>

</varlistentry>

<varlistentry><term><option>--include-outputs</option></term>

<listitem><para>Also copy the outputs of store derivations included
Expand Down
7 changes: 4 additions & 3 deletions perl/lib/Nix/CopyClosure.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use Nix::Store;


sub copyTo {
my ($sshHost, $sshOpts, $storePaths, $compressor, $decompressor, $includeOutputs, $dryRun, $sign) = @_;
my ($sshHost, $sshOpts, $storePaths, $compressor, $decompressor, $includeOutputs, $dryRun, $sign, $progressViewer) = @_;

$compressor = "$compressor |" if $compressor ne "";
$decompressor = "$decompressor |" if $decompressor ne "";

$progressViewer = "$progressViewer |" if $progressViewer ne "";

# Get the closure of this path.
my @closure = reverse(topoSortPaths(computeFSClosure(0, $includeOutputs,
map { followLinksToStorePath $_ } @{$storePaths})));
Expand All @@ -34,7 +35,7 @@ sub copyTo {
if (scalar @missing > 0) {
print STDERR "copying ", scalar @missing, " missing paths to ‘$sshHost’...\n";
unless ($dryRun) {
open SSH, "| $compressor ssh $sshHost @{$sshOpts} '$decompressor nix-store --import' > /dev/null" or die;
open SSH, "| $compressor $progressViewer ssh $sshHost @{$sshOpts} '$decompressor nix-store --import' > /dev/null" or die;
exportPaths(fileno(SSH), $sign, @missing);
close SSH or die "copying store paths to remote machine `$sshHost' failed: $?";
}
Expand Down
10 changes: 8 additions & 2 deletions scripts/nix-copy-closure.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ my $sign = 0;
my $compressor = "";
my $decompressor = "";

my $progressViewer = "";

my $toMode = 1;

my $includeOutputs = 0;
Expand Down Expand Up @@ -60,6 +62,9 @@ while (@ARGV) {
elsif ($arg eq "--include-outputs") {
$includeOutputs = 1;
}
elsif ($arg eq "--show-progress") {
$progressViewer = "pv";
}
elsif ($arg eq "--dry-run") {
$dryRun = 1;
}
Expand All @@ -76,7 +81,7 @@ 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);
Nix::CopyClosure::copyTo($sshHost, [ @sshOpts ], [ @storePaths ], $compressor, $decompressor, $includeOutputs, $dryRun, $sign, $progressViewer);
}

else { # Copy FROM the remote machine.
Expand All @@ -101,9 +106,10 @@ else { # Copy FROM the remote machine.
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) {
my $extraOpts = $sign ? "--sign" : "";
system("set -f; ssh $sshHost @sshOpts 'nix-store --export $extraOpts @missing $compressor' | $decompressor $Nix::Config::binDir/nix-store --import > /dev/null") == 0
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: $?";
}
}
Expand Down