Skip to content

Commit 5cc2fc4

Browse files
viricedolstra
authored andcommitted
Adding ETA support to the --show-progress in nix-copy-closure
Based on NixOS#6 from shlevy
1 parent 3628b61 commit 5cc2fc4

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

perl/lib/Nix/CopyClosure.pm

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ package Nix::CopyClosure;
33
use strict;
44
use Nix::Config;
55
use Nix::Store;
6+
use List::Util qw(sum);
67

78

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

12-
$compressor = "$compressor |" if $compressor ne "";
13-
$decompressor = "$decompressor |" if $decompressor ne "";
14-
$progressViewer = "$progressViewer |" if $progressViewer ne "";
15-
1613
# Get the closure of this path.
1714
my @closure = reverse(topoSortPaths(computeFSClosure(0, $includeOutputs,
1815
map { followLinksToStorePath $_ } @{$storePaths})));
@@ -28,16 +25,23 @@ sub copyTo {
2825
# we'll want to use ‘--from-stdin’, but we can't rely on the
2926
# target having this option yet.
3027
my @missing = ();
28+
my $missingSize = 0;
3129
while (scalar(@closure) > 0) {
3230
my @ps = splice(@closure, 0, 1500);
3331
open(READ, "set -f; ssh $sshHost @{$sshOpts} nix-store --check-validity --print-invalid @ps|");
3432
while (<READ>) {
3533
chomp;
3634
push @missing, $_;
35+
my ($deriver, $narHash, $time, $narSize, $refs) = queryPathInfo($_, 1);
36+
$missingSize += $narSize;
3737
}
3838
close READ or die;
3939
}
4040

41+
$compressor = "$compressor |" if $compressor ne "";
42+
$decompressor = "$decompressor |" if $decompressor ne "";
43+
$progressViewer = "$progressViewer -s $missingSize |" if $progressViewer ne "";
44+
4145
# Export the store paths and import them on the remote machine.
4246
if (scalar @missing > 0) {
4347
print STDERR "copying ", scalar @missing, " missing paths to ‘$sshHost’...\n";

scripts/nix-copy-closure.in

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use Nix::SSH;
44
use Nix::Config;
55
use Nix::Store;
66
use Nix::CopyClosure;
7+
use List::Util qw(sum);
78

89

910
if (scalar @ARGV < 1) {
@@ -61,7 +62,7 @@ while (@ARGV) {
6162
$includeOutputs = 1;
6263
}
6364
elsif ($arg eq "--show-progress") {
64-
$progressViewer = "@pv@";
65+
$progressViewer = "pv";
6566
}
6667
elsif ($arg eq "--dry-run") {
6768
$dryRun = 1;
@@ -104,6 +105,11 @@ else { # Copy FROM the remote machine.
104105

105106
close READ or die "nix-store on remote machine `$sshHost' failed: $?";
106107

108+
my $missingSize = 0;
109+
if ($progressViewer ne "") {
110+
$missingSize = sum (split ' ', `set -f; ssh @sshOpts $sshHost nix-store -q --size @missing`) or die;
111+
}
112+
107113
# Export the store paths on the remote machine and import them locally.
108114
if (scalar @missing > 0) {
109115
print STDERR "copying ", scalar @missing, " missing paths from ‘$sshHost’...\n";
@@ -113,7 +119,7 @@ else { # Copy FROM the remote machine.
113119
}
114120
$compressor = "| $compressor" if $compressor ne "";
115121
$decompressor = "$decompressor |" if $decompressor ne "";
116-
$progressViewer = "$progressViewer |" if $progressViewer ne "";
122+
$progressViewer = "$progressViewer -s $missingSize |" if $progressViewer ne "";
117123
my $extraOpts = $sign ? "--sign" : "";
118124
system("set -f; ssh $sshHost @sshOpts 'nix-store --export $extraOpts @missing $compressor' | $progressViewer $decompressor $Nix::Config::binDir/nix-store --import > /dev/null") == 0
119125
or die "copying store paths from remote machine `$sshHost' failed: $?";

0 commit comments

Comments
 (0)