From a93e272364db6459f77882cae6d83dad9431bd37 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 19 Nov 2010 15:44:20 +0000 Subject: [PATCH] * Add a NarSize field to Hydra manifests. This allows nix-env to predict how much disk space a package will require. * Compute the output / closure size using the info stored in the Nix database (rather than doing a slow "du"). --- deps.nix | 4 ++-- src/lib/Hydra/Helper/Nix.pm | 13 +------------ src/lib/Hydra/View/NixManifest.pm | 3 ++- src/script/hydra_build.pl.in | 21 ++++++++++++--------- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/deps.nix b/deps.nix index bb3431c9..494136ab 100644 --- a/deps.nix +++ b/deps.nix @@ -8,8 +8,8 @@ let name = "Nix-0.15"; src = fetchsvn { url = https://svn.nixos.org/repos/nix/nix-perl/trunk; - rev = 24765; - sha256 = "12ah8c8p9bx55hd17lhcfc74bd4r1677dxy0id3008pww1aklir7"; + rev = 24774; + sha256 = "1akj695gpnbrjlnwd1gdnnnk7ppvpp1qsinjn04az7q6hjqzbm6p"; }; NIX_PREFIX = nixSqlite; doCheck = false; # tests currently don't work diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 79d39dfe..8cf970cf 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -9,7 +9,7 @@ use Hydra::Helper::CatalystUtils; our @ISA = qw(Exporter); our @EXPORT = qw( - isValidPath queryPathInfo + isValidPath getHydraPath getHydraDBPath openHydraDB txn_do registerRoot getGCRootsDir gcRootFor getPrimaryBuildsForView @@ -23,17 +23,6 @@ sub isValidPath { } -sub queryPathInfo { - my $path = shift; - - my $hash = Nix::queryPathHash($path); - my $deriver = Nix::queryDeriver($path); - my @refs = Nix::queryReferences($path); - - return ($hash, $deriver, \@refs); -} - - sub getHydraPath { my $dir = $ENV{"HYDRA_DATA"}; die "The HYDRA_DATA environment variable is not set!\n" unless defined $dir; diff --git a/src/lib/Hydra/View/NixManifest.pm b/src/lib/Hydra/View/NixManifest.pm index 927cc548..8a672084 100644 --- a/src/lib/Hydra/View/NixManifest.pm +++ b/src/lib/Hydra/View/NixManifest.pm @@ -21,7 +21,7 @@ sub process { "}\n"; foreach my $path (@paths) { - my ($hash, $deriver, $refs) = queryPathInfo $path; + my ($deriver, $hash, $time, $narSize, $refs) = Nix::queryPathInfo $path; # Escape the characters that are allowed to appear in a Nix # path name but have special meaning in a URI. @@ -40,6 +40,7 @@ sub process { (defined $deriver ? " Deriver: $deriver\n" : "") . " NarURL: $url\n" . " NarHash: $hash\n" . + ($narSize != 0 ? " NarSize: $narSize\n" : "") . "}\n"; } diff --git a/src/script/hydra_build.pl.in b/src/script/hydra_build.pl.in index 9a6f5a66..77448c1b 100755 --- a/src/script/hydra_build.pl.in +++ b/src/script/hydra_build.pl.in @@ -199,10 +199,6 @@ sub sendEmailNotification { sendmail($email); } -sub getSize { - my $size = `du -bcs @_ 2> /dev/null | tail -1 | cut -f 1 `; - return int($size); -} sub doBuild { my ($build) = @_; @@ -233,7 +229,7 @@ sub doBuild { # Run Nix to perform the build, and monitor the stderr output # to get notifications about specific build steps, the # associated log files, etc. - my $cmd = "nix-store --realise $drvPath " . + my $cmd = "nix-store -j1 --no-build-hook --realise $drvPath " . "--max-silent-time $maxsilent --keep-going --fallback " . "--no-build-output --log-type flat --print-build-trace " . "--add-root " . gcRootFor $outPath . " 2>&1"; @@ -371,13 +367,20 @@ sub doBuild { done: my $logfile = getBuildLog($drvPath); - my $logsize = defined $logfile ? getSize($logfile) : 0; - my $size = isValidPath($outPath) ? getSize($outPath) : 0; + my $logsize = defined $logfile ? stat($logfile)->size : 0; + my $size = 0; my $closuresize = 0; + if (isValidPath($outPath)) { - (my $hash, my $deriver, my $refs) = queryPathInfo($outPath) ; - $closuresize = getSize(@{$refs}); + my ($deriver, $hash, $time, $narSize, $refs) = Nix::queryPathInfo($outPath); + $size = $narSize; + + my @closure = Nix::computeFSClosure(0, 0, $outPath); + foreach my $path (@closure) { + my ($deriver, $hash, $time, $narSize, $refs) = Nix::queryPathInfo($path); + $closuresize += $narSize; + } } txn_do($db, sub {