Skip to content

Commit bdf089f

Browse files
committed
* Before a build, show the disk space that the downloaded store paths
will approximately require.
1 parent 06699d4 commit bdf089f

File tree

11 files changed

+36
-29
lines changed

11 files changed

+36
-29
lines changed

scripts/copy-from-other-stores.pl.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ if ($ARGV[0] eq "--query") {
6363
`@bindir@/nix-store --query --references $storePath`;
6464
die "cannot query references of `$storePath'" if $? != 0;
6565

66+
my $narSize = `@bindir@/nix-store --query --size $storePath`;
67+
die "cannot query size of `$storePath'" if $? != 0;
68+
chomp $narSize;
69+
6670
print "$deriver\n";
6771
print scalar @references, "\n";
6872
print "$_\n" foreach @references;
69-
print "0\n"; # !!! showing size not supported (yet)
73+
print "$narSize\n";
74+
print "$narSize\n";
7075
}
7176

7277
else { die "unknown command `$cmd'"; }

scripts/download-using-manifests.pl.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ if ($ARGV[0] eq "--query") {
6464
print "$_\n" foreach @references;
6565
my $size = $info->{size} || 0;
6666
print "$size\n";
67+
my $narSize = $info->{narSize} || 0;
68+
print "$narSize\n";
6769
}
6870

6971
else { die "unknown command `$cmd'"; }

