* Install NixManifest.pm, NixConfig.pm and GeneratePatches.pm under

the Nix:: namespace.
This commit is contained in:
Eelco Dolstra 2011-10-10 21:11:08 +00:00
parent 659c427caa
commit 6fcdbcac20
20 changed files with 108 additions and 147 deletions

View File

@ -283,6 +283,8 @@ fi
# Check for the required Perl dependencies (DBI and DBD::SQLite). # Check for the required Perl dependencies (DBI and DBD::SQLite).
perlFlags="-I${libdir}/perl5/site_perl"
AC_ARG_WITH(dbi, AC_HELP_STRING([--with-dbi=PATH], AC_ARG_WITH(dbi, AC_HELP_STRING([--with-dbi=PATH],
[prefix of the Perl DBI library]), [prefix of the Perl DBI library]),
perlFlags="$perlFlags -I$withval") perlFlags="$perlFlags -I$withval")

View File

@ -1,4 +1,4 @@
{system, storePath, hashAlgo}: { system, storePath, hashAlgo }:
derivation { derivation {
name = "nar"; name = "nar";

View File

@ -2,7 +2,9 @@ perlversion := $(shell perl -e 'use Config; print $$Config{version};')
perlarchname := $(shell perl -e 'use Config; print $$Config{archname};') perlarchname := $(shell perl -e 'use Config; print $$Config{archname};')
perllibdir = $(libdir)/perl5/site_perl/$(perlversion)/$(perlarchname) perllibdir = $(libdir)/perl5/site_perl/$(perlversion)/$(perlarchname)
install-exec-local: lib/Nix/*.pm all: lib/Nix/Config.pm
install-exec-local: lib/Nix/*.pm lib/Nix/Config.pm
$(INSTALL) -d $(DESTDIR)$(perllibdir)/Nix $(INSTALL) -d $(DESTDIR)$(perllibdir)/Nix
$(INSTALL_DATA) lib/Nix/*.pm $(DESTDIR)$(perllibdir)/Nix $(INSTALL_DATA) lib/Nix/*.pm $(DESTDIR)$(perllibdir)/Nix
$(INSTALL) -d $(DESTDIR)$(perllibdir)/auto/Nix/Store $(INSTALL) -d $(DESTDIR)$(perllibdir)/auto/Nix/Store
@ -22,4 +24,6 @@ AM_CXXFLAGS = \
lib/Nix/Store.cc: lib/Nix/Store.xs lib/Nix/Store.cc: lib/Nix/Store.xs
xsubpp $^ -output $@ xsubpp $^ -output $@
EXTRA_DIST = lib/Nix/*.pm lib/Nix/Store.xs EXTRA_DIST = lib/Nix/Store.pm lib/Nix/Manifest.pm lib/Nix/Config.pm.in lib/Nix/Store.xs
include ../substitute.mk

View File

@ -1,4 +1,12 @@
use strict; package Nix::Config;
$binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
$libexecDir = $ENV{"NIX_LIBEXEC_DIR"} || "@libexecdir@";
$manifestDir = $ENV{"NIX_MANIFESTS_DIR"} || "@localstatedir@/nix/manifests";
$logDir = $ENV{"NIX_LOG_DIR"} || "@localstatedir@/log/nix";
$bzip2 = $ENV{"NIX_BZIP2"} || "@bzip2@";
$curl = "@curl@";
sub readConfig { sub readConfig {
my %config; my %config;

View File

@ -1,6 +1,13 @@
package Nix::GeneratePatches;
use strict; use strict;
use File::Temp qw(tempdir); use File::Temp qw(tempdir);
use File::stat; use File::stat;
use Nix::Config;
use Nix::Manifest;
our @ISA = qw(Exporter);
our @EXPORT = qw(generatePatches propagatePatches copyPatches);
# Some patch generations options. # Some patch generations options.
@ -201,7 +208,7 @@ sub generatePatches {
next; next;
} }
system("@bunzip2@ < $srcNarBz2 > $tmpDir/A") == 0 system("$Nix::Config::bzip2 -d < $srcNarBz2 > $tmpDir/A") == 0
or die "cannot unpack $srcNarBz2"; or die "cannot unpack $srcNarBz2";
if (stat("$tmpDir/A")->size >= $maxNarSize) { if (stat("$tmpDir/A")->size >= $maxNarSize) {
@ -209,7 +216,7 @@ sub generatePatches {
next; next;
} }
system("@bunzip2@ < $dstNarBz2 > $tmpDir/B") == 0 system("$Nix::Config::bzip2 -d < $dstNarBz2 > $tmpDir/B") == 0
or die "cannot unpack $dstNarBz2"; or die "cannot unpack $dstNarBz2";
if (stat("$tmpDir/B")->size >= $maxNarSize) { if (stat("$tmpDir/B")->size >= $maxNarSize) {
@ -218,20 +225,20 @@ sub generatePatches {
} }
my $time1 = time(); my $time1 = time();
my $res = system("ulimit -t $timeLimit; @libexecdir@/bsdiff $tmpDir/A $tmpDir/B $tmpDir/DIFF"); my $res = system("ulimit -t $timeLimit; $Nix::Config::libexecDir/bsdiff $tmpDir/A $tmpDir/B $tmpDir/DIFF");
my $time2 = time(); my $time2 = time();
if ($res) { if ($res) {
warn "binary diff computation aborted after ", $time2 - $time1, " seconds\n"; warn "binary diff computation aborted after ", $time2 - $time1, " seconds\n";
next; next;
} }
my $baseHash = `@bindir@/nix-hash --flat --type $hashAlgo --base32 $tmpDir/A` or die; my $baseHash = `$Nix::Config::binDir/nix-hash --flat --type $hashAlgo --base32 $tmpDir/A` or die;
chomp $baseHash; chomp $baseHash;
my $narHash = `@bindir@/nix-hash --flat --type $hashAlgo --base32 $tmpDir/B` or die; my $narHash = `$Nix::Config::binDir/nix-hash --flat --type $hashAlgo --base32 $tmpDir/B` or die;
chomp $narHash; chomp $narHash;
my $narDiffHash = `@bindir@/nix-hash --flat --type $hashAlgo --base32 $tmpDir/DIFF` or die; my $narDiffHash = `$Nix::Config::binDir/nix-hash --flat --type $hashAlgo --base32 $tmpDir/DIFF` or die;
chomp $narDiffHash; chomp $narDiffHash;
my $narDiffSize = stat("$tmpDir/DIFF")->size; my $narDiffSize = stat("$tmpDir/DIFF")->size;

View File

@ -1,9 +1,15 @@
package Nix::Manifest;
use strict; use strict;
use DBI; use DBI;
use Cwd; use Cwd;
use File::stat; use File::stat;
use File::Path; use File::Path;
use Fcntl ':flock'; use Fcntl ':flock';
use Nix::Config;
our @ISA = qw(Exporter);
our @EXPORT = qw(readManifest writeManifest updateManifestDB addPatch);
sub addNAR { sub addNAR {
@ -200,7 +206,7 @@ sub writeManifest {
# Create a bzipped manifest. # Create a bzipped manifest.
unless (defined $noCompress) { unless (defined $noCompress) {
system("@bzip2@ < $manifest > $manifest.bz2.tmp") == 0 system("$Nix::Config::bzip2 < $manifest > $manifest.bz2.tmp") == 0
or die "cannot compress manifest"; or die "cannot compress manifest";
rename("$manifest.bz2.tmp", "$manifest.bz2") rename("$manifest.bz2.tmp", "$manifest.bz2")
@ -210,7 +216,7 @@ sub writeManifest {
sub updateManifestDB { sub updateManifestDB {
my $manifestDir = ($ENV{"NIX_MANIFESTS_DIR"} or "@localstatedir@/nix/manifests"); my $manifestDir = $Nix::Config::manifestDir;
mkpath($manifestDir); mkpath($manifestDir);
@ -276,7 +282,8 @@ EOF
# Acquire an exclusive lock to ensure that only one process # Acquire an exclusive lock to ensure that only one process
# updates the DB at the same time. This isn't really necessary, # updates the DB at the same time. This isn't really necessary,
# but it prevents work duplication and lock contention in SQLite. # but it prevents work duplication and lock contention in SQLite.
open MAINLOCK, ">>$manifestDir/cache.lock" or die; my $lockFile = "$manifestDir/cache.lock";
open MAINLOCK, ">>$lockFile" or die "unable to acquire lock $lockFile: $!\n";
flock(MAINLOCK, LOCK_EX) or die; flock(MAINLOCK, LOCK_EX) or die;
$dbh->begin_work; $dbh->begin_work;

View File

@ -3,20 +3,17 @@ bin_SCRIPTS = nix-collect-garbage \
nix-install-package nix-channel nix-build \ nix-install-package nix-channel nix-build \
nix-copy-closure nix-generate-patches nix-copy-closure nix-generate-patches
noinst_SCRIPTS = nix-profile.sh GeneratePatches.pm \ noinst_SCRIPTS = nix-profile.sh \
find-runtime-roots.pl build-remote.pl nix-reduce-build \ find-runtime-roots.pl build-remote.pl nix-reduce-build \
copy-from-other-stores.pl nix-http-export.cgi copy-from-other-stores.pl nix-http-export.cgi
nix-pull nix-push: NixManifest.pm NixConfig.pm download-using-manifests.pl nix-pull nix-push: download-using-manifests.pl
install-exec-local: NixManifest.pm GeneratePatches.pm download-using-manifests.pl copy-from-other-stores.pl find-runtime-roots.pl install-exec-local: download-using-manifests.pl copy-from-other-stores.pl find-runtime-roots.pl
$(INSTALL) -d $(DESTDIR)$(sysconfdir)/profile.d $(INSTALL) -d $(DESTDIR)$(sysconfdir)/profile.d
$(INSTALL_PROGRAM) nix-profile.sh $(DESTDIR)$(sysconfdir)/profile.d/nix.sh $(INSTALL_PROGRAM) nix-profile.sh $(DESTDIR)$(sysconfdir)/profile.d/nix.sh
$(INSTALL) -d $(DESTDIR)$(libexecdir)/nix $(INSTALL) -d $(DESTDIR)$(libexecdir)/nix
$(INSTALL_DATA) NixManifest.pm $(DESTDIR)$(libexecdir)/nix
$(INSTALL_DATA) NixConfig.pm $(DESTDIR)$(libexecdir)/nix
$(INSTALL_DATA) SSH.pm $(DESTDIR)$(libexecdir)/nix $(INSTALL_DATA) SSH.pm $(DESTDIR)$(libexecdir)/nix
$(INSTALL_DATA) GeneratePatches.pm $(DESTDIR)$(libexecdir)/nix
$(INSTALL_PROGRAM) find-runtime-roots.pl $(DESTDIR)$(libexecdir)/nix $(INSTALL_PROGRAM) find-runtime-roots.pl $(DESTDIR)$(libexecdir)/nix
$(INSTALL_PROGRAM) build-remote.pl $(DESTDIR)$(libexecdir)/nix $(INSTALL_PROGRAM) build-remote.pl $(DESTDIR)$(libexecdir)/nix
$(INSTALL) -d $(DESTDIR)$(libexecdir)/nix/substituters $(INSTALL) -d $(DESTDIR)$(libexecdir)/nix/substituters
@ -30,7 +27,6 @@ EXTRA_DIST = nix-collect-garbage.in \
nix-pull.in nix-push.in nix-profile.sh.in \ nix-pull.in nix-push.in nix-profile.sh.in \
nix-prefetch-url.in nix-install-package.in \ nix-prefetch-url.in nix-install-package.in \
nix-channel.in \ nix-channel.in \
NixManifest.pm.in \
NixConfig.pm.in \ NixConfig.pm.in \
SSH.pm \ SSH.pm \
GeneratePatches.pm.in \ GeneratePatches.pm.in \

View File

@ -1,16 +1,14 @@
#! @perl@ -w -I@libexecdir@/nix @perlFlags@ #! @perl@ -w @perlFlags@
use strict; use strict;
use NixManifest; use Nix::Config;
use Nix::Manifest;
use POSIX qw(strftime); use POSIX qw(strftime);
use File::Temp qw(tempdir); use File::Temp qw(tempdir);
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
STDOUT->autoflush(1); STDOUT->autoflush(1);
my $manifestDir = ($ENV{"NIX_MANIFESTS_DIR"} or "@localstatedir@/nix/manifests"); my $logFile = "$Nix::Config::logDir/downloads";
my $logFile = "@localstatedir@/log/nix/downloads";
# For queries, skip expensive calls to nix-hash etc. We're just # For queries, skip expensive calls to nix-hash etc. We're just
# estimating the expected download size. # estimating the expected download size.
@ -26,7 +24,7 @@ sub isValidPath {
if ($fast) { if ($fast) {
return -e $p; return -e $p;
} else { } else {
return system("$binDir/nix-store --check-validity '$p' 2> /dev/null") == 0; return system("$Nix::Config::binDir/nix-store --check-validity '$p' 2> /dev/null") == 0;
} }
} }
@ -108,8 +106,8 @@ sub computeSmallestDownload {
my $format = "--base32"; my $format = "--base32";
$format = "" if $baseHashAlgo eq "md5"; $format = "" if $baseHashAlgo eq "md5";
my $hash = $fast && $baseHashAlgo eq "sha256" my $hash = $fast && $baseHashAlgo eq "sha256"
? `$binDir/nix-store -q --hash "$patch->{basePath}"` ? `$Nix::Config::binDir/nix-store -q --hash "$patch->{basePath}"`
: `$binDir/nix-hash --type '$baseHashAlgo' $format "$patch->{basePath}"`; : `$Nix::Config::binDir/nix-hash --type '$baseHashAlgo' $format "$patch->{basePath}"`;
chomp $hash; chomp $hash;
$hash =~ s/.*://; $hash =~ s/.*://;
next if $hash ne $baseHash; next if $hash ne $baseHash;
@ -282,7 +280,7 @@ sub downloadFile {
my $url = shift; my $url = shift;
$ENV{"PRINT_PATH"} = 1; $ENV{"PRINT_PATH"} = 1;
$ENV{"QUIET"} = 1; $ENV{"QUIET"} = 1;
my ($hash, $path) = `$binDir/nix-prefetch-url '$url'`; my ($hash, $path) = `$Nix::Config::binDir/nix-prefetch-url '$url'`;
die "download of `$url' failed" . ($! ? ": $!" : "") unless $? == 0; die "download of `$url' failed" . ($! ? ": $!" : "") unless $? == 0;
chomp $path; chomp $path;
return $path; return $path;
@ -306,7 +304,7 @@ while (scalar @path > 0) {
# as a base to one or more patches. So turn the base path # as a base to one or more patches. So turn the base path
# into a NAR archive, to which we can apply the patch. # into a NAR archive, to which we can apply the patch.
print " packing base path...\n"; print " packing base path...\n";
system("$binDir/nix-store --dump $v > $tmpNar") == 0 system("$Nix::Config::binDir/nix-store --dump $v > $tmpNar") == 0
or die "cannot dump `$v'"; or die "cannot dump `$v'";
} }
} }
@ -324,7 +322,7 @@ while (scalar @path > 0) {
# Apply the patch to the NAR archive produced in step 1 (for # Apply the patch to the NAR archive produced in step 1 (for
# the already present path) or a later step (for patch sequences). # the already present path) or a later step (for patch sequences).
print " applying patch...\n"; print " applying patch...\n";
system("@libexecdir@/bspatch $tmpNar $tmpNar2 $patchPath") == 0 system("$Nix::Config::libexecDir/bspatch $tmpNar $tmpNar2 $patchPath") == 0
or die "cannot apply patch `$patchPath' to $tmpNar"; or die "cannot apply patch `$patchPath' to $tmpNar";
if ($curStep < $maxStep) { if ($curStep < $maxStep) {
@ -334,7 +332,7 @@ while (scalar @path > 0) {
# This was the last patch. Unpack the final NAR archive # This was the last patch. Unpack the final NAR archive
# into the target path. # into the target path.
print " unpacking patched archive...\n"; print " unpacking patched archive...\n";
system("$binDir/nix-store --restore $v < $tmpNar2") == 0 system("$Nix::Config::binDir/nix-store --restore $v < $tmpNar2") == 0
or die "cannot unpack $tmpNar2 into `$v'"; or die "cannot unpack $tmpNar2 into `$v'";
} }
@ -354,12 +352,12 @@ while (scalar @path > 0) {
if ($curStep < $maxStep) { if ($curStep < $maxStep) {
# The archive will be used a base to a patch. # The archive will be used a base to a patch.
system("@bunzip2@ < '$narFilePath' > $tmpNar") == 0 system("$Nix::Config::bzip2 -d < '$narFilePath' > $tmpNar") == 0
or die "cannot unpack `$narFilePath' into `$v'"; or die "cannot unpack `$narFilePath' into `$v'";
} else { } else {
# Unpack the archive into the target path. # Unpack the archive into the target path.
print " unpacking archive...\n"; print " unpacking archive...\n";
system("@bunzip2@ < '$narFilePath' | $binDir/nix-store --restore '$v'") == 0 system("$Nix::Config::bzip2 -d < '$narFilePath' | $Nix::Config::binDir/nix-store --restore '$v'") == 0
or die "cannot unpack `$narFilePath' into `$v'"; or die "cannot unpack `$narFilePath' into `$v'";
} }
@ -382,7 +380,7 @@ if (defined $finalNarHash) {
($hashAlgo eq "sha256" && length($hash) != 64) ($hashAlgo eq "sha256" && length($hash) != 64)
? "--base32" : ""; ? "--base32" : "";
my $hash2 = `@bindir@/nix-hash --type $hashAlgo $extraFlag $targetPath` my $hash2 = `$Nix::Config::binDir/nix-hash --type $hashAlgo $extraFlag $targetPath`
or die "cannot compute hash of path `$targetPath'"; or die "cannot compute hash of path `$targetPath'";
chomp $hash2; chomp $hash2;

View File

@ -1,9 +1,9 @@
#! @perl@ -w -I@libexecdir@/nix @perlFlags@ #! @perl@ -w @perlFlags@
use strict; use strict;
use File::Temp qw(tempdir); use File::Temp qw(tempdir);
use NixManifest; use Nix::Manifest;
use GeneratePatches; use Nix::GeneratePatches;
if (scalar @ARGV != 5) { if (scalar @ARGV != 5) {
print STDERR <<EOF; print STDERR <<EOF;

View File

@ -2,8 +2,7 @@
use strict; use strict;
use File::Temp qw(tempdir); use File::Temp qw(tempdir);
use Nix::Config;
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
sub usageError { sub usageError {
@ -61,7 +60,7 @@ if ($interactive && !defined $ENV{"NIX_HAVE_TERMINAL"}) {
$ENV{"NIX_HAVE_TERMINAL"} = "1"; $ENV{"NIX_HAVE_TERMINAL"} = "1";
$ENV{"LD_LIBRARY_PATH"} = ""; $ENV{"LD_LIBRARY_PATH"} = "";
foreach my $term ("xterm", "konsole", "gnome-terminal", "xterm") { foreach my $term ("xterm", "konsole", "gnome-terminal", "xterm") {
exec($term, "-e", "$binDir/nix-install-package", @ARGV); exec($term, "-e", "$Nix::Config::binDir/nix-install-package", @ARGV);
} }
die "cannot execute `xterm'"; die "cannot execute `xterm'";
} }
@ -132,12 +131,12 @@ $ENV{NIX_REMOTE} = "";
print "\nPulling manifests...\n"; print "\nPulling manifests...\n";
system("$binDir/nix-pull", $manifestURL) == 0 system("$Nix::Config::binDir/nix-pull", $manifestURL) == 0
or barf "nix-pull failed: $?"; or barf "nix-pull failed: $?";
print "\nInstalling package...\n"; print "\nInstalling package...\n";
system("$binDir/nix-env", "--install", $outPath, "--force-name", $drvName, @extraNixEnvArgs) == 0 system("$Nix::Config::binDir/nix-env", "--install", $outPath, "--force-name", $drvName, @extraNixEnvArgs) == 0
or barf "nix-env failed: $?"; or barf "nix-env failed: $?";

View File

@ -3,6 +3,9 @@
url=$1 url=$1
expHash=$2 expHash=$2
binDir=@bindir@
if [ -n "$NIX_BIN_DIR" ]; then binDir="$NIX_BIN_DIR"; fi
# needed to make it work on NixOS # needed to make it work on NixOS
export PATH=$PATH:@coreutils@ export PATH=$PATH:@coreutils@
@ -31,8 +34,8 @@ if test -z "$name"; then echo "invalid url"; exit 1; fi
# If the hash was given, a file with that hash may already be in the # If the hash was given, a file with that hash may already be in the
# store. # store.
if test -n "$expHash"; then if test -n "$expHash"; then
finalPath=$(@bindir@/nix-store --print-fixed-path "$hashType" "$expHash" "$name") finalPath=$($binDir/nix-store --print-fixed-path "$hashType" "$expHash" "$name")
if ! @bindir@/nix-store --check-validity "$finalPath" 2> /dev/null; then if ! $bindir/nix-store --check-validity "$finalPath" 2> /dev/null; then
finalPath= finalPath=
fi fi
hash=$expHash hash=$expHash
@ -103,7 +106,7 @@ if test -z "$finalPath"; then
# garbage-collected independently. # garbage-collected independently.
if test -n "$NIX_DOWNLOAD_CACHE"; then if test -n "$NIX_DOWNLOAD_CACHE"; then
echo -n "$url" > $tmpPath/url echo -n "$url" > $tmpPath/url
urlHash=$(@bindir@/nix-hash --type sha256 --base32 --flat $tmpPath/url) urlHash=$($binDir/nix-hash --type sha256 --base32 --flat $tmpPath/url)
echo "$url" > "$NIX_DOWNLOAD_CACHE/$urlHash.url" echo "$url" > "$NIX_DOWNLOAD_CACHE/$urlHash.url"
cachedHashFN="$NIX_DOWNLOAD_CACHE/$urlHash.$hashType" cachedHashFN="$NIX_DOWNLOAD_CACHE/$urlHash.$hashType"
cachedTimestampFN="$NIX_DOWNLOAD_CACHE/$urlHash.stamp" cachedTimestampFN="$NIX_DOWNLOAD_CACHE/$urlHash.stamp"
@ -121,8 +124,8 @@ if test -z "$finalPath"; then
# Curl didn't create $tmpFile, so apparently there's no newer # Curl didn't create $tmpFile, so apparently there's no newer
# file on the server. # file on the server.
hash=$(cat $cachedHashFN) hash=$(cat $cachedHashFN)
finalPath=$(@bindir@/nix-store --print-fixed-path "$hashType" "$hash" "$name") finalPath=$($binDir/nix-store --print-fixed-path "$hashType" "$hash" "$name")
if ! @bindir@/nix-store --check-validity "$finalPath" 2> /dev/null; then if ! $binDir/nix-store --check-validity "$finalPath" 2> /dev/null; then
echo "cached contents of \`$url' disappeared, redownloading..." >&2 echo "cached contents of \`$url' disappeared, redownloading..." >&2
finalPath= finalPath=
cacheFlags="--remote-time" cacheFlags="--remote-time"
@ -133,7 +136,7 @@ if test -z "$finalPath"; then
if test -z "$finalPath"; then if test -z "$finalPath"; then
# Compute the hash. # Compute the hash.
hash=$(@bindir@/nix-hash --type "$hashType" $hashFormat --flat $tmpFile) hash=$($binDir/nix-hash --type "$hashType" $hashFormat --flat $tmpFile)
if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
if test -n "$NIX_DOWNLOAD_CACHE"; then if test -n "$NIX_DOWNLOAD_CACHE"; then
@ -142,7 +145,7 @@ if test -z "$finalPath"; then
fi fi
# Add the downloaded file to the Nix store. # Add the downloaded file to the Nix store.
finalPath=$(@bindir@/nix-store --add-fixed "$hashType" $tmpFile) finalPath=$($binDir/nix-store --add-fixed "$hashType" $tmpFile)
if test -n "$expHash" -a "$expHash" != "$hash"; then if test -n "$expHash" -a "$expHash" != "$hash"; then
echo "hash mismatch for URL \`$url'" >&2 echo "hash mismatch for URL \`$url'" >&2

View File

@ -1,17 +1,17 @@
#! @perl@ -w -I@libexecdir@/nix @perlFlags@ #! @perl@ -w @perlFlags@
use strict; use strict;
use File::Temp qw(tempdir); use File::Temp qw(tempdir);
use NixManifest; use Nix::Config;
use Nix::Manifest;
my $tmpDir = tempdir("nix-pull.XXXXXX", CLEANUP => 1, TMPDIR => 1) my $tmpDir = tempdir("nix-pull.XXXXXX", CLEANUP => 1, TMPDIR => 1)
or die "cannot create a temporary directory"; or die "cannot create a temporary directory";
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
my $libexecDir = ($ENV{"NIX_LIBEXEC_DIR"} or "@libexecdir@"); my $libexecDir = ($ENV{"NIX_LIBEXEC_DIR"} or "@libexecdir@");
my $storeDir = ($ENV{"NIX_STORE_DIR"} or "@storedir@"); my $storeDir = ($ENV{"NIX_STORE_DIR"} or "@storedir@");
my $stateDir = ($ENV{"NIX_STATE_DIR"} or "@localstatedir@/nix"); my $stateDir = ($ENV{"NIX_STATE_DIR"} or "@localstatedir@/nix");
my $manifestDir = ($ENV{"NIX_MANIFESTS_DIR"} or "$stateDir/manifests"); my $manifestDir = $Nix::Config::manifestDir;
# Prevent access problems in shared-stored installations. # Prevent access problems in shared-stored installations.
@ -42,7 +42,7 @@ sub downloadFile {
my $url = shift; my $url = shift;
$ENV{"PRINT_PATH"} = 1; $ENV{"PRINT_PATH"} = 1;
$ENV{"QUIET"} = 1; $ENV{"QUIET"} = 1;
my ($dummy, $path) = `$binDir/nix-prefetch-url '$url'`; my ($dummy, $path) = `$Nix::Config::binDir/nix-prefetch-url '$url'`;
die "cannot fetch `$url'" if $? != 0; die "cannot fetch `$url'" if $? != 0;
die "nix-prefetch-url did not return a path" unless defined $path; die "nix-prefetch-url did not return a path" unless defined $path;
chomp $path; chomp $path;
@ -57,16 +57,16 @@ sub processURL {
my $manifest; my $manifest;
# First see if a bzipped manifest is available. # First see if a bzipped manifest is available.
if (system("@curl@ --fail --silent --head '$url'.bz2 > /dev/null") == 0) { if (system("$Nix::Config::curl --fail --silent --head '$url'.bz2 > /dev/null") == 0) {
print "fetching list of Nix archives at `$url.bz2'...\n"; print "fetching list of Nix archives at `$url.bz2'...\n";
my $bzipped = downloadFile "$url.bz2"; my $bzipped = downloadFile "$url.bz2";
$manifest = "$tmpDir/MANIFEST"; $manifest = "$tmpDir/MANIFEST";
system("@bunzip2@ < $bzipped > $manifest") == 0 system("$Nix::Config::bzip2 -d < $bzipped > $manifest") == 0
or die "cannot decompress manifest"; or die "cannot decompress manifest";
$manifest = (`$binDir/nix-store --add $manifest` $manifest = (`$Nix::Config::binDir/nix-store --add $manifest`
or die "cannot copy $manifest to the store"); or die "cannot copy $manifest to the store");
chomp $manifest; chomp $manifest;
} }
@ -96,7 +96,7 @@ sub processURL {
$baseName = $1; $baseName = $1;
} }
my $hash = `$binDir/nix-hash --flat '$manifest'` my $hash = `$Nix::Config::binDir/nix-hash --flat '$manifest'`
or die "cannot hash `$manifest'"; or die "cannot hash `$manifest'";
chomp $hash; chomp $hash;

View File

@ -1,9 +1,10 @@
#! @perl@ -w -I@libexecdir@/nix @perlFlags@ #! @perl@ -w @perlFlags@
use strict; use strict;
use File::Temp qw(tempdir); use File::Temp qw(tempdir);
use File::stat; use File::stat;
use NixManifest; use Nix::Config;
use Nix::Manifest;
my $hashAlgo = "sha256"; my $hashAlgo = "sha256";
@ -13,7 +14,7 @@ my $tmpDir = tempdir("nix-push.XXXXXX", CLEANUP => 1, TMPDIR => 1)
my $nixExpr = "$tmpDir/create-nars.nix"; my $nixExpr = "$tmpDir/create-nars.nix";
my $manifest = "$tmpDir/MANIFEST"; my $manifest = "$tmpDir/MANIFEST";
my $curl = "@curl@ --fail --silent"; my $curl = "$Nix::Config::curl --fail --silent";
my $extraCurlFlags = ${ENV{'CURL_FLAGS'}}; my $extraCurlFlags = ${ENV{'CURL_FLAGS'}};
$curl = "$curl $extraCurlFlags" if defined $extraCurlFlags; $curl = "$curl $extraCurlFlags" if defined $extraCurlFlags;
@ -107,7 +108,7 @@ foreach my $storePath (@storePaths) {
# Construct a Nix expression that creates a Nix archive. # Construct a Nix expression that creates a Nix archive.
my $nixexpr = my $nixexpr =
"((import $dataDir/nix/corepkgs/nar/nar.nix) " . "((import $dataDir/nix/corepkgs/nar/nar.nix) " .
"{storePath = builtins.storePath \"$storePath\"; system = \"@system@\"; hashAlgo = \"$hashAlgo\";}) "; "{ storePath = builtins.storePath \"$storePath\"; system = \"@system@\"; hashAlgo = \"$hashAlgo\"; }) ";
print NIX $nixexpr; print NIX $nixexpr;
} }

View File

@ -1,52 +0,0 @@
#! /usr/bin/perl -w -I.
use strict;
use readmanifest;
die unless scalar @ARGV == 2;
my $cache = $ARGV[0];
my $manifest = $ARGV[1];
my %narFiles;
my %patches;
readManifest $manifest, \%narFiles, \%patches;
foreach my $storePath (keys %narFiles) {
my $narFileList = $narFiles{$storePath};
foreach my $narFile (@{$narFileList}) {
if (!defined $narFile->{size} or
!defined $narFile->{narHash})
{
$narFile->{url} =~ /\/([^\/]+)$/;
die unless defined $1;
my $fn = "$cache/$1";
my @info = stat $fn or die;
$narFile->{size} = $info[7];
my $narHash;
my $hashFile = "$fn.NARHASH";
if (-e $hashFile) {
open HASH, "<$hashFile" or die;
$narHash = <HASH>;
close HASH;
} else {
print "$fn\n";
$narHash = `bunzip2 < '$fn' | nix-hash --flat /dev/stdin` or die;
open HASH, ">$hashFile" or die;
print HASH $narHash;
close HASH;
}
chomp $narHash;
$narFile->{narHash} = $narHash;
}
}
}
if (! -e "$manifest.backup") {
system "mv --reply=no '$manifest' '$manifest.backup'";
}
writeManifest $manifest, \%narFiles, \%patches;

View File

@ -6,13 +6,13 @@
-e "s^@sysconfdir\@^$(sysconfdir)^g" \ -e "s^@sysconfdir\@^$(sysconfdir)^g" \
-e "s^@localstatedir\@^$(localstatedir)^g" \ -e "s^@localstatedir\@^$(localstatedir)^g" \
-e "s^@datadir\@^$(datadir)^g" \ -e "s^@datadir\@^$(datadir)^g" \
-e "s^@libdir\@^$(libdir)^g" \
-e "s^@libexecdir\@^$(libexecdir)^g" \ -e "s^@libexecdir\@^$(libexecdir)^g" \
-e "s^@storedir\@^$(storedir)^g" \ -e "s^@storedir\@^$(storedir)^g" \
-e "s^@system\@^$(system)^g" \ -e "s^@system\@^$(system)^g" \
-e "s^@shell\@^$(bash)^g" \ -e "s^@shell\@^$(bash)^g" \
-e "s^@curl\@^$(curl)^g" \ -e "s^@curl\@^$(curl)^g" \
-e "s^@bzip2\@^$(bzip2_bin)/bzip2^g" \ -e "s^@bzip2\@^$(bzip2_bin)/bzip2^g" \
-e "s^@bunzip2\@^$(bzip2_bin)/bunzip2^g" \
-e "s^@bzip2_bin_test\@^$(bzip2_bin_test)^g" \ -e "s^@bzip2_bin_test\@^$(bzip2_bin_test)^g" \
-e "s^@perl\@^$(perl)^g" \ -e "s^@perl\@^$(perl)^g" \
-e "s^@perlFlags\@^$(perlFlags)^g" \ -e "s^@perlFlags\@^$(perlFlags)^g" \

View File

@ -7,22 +7,22 @@ mkdir -p $TEST_ROOT/cache2 $TEST_ROOT/patches
RESULT=$TEST_ROOT/result RESULT=$TEST_ROOT/result
# Build version 1 and 2 of the "foo" package. # Build version 1 and 2 of the "foo" package.
$NIX_BIN_DIR/nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest1 \ nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest1 \
$($nixbuild -o $RESULT binary-patching.nix --arg version 1) $($nixbuild -o $RESULT binary-patching.nix --arg version 1)
out2=$($nixbuild -o $RESULT binary-patching.nix --arg version 2) out2=$($nixbuild -o $RESULT binary-patching.nix --arg version 2)
$NIX_BIN_DIR/nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest2 $out2 nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest2 $out2
out3=$($nixbuild -o $RESULT binary-patching.nix --arg version 3) out3=$($nixbuild -o $RESULT binary-patching.nix --arg version 3)
$NIX_BIN_DIR/nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest3 $out3 nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest3 $out3
rm $RESULT rm $RESULT
# Generate binary patches. # Generate binary patches.
$NIX_BIN_DIR/nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \ nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \
file://$TEST_ROOT/patches $TEST_ROOT/manifest1 $TEST_ROOT/manifest2 file://$TEST_ROOT/patches $TEST_ROOT/manifest1 $TEST_ROOT/manifest2
$NIX_BIN_DIR/nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \ nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \
file://$TEST_ROOT/patches $TEST_ROOT/manifest2 $TEST_ROOT/manifest3 file://$TEST_ROOT/patches $TEST_ROOT/manifest2 $TEST_ROOT/manifest3
grep -q "patch {" $TEST_ROOT/manifest3 grep -q "patch {" $TEST_ROOT/manifest3
@ -45,7 +45,7 @@ rm $RESULT
[ "$(grep ' patch ' $TEST_ROOT/var/log/nix/downloads | wc -l)" -eq 2 ] [ "$(grep ' patch ' $TEST_ROOT/var/log/nix/downloads | wc -l)" -eq 2 ]
# Add a patch from version 1 directly to version 3. # Add a patch from version 1 directly to version 3.
$NIX_BIN_DIR/nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \ nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \
file://$TEST_ROOT/patches $TEST_ROOT/manifest1 $TEST_ROOT/manifest3 file://$TEST_ROOT/patches $TEST_ROOT/manifest1 $TEST_ROOT/manifest3
# Rebuild version 3. This should use the direct patch rather than the # Rebuild version 3. This should use the direct patch rather than the

View File

@ -1,5 +1,7 @@
set -e set -e
export TOP=$(pwd)/..
export TEST_ROOT=$(pwd)/test-tmp export TEST_ROOT=$(pwd)/test-tmp
export NIX_STORE_DIR export NIX_STORE_DIR
if ! NIX_STORE_DIR=$(readlink -f $TEST_ROOT/store 2> /dev/null); then if ! NIX_STORE_DIR=$(readlink -f $TEST_ROOT/store 2> /dev/null); then
@ -15,9 +17,12 @@ export NIX_DB_DIR=$TEST_ROOT/db
export NIX_CONF_DIR=$TEST_ROOT/etc export NIX_CONF_DIR=$TEST_ROOT/etc
export NIX_BIN_DIR=$TEST_ROOT/bin export NIX_BIN_DIR=$TEST_ROOT/bin
export NIX_LIBEXEC_DIR=$TEST_ROOT/bin export NIX_LIBEXEC_DIR=$TEST_ROOT/bin
export NIX_MANIFESTS_DIR=$TEST_ROOT/var/nix/manifests
export NIX_ROOT_FINDER= export NIX_ROOT_FINDER=
export SHARED=$TEST_ROOT/shared export SHARED=$TEST_ROOT/shared
export PATH=$NIX_BIN_DIR:$TOP/scripts:$PATH
export NIX_REMOTE= export NIX_REMOTE=
export REAL_BIN_DIR=@bindir@ export REAL_BIN_DIR=@bindir@
@ -27,10 +32,10 @@ export REAL_DATA_DIR=@datadir@
export REAL_STORE_DIR=@storedir@ export REAL_STORE_DIR=@storedir@
export NIX_BUILD_HOOK= export NIX_BUILD_HOOK=
export PERL=perl export PERL=perl
export TOP=$(pwd)/.. export PERL5LIB=$TOP/perl/lib
export bzip2_bin_test="@bzip2_bin_test@" export NIX_BZIP2="@bzip2_bin_test@/bzip2"
if test "${bzip2_bin_test:0:1}" != "/"; then if test "${NIX_BZIP2:0:1}" != "/"; then
bzip2_bin_test=`pwd`/${bzip2_bin_test} NIX_BZIP2=`pwd`/${NIX_BZIP2}
fi fi
export dot=@dot@ export dot=@dot@
export xmllint="@xmllint@" export xmllint="@xmllint@"

View File

@ -29,16 +29,11 @@ ln -s $TOP/scripts/nix-prefetch-url $NIX_BIN_DIR/
ln -s $TOP/scripts/nix-collect-garbage $NIX_BIN_DIR/ ln -s $TOP/scripts/nix-collect-garbage $NIX_BIN_DIR/
ln -s $TOP/scripts/nix-build $NIX_BIN_DIR/ ln -s $TOP/scripts/nix-build $NIX_BIN_DIR/
ln -s $TOP/scripts/nix-install-package $NIX_BIN_DIR/ ln -s $TOP/scripts/nix-install-package $NIX_BIN_DIR/
ln -s $TOP/scripts/nix-push $NIX_BIN_DIR/
ln -s $TOP/scripts/nix-pull $NIX_BIN_DIR/ ln -s $TOP/scripts/nix-pull $NIX_BIN_DIR/
ln -s $TOP/scripts/nix-generate-patches $NIX_BIN_DIR/
mkdir $NIX_BIN_DIR/nix mkdir $NIX_BIN_DIR/nix
ln -s $bzip2_bin_test/bzip2 $NIX_BIN_DIR/nix/ ln -s $NIX_BZIP2 $NIX_BIN_DIR/nix/
ln -s $bzip2_bin_test/bunzip2 $NIX_BIN_DIR/nix/
ln -s $TOP/scripts/copy-from-other-stores.pl $NIX_BIN_DIR/nix/ ln -s $TOP/scripts/copy-from-other-stores.pl $NIX_BIN_DIR/nix/
ln -s $TOP/scripts/download-using-manifests.pl $NIX_BIN_DIR/nix/ ln -s $TOP/scripts/download-using-manifests.pl $NIX_BIN_DIR/nix/
ln -s $TOP/scripts/GeneratePatches.pm $NIX_BIN_DIR/nix/
ln -s $TOP/scripts/NixManifest.pm $NIX_BIN_DIR/nix/
cat > "$NIX_CONF_DIR"/nix.conf <<EOF cat > "$NIX_CONF_DIR"/nix.conf <<EOF
gc-keep-outputs = false gc-keep-outputs = false
@ -53,17 +48,6 @@ cp -pr $TOP/corepkgs $NIX_DATA_DIR/nix/
# (and likely to fail). # (and likely to fail).
for i in \ for i in \
$NIX_DATA_DIR/nix/corepkgs/nar/nar.sh \ $NIX_DATA_DIR/nix/corepkgs/nar/nar.sh \
$NIX_BIN_DIR/nix/download-using-manifests.pl \
$NIX_BIN_DIR/nix/copy-from-other-stores.pl \
$NIX_BIN_DIR/nix-prefetch-url \
$NIX_BIN_DIR/nix-collect-garbage \
$NIX_BIN_DIR/nix-build \
$NIX_BIN_DIR/nix-install-package \
$NIX_BIN_DIR/nix-push \
$NIX_BIN_DIR/nix-pull \
$NIX_BIN_DIR/nix-generate-patches \
$NIX_BIN_DIR/nix/NixManifest.pm \
$NIX_BIN_DIR/nix/GeneratePatches.pm \
; do ; do
sed < $i > $i.tmp \ sed < $i > $i.tmp \
-e "s^$REAL_BIN_DIR/nix-store^$NIX_BIN_DIR/nix-store^" \ -e "s^$REAL_BIN_DIR/nix-store^$NIX_BIN_DIR/nix-store^" \

View File

@ -2,7 +2,7 @@ source common.sh
pullCache () { pullCache () {
echo "pulling cache..." echo "pulling cache..."
$NIX_BIN_DIR/nix-pull file://$TEST_ROOT/manifest nix-pull file://$TEST_ROOT/manifest
} }
clearStore clearStore

View File

@ -7,5 +7,4 @@ echo "pushing $drvPath"
mkdir -p $TEST_ROOT/cache mkdir -p $TEST_ROOT/cache
$NIX_BIN_DIR/nix-push \ nix-push --copy $TEST_ROOT/cache $TEST_ROOT/manifest $drvPath
--copy $TEST_ROOT/cache $TEST_ROOT/manifest $drvPath