scripts/readmanifest.pm.in

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,8 @@ sub readManifest {
3333

3434
my $manifestVersion = 2;
3535

36-
my $storePath;
37-
my $url;
38-
my $hash;
39-
my $size;
40-
my $basePath;
41-
my $baseHash;
42-
my $patchType;
43-
my $narHash;
44-
my $references;
45-
my $deriver;
46-
my $hashAlgo;
47-
my $copyFrom;
36+
my ($storePath, $url, $hash, $size, $basePath, $baseHash, $patchType);
37+
my ($narHash, $narSize, $references, $deriver, $hashAlgo, $copyFrom);
4838

4939
while (<MANIFEST>) {
5040
chomp;
@@ -62,6 +52,7 @@ sub readManifest {
6252
undef $hash;
6353
undef $size;
6454
undef $narHash;
55+
undef $narSize;
6556
undef $basePath;
6657
undef $baseHash;
6758
undef $patchType;
@@ -89,7 +80,8 @@ sub readManifest {
8980
if (!$found) {
9081
push @{$narFileList},
9182
{ url => $url, hash => $hash, size => $size
92-
, narHash => $narHash, references => $references
83+
, narHash => $narHash, narSize => $narSize
84+
, references => $references
9385
, deriver => $deriver, hashAlgo => $hashAlgo
9486
};
9587
}
@@ -100,8 +92,8 @@ sub readManifest {
10092
addPatch $patches, $storePath,
10193
{ url => $url, hash => $hash, size => $size
10294
, basePath => $basePath, baseHash => $baseHash
103-
, narHash => $narHash, patchType => $patchType
104-
, hashAlgo => $hashAlgo
95+
, narHash => $narHash, narSize => $narSize
96+
, patchType => $patchType, hashAlgo => $hashAlgo
10597
};
10698
}
10799

@@ -132,6 +124,7 @@ sub readManifest {
132124
elsif (/^\s*BaseHash:\s*(\S+)\s*$/) { $baseHash = $1; }
133125
elsif (/^\s*Type:\s*(\S+)\s*$/) { $patchType = $1; }
134126
elsif (/^\s*NarHash:\s*(\S+)\s*$/) { $narHash = $1; }
127+
elsif (/^\s*NarSize:\s*(\d+)\s*$/) { $narSize = $1; }
135128
elsif (/^\s*References:\s*(.*)\s*$/) { $references = $1; }
136129
elsif (/^\s*Deriver:\s*(\S+)\s*$/) { $deriver = $1; }
137130
elsif (/^\s*ManifestVersion:\s*(\d+)\s*$/) { $manifestVersion = $1; }
@@ -183,8 +176,9 @@ sub writeManifest {
183176
print MANIFEST " StorePath: $storePath\n";
184177
print MANIFEST " NarURL: $patch->{url}\n";
185178
print MANIFEST " Hash: $patch->{hash}\n";
186-
print MANIFEST " NarHash: $patch->{narHash}\n";
187179
print MANIFEST " Size: $patch->{size}\n";
180+
print MANIFEST " NarHash: $patch->{narHash}\n";
181+
print MANIFEST " NarSize: $patch->{narSize}\n" if $patch->{narSize};
188182
print MANIFEST " BasePath: $patch->{basePath}\n";
189183
print MANIFEST " BaseHash: $patch->{baseHash}\n";
190184
print MANIFEST " Type: $patch->{patchType}\n";

src/libmain/shared.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,26 @@ void printGCWarning()
5454

5555
void printMissing(const PathSet & paths)
5656
{
57-
unsigned long long downloadSize;
57+
unsigned long long downloadSize, narSize;
5858
PathSet willBuild, willSubstitute, unknown;
59-
queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize);
59+
queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize, narSize);
6060

6161
if (!willBuild.empty()) {
62-
printMsg(lvlInfo, format("the following derivations will be built:"));
62+
printMsg(lvlInfo, format("these derivations will be built:"));
6363
foreach (PathSet::iterator, i, willBuild)
6464
printMsg(lvlInfo, format(" %1%") % *i);
6565
}
6666

6767
if (!willSubstitute.empty()) {
68-
printMsg(lvlInfo, format("the following paths will be downloaded/copied (%.2f MiB):") %
69-
(downloadSize / (1024.0 * 1024.0)));
68+
printMsg(lvlInfo, format("these paths will be downloaded/copied (%.2f MiB download, %.2f MiB unpacked):")
69+
% (downloadSize / (1024.0 * 1024.0))
70+
% (narSize / (1024.0 * 1024.0)));
7071
foreach (PathSet::iterator, i, willSubstitute)
7172
printMsg(lvlInfo, format(" %1%") % *i);
7273
}
7374

7475
if (!unknown.empty()) {
75-
printMsg(lvlInfo, format("don't know how to build the following paths%1%:")
76+
printMsg(lvlInfo, format("don't know how to build these paths%1%:")
7677
% (readOnlyMode ? " (may be caused by read-only store access)" : ""));
7778
foreach (PathSet::iterator, i, unknown)
7879
printMsg(lvlInfo, format(" %1%") % *i);

src/libstore/local-store.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ bool LocalStore::querySubstitutablePathInfo(const Path & substituter,
839839
info.references.insert(p);
840840
}
841841
info.downloadSize = getIntLine<long long>(run.from);
842+
info.narSize = getIntLine<long long>(run.from);
842843

843844
return true;
844845
}

src/libstore/misc.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ Path findOutput(const Derivation & drv, string id)
4848

4949
void queryMissing(const PathSet & targets,
5050
PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown,
51-
unsigned long long & downloadSize)
51+
unsigned long long & downloadSize, unsigned long long & narSize)
5252
{
53-
downloadSize = 0;
53+
downloadSize = narSize = 0;
5454

5555
PathSet todo(targets.begin(), targets.end()), done;
5656

@@ -88,6 +88,7 @@ void queryMissing(const PathSet & targets,
8888
if (store->querySubstitutablePathInfo(p, info)) {
8989
willSubstitute.insert(p);
9090
downloadSize += info.downloadSize;
91+
narSize += info.narSize;
9192
todo.insert(info.references.begin(), info.references.end());
9293
} else
9394
unknown.insert(p);

src/libstore/misc.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Path findOutput(const Derivation & drv, string id);
3131
will be substituted. */
3232
void queryMissing(const PathSet & targets,
3333
PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown,
34-
unsigned long long & downloadSize);
34+
unsigned long long & downloadSize, unsigned long long & narSize);
3535

3636

3737
}

src/libstore/remote-store.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,8 @@ void RemoteStore::setOptions()
191191
writeInt(logType, to);
192192
writeInt(printBuildTrace, to);
193193
}
194-
if (GET_PROTOCOL_MINOR(daemonVersion) >= 6) {
194+
if (GET_PROTOCOL_MINOR(daemonVersion) >= 6)
195195
writeInt(buildCores, to);
196-
}
197196
processStderr();
198197
}
199198

@@ -243,6 +242,7 @@ bool RemoteStore::querySubstitutablePathInfo(const Path & path,
243242
if (info.deriver != "") assertStorePath(info.deriver);
244243
info.references = readStorePaths(from);
245244
info.downloadSize = readLongLong(from);
245+
info.narSize = GET_PROTOCOL_MINOR(daemonVersion) >= 7 ? readLongLong(from) : 0;
246246
return true;
247247
}
248248

src/libstore/store-api.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct SubstitutablePathInfo
8787
Path deriver;
8888
PathSet references;
8989
unsigned long long downloadSize; /* 0 = unknown or inapplicable */
90+
unsigned long long narSize; /* 0 = unknown */
9091
};
9192

9293

src/libstore/worker-protocol.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace nix {
88
#define WORKER_MAGIC_1 0x6e697863
99
#define WORKER_MAGIC_2 0x6478696f
1010

11-
#define PROTOCOL_VERSION 0x106
11+
#define PROTOCOL_VERSION 0x107
1212
#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
1313
#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
1414

0 commit comments

Comments
 (0)