From 13114daa3e38abc5c84987830d9276b93251592f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 12 Sep 2011 09:07:43 +0000 Subject: [PATCH 01/23] * Ouch. A store upgrade could cause a substituter to be triggered, causing a deadlock. --- src/libstore/derivations.cc | 3 ++- src/libstore/local-store.cc | 6 +++--- src/libstore/local-store.hh | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 5a0f4ecc69..97343d57d4 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -239,7 +239,8 @@ Hash hashDerivationModulo(StoreAPI & store, Derivation drv) foreach (DerivationInputs::const_iterator, i, drv.inputDrvs) { Hash h = drvHashes[i->first]; if (h.type == htUnknown) { - Derivation drv2 = derivationFromPath(store, i->first); + assert(store.isValidPath(i->first)); + Derivation drv2 = parseDerivation(readFile(i->first)); h = hashDerivationModulo(store, drv2); drvHashes[i->first] = h; } diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 6ad4c84c69..702ff67e79 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -510,7 +510,7 @@ void LocalStore::checkDerivationOutputs(const Path & drvPath, const Derivation & } -unsigned long long LocalStore::addValidPath(const ValidPathInfo & info) +unsigned long long LocalStore::addValidPath(const ValidPathInfo & info, bool checkOutputs) { SQLiteStmtUse use(stmtRegisterValidPath); stmtRegisterValidPath.bind(info.path); @@ -540,7 +540,7 @@ unsigned long long LocalStore::addValidPath(const ValidPathInfo & info) derivations). Note that if this throws an error, then the DB transaction is rolled back, so the path validity registration above is undone. */ - checkDerivationOutputs(info.path, drv); + if (checkOutputs) checkDerivationOutputs(info.path, drv); foreach (DerivationOutputs::iterator, i, drv.outputs) { SQLiteStmtUse use(stmtAddDerivationOutput); @@ -1521,7 +1521,7 @@ void LocalStore::upgradeStore6() SQLiteTxn txn(db); foreach (PathSet::iterator, i, validPaths) { - addValidPath(queryPathInfoOld(*i)); + addValidPath(queryPathInfoOld(*i), false); std::cerr << "."; } diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 8cf6b66406..7ef01b2644 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -226,7 +226,7 @@ private: unsigned long long queryValidPathId(const Path & path); - unsigned long long addValidPath(const ValidPathInfo & info); + unsigned long long addValidPath(const ValidPathInfo & info, bool checkOutputs = true); void addReference(unsigned long long referrer, unsigned long long reference); From 55481c44d4767ffde561c02b039717916e0536f6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 17 Sep 2011 09:53:31 +0000 Subject: [PATCH 02/23] * Don't assume that we want a shared Nix store. --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index cb1a321ddd..0e1d1413ce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,7 +33,7 @@ init-state: $(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/temproots ln -sfn $(localstatedir)/nix/profiles $(DESTDIR)$(localstatedir)/nix/gcroots/profiles $(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/userpool - -$(INSTALL) $(INIT_FLAGS) -m 1777 -d $(DESTDIR)$(storedir) + -$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(storedir) $(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/manifests ln -sfn $(localstatedir)/nix/manifests $(DESTDIR)$(localstatedir)/nix/gcroots/manifests From 73fe6871c479f7670f8c93b0cc9ef7bb1a851777 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Oct 2011 18:12:40 +0000 Subject: [PATCH 03/23] * Include the Nix Perl bindings in Nix itself. This will allow the bindings to be used in Nix's own Perl scripts. The only downside is that Perl XS and Automake/libtool don't really like each other, so building is a bit tricky. --- Makefile.am | 2 +- configure.ac | 1 + perl/MANIFEST | 7 +++ perl/Makefile.am | 25 ++++++++ perl/lib/Nix/Store.pm | 23 ++++++++ perl/lib/Nix/Store.xs | 129 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 perl/MANIFEST create mode 100644 perl/Makefile.am create mode 100644 perl/lib/Nix/Store.pm create mode 100644 perl/lib/Nix/Store.xs diff --git a/Makefile.am b/Makefile.am index 0e1d1413ce..b946b1e362 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = externals src scripts corepkgs doc misc tests +SUBDIRS = externals src perl scripts corepkgs doc misc tests EXTRA_DIST = substitute.mk nix.spec nix.spec.in bootstrap.sh \ nix.conf.example NEWS version diff --git a/configure.ac b/configure.ac index 3b8617f93d..b0ce642a79 100644 --- a/configure.ac +++ b/configure.ac @@ -341,6 +341,7 @@ AC_CONFIG_FILES([Makefile src/nix-setuid-helper/Makefile src/nix-log2xml/Makefile src/bsdiff-4.3/Makefile + perl/Makefile scripts/Makefile corepkgs/Makefile corepkgs/nar/Makefile diff --git a/perl/MANIFEST b/perl/MANIFEST new file mode 100644 index 0000000000..08897647c9 --- /dev/null +++ b/perl/MANIFEST @@ -0,0 +1,7 @@ +Changes +Makefile.PL +MANIFEST +Nix.xs +README +t/Nix.t +lib/Nix.pm diff --git a/perl/Makefile.am b/perl/Makefile.am new file mode 100644 index 0000000000..548708a338 --- /dev/null +++ b/perl/Makefile.am @@ -0,0 +1,25 @@ +perlversion := $(shell perl -e 'use Config; print $$Config{version};') +perlarchname := $(shell perl -e 'use Config; print $$Config{archname};') +perllibdir = $(libdir)/perl5/site_perl/$(perlversion)/$(perlarchname) + +install-exec-local: lib/Nix/*.pm + $(INSTALL) -d $(DESTDIR)$(perllibdir)/Nix + $(INSTALL_DATA) lib/Nix/*.pm $(DESTDIR)$(perllibdir)/Nix + $(INSTALL) -d $(DESTDIR)$(perllibdir)/auto/Nix/Store + ln -sfn $(pkglibdir)/libNixStore.so $(DESTDIR)$(perllibdir)/auto/Nix/Store/Store.so + +# Awful hackery to get libtool to build Perl XS bindings. +pkglib_LTLIBRARIES = libNixStore.la + +libNixStore_la_SOURCES = lib/Nix/Store.cc + +libNixStore_la_LIBADD = $(top_srcdir)/src/libstore/libstore.la + +AM_CXXFLAGS = \ + -I$(top_srcdir)/src -I$(top_srcdir)/src/libutil -I$(top_srcdir)/src/libstore \ + -I$(shell perl -e 'use Config; print $$Config{archlibexp};')/CORE + +lib/Nix/Store.cc: lib/Nix/Store.xs + xsubpp $^ -output $@ + +EXTRA_DIST = lib/Nix/*.pm lib/Nix/Store.xs diff --git a/perl/lib/Nix/Store.pm b/perl/lib/Nix/Store.pm new file mode 100644 index 0000000000..af69debeda --- /dev/null +++ b/perl/lib/Nix/Store.pm @@ -0,0 +1,23 @@ +package Nix::Store; + +use 5.010001; +use strict; +use warnings; + +require Exporter; + +our @ISA = qw(Exporter); + +our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); + +our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); + +our @EXPORT = qw( ); + +our $VERSION = '0.15'; + +require XSLoader; +XSLoader::load('Nix::Store', $VERSION); + +1; +__END__ diff --git a/perl/lib/Nix/Store.xs b/perl/lib/Nix/Store.xs new file mode 100644 index 0000000000..dd5cffdbb7 --- /dev/null +++ b/perl/lib/Nix/Store.xs @@ -0,0 +1,129 @@ +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +/* Prevent a clash between some Perl and libstdc++ macros. */ +#undef do_open +#undef do_close + +#include +#include +#include +#include + + +using namespace nix; + + +void doInit() +{ + if (!store) { + nixStore = canonPath(getEnv("NIX_STORE_DIR", getEnv("NIX_STORE", "/nix/store"))); + nixStateDir = canonPath(getEnv("NIX_STATE_DIR", "/nix/var/nix")); + nixDBPath = getEnv("NIX_DB_DIR", nixStateDir + "/db"); + try { + store = openStore(); + } catch (Error & e) { + croak(e.what()); + } + } +} + + +MODULE = Nix::Store PACKAGE = Nix::Store +PROTOTYPES: ENABLE + + +void init() + CODE: + doInit(); + + +int isValidPath(path) + char * path + CODE: + try { + doInit(); + RETVAL = store->isValidPath(path); + } catch (Error & e) { + croak(e.what()); + } + OUTPUT: + RETVAL + + +SV * queryReferences(path) + char * path + PPCODE: + try { + doInit(); + PathSet paths; + store->queryReferences(path, paths); + for (PathSet::iterator i = paths.begin(); i != paths.end(); ++i) + XPUSHs(sv_2mortal(newSVpv(i->c_str(), 0))); + } catch (Error & e) { + croak(e.what()); + } + + +SV * queryPathHash(path) + char * path + PPCODE: + try { + doInit(); + Hash hash = store->queryPathHash(path); + string s = "sha256:" + printHash(hash); + XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0))); + } catch (Error & e) { + croak(e.what()); + } + + +SV * queryDeriver(path) + char * path + PPCODE: + try { + doInit(); + Path deriver = store->queryDeriver(path); + if (deriver == "") XSRETURN_UNDEF; + XPUSHs(sv_2mortal(newSVpv(deriver.c_str(), 0))); + } catch (Error & e) { + croak(e.what()); + } + + +SV * queryPathInfo(path) + char * path + PPCODE: + try { + doInit(); + ValidPathInfo info = store->queryPathInfo(path); + if (info.deriver == "") + XPUSHs(&PL_sv_undef); + else + XPUSHs(sv_2mortal(newSVpv(info.deriver.c_str(), 0))); + string s = "sha256:" + printHash(info.hash); + XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0))); + mXPUSHi(info.registrationTime); + mXPUSHi(info.narSize); + AV * arr = newAV(); + for (PathSet::iterator i = info.references.begin(); i != info.references.end(); ++i) + av_push(arr, newSVpv(i->c_str(), 0)); + XPUSHs(sv_2mortal(newRV((SV *) arr))); + } catch (Error & e) { + croak(e.what()); + } + + +SV * computeFSClosure(int flipDirection, int includeOutputs, ...) + PPCODE: + try { + doInit(); + PathSet paths; + for (int n = 2; n < items; ++n) + computeFSClosure(*store, SvPV_nolen(ST(n)), paths, flipDirection, includeOutputs); + for (PathSet::iterator i = paths.begin(); i != paths.end(); ++i) + XPUSHs(sv_2mortal(newSVpv(i->c_str(), 0))); + } catch (Error & e) { + croak(e.what()); + } From 659c427caa39e44e5861ff1345425e4c34c9ced3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Oct 2011 18:58:49 +0000 Subject: [PATCH 04/23] * Hopefully perl-devel contains the required headers (untested). --- nix.spec.in | 1 + release.nix | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/nix.spec.in b/nix.spec.in index 1819c849a3..e23f537ffe 100644 --- a/nix.spec.in +++ b/nix.spec.in @@ -20,6 +20,7 @@ Prefix: /usr Requires: /usr/bin/perl Requires: curl Requires: perl-DBD-SQLite +Requires: perl-devel # Hack to make that shitty RPM scanning hack shut up. Provides: perl(readmanifest) diff --git a/release.nix b/release.nix index 2851ff39c1..cc210d2c6d 100644 --- a/release.nix +++ b/release.nix @@ -155,7 +155,7 @@ let name = "nix-rpm-${diskImage.name}"; src = jobs.tarball; diskImage = (diskImageFun vmTools.diskImageFuns) - { extraPackages = [ "perl-DBD-SQLite" ]; }; + { extraPackages = [ "perl-DBD-SQLite" "perl-devel" ]; }; memSize = 1024; meta.schedulingPriority = prio; }; From 6fcdbcac202e40e5de7147ff64b34d6aaad16249 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Oct 2011 21:11:08 +0000 Subject: [PATCH 05/23] * Install NixManifest.pm, NixConfig.pm and GeneratePatches.pm under the Nix:: namespace. --- configure.ac | 2 + corepkgs/nar/nar.nix | 2 +- perl/Makefile.am | 8 ++- .../lib/Nix/Config.pm.in | 10 +++- .../lib/Nix/GeneratePatches.pm | 19 ++++--- .../lib/Nix/Manifest.pm | 13 +++-- scripts/Makefile.am | 10 ++-- scripts/download-using-manifests.pl.in | 30 +++++------ scripts/nix-generate-patches.in | 6 +-- scripts/nix-install-package.in | 9 ++-- scripts/nix-prefetch-url.in | 17 +++--- scripts/nix-pull.in | 18 +++---- scripts/nix-push.in | 9 ++-- scripts/update-manifest.pl | 52 ------------------- substitute.mk | 2 +- tests/binary-patching.sh | 12 ++--- tests/common.sh.in | 13 +++-- tests/init.sh | 18 +------ tests/nix-pull.sh | 2 +- tests/nix-push.sh | 3 +- 20 files changed, 108 insertions(+), 147 deletions(-) rename scripts/NixConfig.pm.in => perl/lib/Nix/Config.pm.in (51%) rename scripts/GeneratePatches.pm.in => perl/lib/Nix/GeneratePatches.pm (92%) rename scripts/NixManifest.pm.in => perl/lib/Nix/Manifest.pm (96%) delete mode 100755 scripts/update-manifest.pl diff --git a/configure.ac b/configure.ac index b0ce642a79..876e0a862e 100644 --- a/configure.ac +++ b/configure.ac @@ -283,6 +283,8 @@ fi # 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], [prefix of the Perl DBI library]), perlFlags="$perlFlags -I$withval") diff --git a/corepkgs/nar/nar.nix b/corepkgs/nar/nar.nix index da63bde9a6..d3d799998f 100644 --- a/corepkgs/nar/nar.nix +++ b/corepkgs/nar/nar.nix @@ -1,4 +1,4 @@ -{system, storePath, hashAlgo}: +{ system, storePath, hashAlgo }: derivation { name = "nar"; diff --git a/perl/Makefile.am b/perl/Makefile.am index 548708a338..a459bdc87c 100644 --- a/perl/Makefile.am +++ b/perl/Makefile.am @@ -2,7 +2,9 @@ perlversion := $(shell perl -e 'use Config; print $$Config{version};') perlarchname := $(shell perl -e 'use Config; print $$Config{archname};') 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_DATA) lib/Nix/*.pm $(DESTDIR)$(perllibdir)/Nix $(INSTALL) -d $(DESTDIR)$(perllibdir)/auto/Nix/Store @@ -22,4 +24,6 @@ AM_CXXFLAGS = \ lib/Nix/Store.cc: lib/Nix/Store.xs 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 diff --git a/scripts/NixConfig.pm.in b/perl/lib/Nix/Config.pm.in similarity index 51% rename from scripts/NixConfig.pm.in rename to perl/lib/Nix/Config.pm.in index aeb443aeed..658305fd97 100644 --- a/scripts/NixConfig.pm.in +++ b/perl/lib/Nix/Config.pm.in @@ -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 { my %config; diff --git a/scripts/GeneratePatches.pm.in b/perl/lib/Nix/GeneratePatches.pm similarity index 92% rename from scripts/GeneratePatches.pm.in rename to perl/lib/Nix/GeneratePatches.pm index 4bb5b05a8c..f9d83c49c8 100644 --- a/scripts/GeneratePatches.pm.in +++ b/perl/lib/Nix/GeneratePatches.pm @@ -1,6 +1,13 @@ +package Nix::GeneratePatches; + use strict; use File::Temp qw(tempdir); use File::stat; +use Nix::Config; +use Nix::Manifest; + +our @ISA = qw(Exporter); +our @EXPORT = qw(generatePatches propagatePatches copyPatches); # Some patch generations options. @@ -201,7 +208,7 @@ sub generatePatches { next; } - system("@bunzip2@ < $srcNarBz2 > $tmpDir/A") == 0 + system("$Nix::Config::bzip2 -d < $srcNarBz2 > $tmpDir/A") == 0 or die "cannot unpack $srcNarBz2"; if (stat("$tmpDir/A")->size >= $maxNarSize) { @@ -209,7 +216,7 @@ sub generatePatches { next; } - system("@bunzip2@ < $dstNarBz2 > $tmpDir/B") == 0 + system("$Nix::Config::bzip2 -d < $dstNarBz2 > $tmpDir/B") == 0 or die "cannot unpack $dstNarBz2"; if (stat("$tmpDir/B")->size >= $maxNarSize) { @@ -218,20 +225,20 @@ sub generatePatches { } 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(); if ($res) { warn "binary diff computation aborted after ", $time2 - $time1, " seconds\n"; 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; - 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; - 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; my $narDiffSize = stat("$tmpDir/DIFF")->size; diff --git a/scripts/NixManifest.pm.in b/perl/lib/Nix/Manifest.pm similarity index 96% rename from scripts/NixManifest.pm.in rename to perl/lib/Nix/Manifest.pm index d080dcee74..7790cfe3b9 100644 --- a/scripts/NixManifest.pm.in +++ b/perl/lib/Nix/Manifest.pm @@ -1,9 +1,15 @@ +package Nix::Manifest; + use strict; use DBI; use Cwd; use File::stat; use File::Path; use Fcntl ':flock'; +use Nix::Config; + +our @ISA = qw(Exporter); +our @EXPORT = qw(readManifest writeManifest updateManifestDB addPatch); sub addNAR { @@ -200,7 +206,7 @@ sub writeManifest { # Create a bzipped manifest. unless (defined $noCompress) { - system("@bzip2@ < $manifest > $manifest.bz2.tmp") == 0 + system("$Nix::Config::bzip2 < $manifest > $manifest.bz2.tmp") == 0 or die "cannot compress manifest"; rename("$manifest.bz2.tmp", "$manifest.bz2") @@ -210,7 +216,7 @@ sub writeManifest { sub updateManifestDB { - my $manifestDir = ($ENV{"NIX_MANIFESTS_DIR"} or "@localstatedir@/nix/manifests"); + my $manifestDir = $Nix::Config::manifestDir; mkpath($manifestDir); @@ -276,7 +282,8 @@ EOF # Acquire an exclusive lock to ensure that only one process # updates the DB at the same time. This isn't really necessary, # 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; $dbh->begin_work; diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 60bb0a9b81..752fcd5740 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -3,20 +3,17 @@ bin_SCRIPTS = nix-collect-garbage \ nix-install-package nix-channel nix-build \ 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 \ 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_PROGRAM) nix-profile.sh $(DESTDIR)$(sysconfdir)/profile.d/nix.sh $(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) GeneratePatches.pm $(DESTDIR)$(libexecdir)/nix $(INSTALL_PROGRAM) find-runtime-roots.pl $(DESTDIR)$(libexecdir)/nix $(INSTALL_PROGRAM) build-remote.pl $(DESTDIR)$(libexecdir)/nix $(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-prefetch-url.in nix-install-package.in \ nix-channel.in \ - NixManifest.pm.in \ NixConfig.pm.in \ SSH.pm \ GeneratePatches.pm.in \ diff --git a/scripts/download-using-manifests.pl.in b/scripts/download-using-manifests.pl.in index ca4d97b51a..a827a995f9 100644 --- a/scripts/download-using-manifests.pl.in +++ b/scripts/download-using-manifests.pl.in @@ -1,16 +1,14 @@ -#! @perl@ -w -I@libexecdir@/nix @perlFlags@ +#! @perl@ -w @perlFlags@ use strict; -use NixManifest; +use Nix::Config; +use Nix::Manifest; use POSIX qw(strftime); use File::Temp qw(tempdir); -my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@"; - STDOUT->autoflush(1); -my $manifestDir = ($ENV{"NIX_MANIFESTS_DIR"} or "@localstatedir@/nix/manifests"); -my $logFile = "@localstatedir@/log/nix/downloads"; +my $logFile = "$Nix::Config::logDir/downloads"; # For queries, skip expensive calls to nix-hash etc. We're just # estimating the expected download size. @@ -26,7 +24,7 @@ sub isValidPath { if ($fast) { return -e $p; } 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"; $format = "" if $baseHashAlgo eq "md5"; my $hash = $fast && $baseHashAlgo eq "sha256" - ? `$binDir/nix-store -q --hash "$patch->{basePath}"` - : `$binDir/nix-hash --type '$baseHashAlgo' $format "$patch->{basePath}"`; + ? `$Nix::Config::binDir/nix-store -q --hash "$patch->{basePath}"` + : `$Nix::Config::binDir/nix-hash --type '$baseHashAlgo' $format "$patch->{basePath}"`; chomp $hash; $hash =~ s/.*://; next if $hash ne $baseHash; @@ -282,7 +280,7 @@ sub downloadFile { my $url = shift; $ENV{"PRINT_PATH"} = 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; chomp $path; return $path; @@ -306,7 +304,7 @@ while (scalar @path > 0) { # as a base to one or more patches. So turn the base path # into a NAR archive, to which we can apply the patch. 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'"; } } @@ -324,7 +322,7 @@ while (scalar @path > 0) { # Apply the patch to the NAR archive produced in step 1 (for # the already present path) or a later step (for patch sequences). 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"; if ($curStep < $maxStep) { @@ -334,7 +332,7 @@ while (scalar @path > 0) { # This was the last patch. Unpack the final NAR archive # into the target path. 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'"; } @@ -354,12 +352,12 @@ while (scalar @path > 0) { if ($curStep < $maxStep) { # 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'"; } else { # Unpack the archive into the target path. 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'"; } @@ -382,7 +380,7 @@ if (defined $finalNarHash) { ($hashAlgo eq "sha256" && length($hash) != 64) ? "--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'"; chomp $hash2; diff --git a/scripts/nix-generate-patches.in b/scripts/nix-generate-patches.in index 1f32ab4109..4cb843382b 100644 --- a/scripts/nix-generate-patches.in +++ b/scripts/nix-generate-patches.in @@ -1,9 +1,9 @@ -#! @perl@ -w -I@libexecdir@/nix @perlFlags@ +#! @perl@ -w @perlFlags@ use strict; use File::Temp qw(tempdir); -use NixManifest; -use GeneratePatches; +use Nix::Manifest; +use Nix::GeneratePatches; if (scalar @ARGV != 5) { print STDERR < /dev/null; then + finalPath=$($binDir/nix-store --print-fixed-path "$hashType" "$expHash" "$name") + if ! $bindir/nix-store --check-validity "$finalPath" 2> /dev/null; then finalPath= fi hash=$expHash @@ -103,7 +106,7 @@ if test -z "$finalPath"; then # garbage-collected independently. if test -n "$NIX_DOWNLOAD_CACHE"; then 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" cachedHashFN="$NIX_DOWNLOAD_CACHE/$urlHash.$hashType" 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 # file on the server. hash=$(cat $cachedHashFN) - finalPath=$(@bindir@/nix-store --print-fixed-path "$hashType" "$hash" "$name") - if ! @bindir@/nix-store --check-validity "$finalPath" 2> /dev/null; then + finalPath=$($binDir/nix-store --print-fixed-path "$hashType" "$hash" "$name") + if ! $binDir/nix-store --check-validity "$finalPath" 2> /dev/null; then echo "cached contents of \`$url' disappeared, redownloading..." >&2 finalPath= cacheFlags="--remote-time" @@ -133,7 +136,7 @@ if test -z "$finalPath"; then if test -z "$finalPath"; then # 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 "$NIX_DOWNLOAD_CACHE"; then @@ -142,7 +145,7 @@ if test -z "$finalPath"; then fi # 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 echo "hash mismatch for URL \`$url'" >&2 diff --git a/scripts/nix-pull.in b/scripts/nix-pull.in index 51c7e681a5..8fb256179c 100644 --- a/scripts/nix-pull.in +++ b/scripts/nix-pull.in @@ -1,17 +1,17 @@ -#! @perl@ -w -I@libexecdir@/nix @perlFlags@ +#! @perl@ -w @perlFlags@ use strict; use File::Temp qw(tempdir); -use NixManifest; +use Nix::Config; +use Nix::Manifest; my $tmpDir = tempdir("nix-pull.XXXXXX", CLEANUP => 1, TMPDIR => 1) or die "cannot create a temporary directory"; -my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@"; my $libexecDir = ($ENV{"NIX_LIBEXEC_DIR"} or "@libexecdir@"); my $storeDir = ($ENV{"NIX_STORE_DIR"} or "@storedir@"); 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. @@ -42,7 +42,7 @@ sub downloadFile { my $url = shift; $ENV{"PRINT_PATH"} = 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 "nix-prefetch-url did not return a path" unless defined $path; chomp $path; @@ -57,16 +57,16 @@ sub processURL { my $manifest; # 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"; my $bzipped = downloadFile "$url.bz2"; $manifest = "$tmpDir/MANIFEST"; - system("@bunzip2@ < $bzipped > $manifest") == 0 + system("$Nix::Config::bzip2 -d < $bzipped > $manifest") == 0 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"); chomp $manifest; } @@ -96,7 +96,7 @@ sub processURL { $baseName = $1; } - my $hash = `$binDir/nix-hash --flat '$manifest'` + my $hash = `$Nix::Config::binDir/nix-hash --flat '$manifest'` or die "cannot hash `$manifest'"; chomp $hash; diff --git a/scripts/nix-push.in b/scripts/nix-push.in index fd1ec21485..dcdad57212 100644 --- a/scripts/nix-push.in +++ b/scripts/nix-push.in @@ -1,9 +1,10 @@ -#! @perl@ -w -I@libexecdir@/nix @perlFlags@ +#! @perl@ -w @perlFlags@ use strict; use File::Temp qw(tempdir); use File::stat; -use NixManifest; +use Nix::Config; +use Nix::Manifest; my $hashAlgo = "sha256"; @@ -13,7 +14,7 @@ my $tmpDir = tempdir("nix-push.XXXXXX", CLEANUP => 1, TMPDIR => 1) my $nixExpr = "$tmpDir/create-nars.nix"; my $manifest = "$tmpDir/MANIFEST"; -my $curl = "@curl@ --fail --silent"; +my $curl = "$Nix::Config::curl --fail --silent"; my $extraCurlFlags = ${ENV{'CURL_FLAGS'}}; $curl = "$curl $extraCurlFlags" if defined $extraCurlFlags; @@ -107,7 +108,7 @@ foreach my $storePath (@storePaths) { # Construct a Nix expression that creates a Nix archive. my $nixexpr = "((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; } diff --git a/scripts/update-manifest.pl b/scripts/update-manifest.pl deleted file mode 100755 index 566f646732..0000000000 --- a/scripts/update-manifest.pl +++ /dev/null @@ -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 = ; - 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; diff --git a/substitute.mk b/substitute.mk index 7da60d0677..ede3470073 100644 --- a/substitute.mk +++ b/substitute.mk @@ -6,13 +6,13 @@ -e "s^@sysconfdir\@^$(sysconfdir)^g" \ -e "s^@localstatedir\@^$(localstatedir)^g" \ -e "s^@datadir\@^$(datadir)^g" \ + -e "s^@libdir\@^$(libdir)^g" \ -e "s^@libexecdir\@^$(libexecdir)^g" \ -e "s^@storedir\@^$(storedir)^g" \ -e "s^@system\@^$(system)^g" \ -e "s^@shell\@^$(bash)^g" \ -e "s^@curl\@^$(curl)^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^@perl\@^$(perl)^g" \ -e "s^@perlFlags\@^$(perlFlags)^g" \ diff --git a/tests/binary-patching.sh b/tests/binary-patching.sh index 60e57b4b00..9866f4f6f2 100644 --- a/tests/binary-patching.sh +++ b/tests/binary-patching.sh @@ -7,22 +7,22 @@ mkdir -p $TEST_ROOT/cache2 $TEST_ROOT/patches RESULT=$TEST_ROOT/result # 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) 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) -$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 # 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 -$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 grep -q "patch {" $TEST_ROOT/manifest3 @@ -45,7 +45,7 @@ rm $RESULT [ "$(grep ' patch ' $TEST_ROOT/var/log/nix/downloads | wc -l)" -eq 2 ] # 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 # Rebuild version 3. This should use the direct patch rather than the diff --git a/tests/common.sh.in b/tests/common.sh.in index b03cd49ec7..4a2c96daf7 100644 --- a/tests/common.sh.in +++ b/tests/common.sh.in @@ -1,5 +1,7 @@ set -e +export TOP=$(pwd)/.. + export TEST_ROOT=$(pwd)/test-tmp export NIX_STORE_DIR 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_BIN_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 SHARED=$TEST_ROOT/shared +export PATH=$NIX_BIN_DIR:$TOP/scripts:$PATH + export NIX_REMOTE= export REAL_BIN_DIR=@bindir@ @@ -27,10 +32,10 @@ export REAL_DATA_DIR=@datadir@ export REAL_STORE_DIR=@storedir@ export NIX_BUILD_HOOK= export PERL=perl -export TOP=$(pwd)/.. -export bzip2_bin_test="@bzip2_bin_test@" -if test "${bzip2_bin_test:0:1}" != "/"; then - bzip2_bin_test=`pwd`/${bzip2_bin_test} +export PERL5LIB=$TOP/perl/lib +export NIX_BZIP2="@bzip2_bin_test@/bzip2" +if test "${NIX_BZIP2:0:1}" != "/"; then + NIX_BZIP2=`pwd`/${NIX_BZIP2} fi export dot=@dot@ export xmllint="@xmllint@" diff --git a/tests/init.sh b/tests/init.sh index 104da432ea..0e17740f36 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -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-build $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-generate-patches $NIX_BIN_DIR/ mkdir $NIX_BIN_DIR/nix -ln -s $bzip2_bin_test/bzip2 $NIX_BIN_DIR/nix/ -ln -s $bzip2_bin_test/bunzip2 $NIX_BIN_DIR/nix/ +ln -s $NIX_BZIP2 $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/GeneratePatches.pm $NIX_BIN_DIR/nix/ -ln -s $TOP/scripts/NixManifest.pm $NIX_BIN_DIR/nix/ cat > "$NIX_CONF_DIR"/nix.conf < $i.tmp \ -e "s^$REAL_BIN_DIR/nix-store^$NIX_BIN_DIR/nix-store^" \ diff --git a/tests/nix-pull.sh b/tests/nix-pull.sh index d2309742d2..9fc3992f62 100644 --- a/tests/nix-pull.sh +++ b/tests/nix-pull.sh @@ -2,7 +2,7 @@ source common.sh pullCache () { echo "pulling cache..." - $NIX_BIN_DIR/nix-pull file://$TEST_ROOT/manifest + nix-pull file://$TEST_ROOT/manifest } clearStore diff --git a/tests/nix-push.sh b/tests/nix-push.sh index 0a35e3b97a..0cef0c22a2 100644 --- a/tests/nix-push.sh +++ b/tests/nix-push.sh @@ -7,5 +7,4 @@ echo "pushing $drvPath" mkdir -p $TEST_ROOT/cache -$NIX_BIN_DIR/nix-push \ - --copy $TEST_ROOT/cache $TEST_ROOT/manifest $drvPath +nix-push --copy $TEST_ROOT/cache $TEST_ROOT/manifest $drvPath From cd6d02c366af43bccdd2ef345193e4fdeca78a13 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Oct 2011 21:30:59 +0000 Subject: [PATCH 06/23] --- scripts/Makefile.am | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 752fcd5740..42ed0158e9 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -27,9 +27,7 @@ EXTRA_DIST = nix-collect-garbage.in \ nix-pull.in nix-push.in nix-profile.sh.in \ nix-prefetch-url.in nix-install-package.in \ nix-channel.in \ - NixConfig.pm.in \ SSH.pm \ - GeneratePatches.pm.in \ nix-build.in \ download-using-manifests.pl.in \ copy-from-other-stores.pl.in \ From 8af7d766f0244d5b15d89ab2d2d66b0d63e8f576 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Oct 2011 21:32:34 +0000 Subject: [PATCH 07/23] * Refactoring: remove unnecessary variables from the tests. --- tests/add.sh | 12 ++--- tests/binary-patching.sh | 20 ++++---- tests/build-hook.sh | 2 +- tests/check-refs.sh | 28 +++++------ tests/common.sh.in | 11 +---- tests/dependencies.sh | 20 ++++---- tests/export-graph.sh | 10 ++-- tests/export.sh | 14 +++--- tests/fallback.sh | 8 ++-- tests/filter-source.sh | 2 +- tests/fixed.sh | 20 ++++---- tests/gc-concurrent.sh | 20 ++++---- tests/gc-runtime.sh | 10 ++-- tests/gc.sh | 22 ++++----- tests/hash.sh | 12 ++--- tests/init.sh | 30 +++++------- tests/install-package.sh | 12 ++--- tests/lang.sh | 10 ++-- tests/logging.sh | 2 +- tests/misc.sh | 14 +++--- tests/negative-caching.sh | 6 +-- tests/nix-build.sh | 6 +-- tests/nix-pull.sh | 12 ++--- tests/nix-push.sh | 4 +- tests/parallel.sh | 6 +-- tests/referrers.sh | 6 +-- tests/secure-drv-outputs.sh | 12 ++--- tests/simple.sh | 10 ++-- tests/substitutes.sh | 8 ++-- tests/substitutes2.sh | 6 +-- tests/timeout.sh | 6 +-- tests/user-envs.sh | 92 ++++++++++++++++++------------------- tests/verify.sh | 2 +- 33 files changed, 220 insertions(+), 235 deletions(-) diff --git a/tests/add.sh b/tests/add.sh index 7ea4cb6d6a..e26e05843d 100644 --- a/tests/add.sh +++ b/tests/add.sh @@ -1,9 +1,9 @@ source common.sh -path1=$($nixstore --add ./dummy) +path1=$(nix-store --add ./dummy) echo $path1 -path2=$($nixstore --add-fixed sha256 --recursive ./dummy) +path2=$(nix-store --add-fixed sha256 --recursive ./dummy) echo $path2 if test "$path1" != "$path2"; then @@ -11,18 +11,18 @@ if test "$path1" != "$path2"; then exit 1 fi -path3=$($nixstore --add-fixed sha256 ./dummy) +path3=$(nix-store --add-fixed sha256 ./dummy) echo $path3 test "$path1" != "$path3" || exit 1 -path4=$($nixstore --add-fixed sha1 --recursive ./dummy) +path4=$(nix-store --add-fixed sha1 --recursive ./dummy) echo $path4 test "$path1" != "$path4" || exit 1 -hash1=$($nixstore -q --hash $path1) +hash1=$(nix-store -q --hash $path1) echo $hash1 -hash2=$($nixhash --type sha256 --base32 ./dummy) +hash2=$(nix-hash --type sha256 --base32 ./dummy) echo $hash2 test "$hash1" = "sha256:$hash2" diff --git a/tests/binary-patching.sh b/tests/binary-patching.sh index 9866f4f6f2..8c52c2f142 100644 --- a/tests/binary-patching.sh +++ b/tests/binary-patching.sh @@ -8,12 +8,12 @@ RESULT=$TEST_ROOT/result # Build version 1 and 2 of the "foo" package. nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest1 \ - $($nixbuild -o $RESULT binary-patching.nix --arg version 1) + $(nix-build -o $RESULT binary-patching.nix --arg version 1) -out2=$($nixbuild -o $RESULT binary-patching.nix --arg version 2) +out2=$(nix-build -o $RESULT binary-patching.nix --arg version 2) nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest2 $out2 -out3=$($nixbuild -o $RESULT binary-patching.nix --arg version 3) +out3=$(nix-build -o $RESULT binary-patching.nix --arg version 3) nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest3 $out3 rm $RESULT @@ -28,19 +28,19 @@ nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \ grep -q "patch {" $TEST_ROOT/manifest3 # Get rid of versions 2 and 3. -$nixstore --delete $out2 $out3 +nix-store --delete $out2 $out3 # Pull the manifest containing the patches. clearManifests -$NIX_BIN_DIR/nix-pull file://$TEST_ROOT/manifest3 +nix-pull file://$TEST_ROOT/manifest3 # Make sure that the download size prediction uses the patches rather # than the full download. -$nixbuild -o $RESULT binary-patching.nix --arg version 3 --dry-run 2>&1 | grep -q "0.01 MiB" +nix-build -o $RESULT binary-patching.nix --arg version 3 --dry-run 2>&1 | grep -q "0.01 MiB" # Now rebuild it. This should use the two patches generated above. rm -f $TEST_ROOT/var/log/nix/downloads -$nixbuild -o $RESULT binary-patching.nix --arg version 3 +nix-build -o $RESULT binary-patching.nix --arg version 3 rm $RESULT [ "$(grep ' patch ' $TEST_ROOT/var/log/nix/downloads | wc -l)" -eq 2 ] @@ -50,9 +50,9 @@ nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \ # Rebuild version 3. This should use the direct patch rather than the # sequence of two patches. -$nixstore --delete $out2 $out3 +nix-store --delete $out2 $out3 clearManifests rm $TEST_ROOT/var/log/nix/downloads -$NIX_BIN_DIR/nix-pull file://$TEST_ROOT/manifest3 -$nixbuild -o $RESULT binary-patching.nix --arg version 3 +nix-pull file://$TEST_ROOT/manifest3 +nix-build -o $RESULT binary-patching.nix --arg version 3 [ "$(grep ' patch ' $TEST_ROOT/var/log/nix/downloads | wc -l)" -eq 1 ] diff --git a/tests/build-hook.sh b/tests/build-hook.sh index b9de009936..c733b26804 100644 --- a/tests/build-hook.sh +++ b/tests/build-hook.sh @@ -2,7 +2,7 @@ source common.sh export NIX_BUILD_HOOK="build-hook.hook.sh" -outPath=$($nixbuild build-hook.nix) +outPath=$(nix-build build-hook.nix) echo "output path is $outPath" diff --git a/tests/check-refs.sh b/tests/check-refs.sh index 0e80b1541f..08fe01ec18 100644 --- a/tests/check-refs.sh +++ b/tests/check-refs.sh @@ -4,33 +4,33 @@ set -x RESULT=$TEST_ROOT/result -dep=$($nixbuild -o $RESULT check-refs.nix -A dep) +dep=$(nix-build -o $RESULT check-refs.nix -A dep) # test1 references dep, not itself. -test1=$($nixbuild -o $RESULT check-refs.nix -A test1) -! $nixstore -q --references $test1 | grep -q $test1 -$nixstore -q --references $test1 | grep -q $dep +test1=$(nix-build -o $RESULT check-refs.nix -A test1) +! nix-store -q --references $test1 | grep -q $test1 +nix-store -q --references $test1 | grep -q $dep # test2 references src, not itself nor dep. -test2=$($nixbuild -o $RESULT check-refs.nix -A test2) -! $nixstore -q --references $test2 | grep -q $test2 -! $nixstore -q --references $test2 | grep -q $dep -$nixstore -q --references $test2 | grep -q aux-ref +test2=$(nix-build -o $RESULT check-refs.nix -A test2) +! nix-store -q --references $test2 | grep -q $test2 +! nix-store -q --references $test2 | grep -q $dep +nix-store -q --references $test2 | grep -q aux-ref # test3 should fail (unallowed ref). -! $nixbuild -o $RESULT check-refs.nix -A test3 +! nix-build -o $RESULT check-refs.nix -A test3 # test4 should succeed. -$nixbuild -o $RESULT check-refs.nix -A test4 +nix-build -o $RESULT check-refs.nix -A test4 # test5 should succeed. -$nixbuild -o $RESULT check-refs.nix -A test5 +nix-build -o $RESULT check-refs.nix -A test5 # test6 should fail (unallowed self-ref). -! $nixbuild -o $RESULT check-refs.nix -A test6 +! nix-build -o $RESULT check-refs.nix -A test6 # test7 should succeed (allowed self-ref). -$nixbuild -o $RESULT check-refs.nix -A test7 +nix-build -o $RESULT check-refs.nix -A test7 # test8 should fail (toFile depending on derivation output). -! $nixbuild -o $RESULT check-refs.nix -A test8 +! nix-build -o $RESULT check-refs.nix -A test8 diff --git a/tests/common.sh.in b/tests/common.sh.in index 4a2c96daf7..567f5b4606 100644 --- a/tests/common.sh.in +++ b/tests/common.sh.in @@ -47,13 +47,6 @@ export SHELL="@shell@" export version=@version@ export system=@system@ -export nixinstantiate=$TOP/src/nix-instantiate/nix-instantiate -export nixstore=$TOP/src/nix-store/nix-store -export nixenv=$TOP/src/nix-env/nix-env -export nixhash=$TOP/src/nix-hash/nix-hash -export nixworker=$TOP/src/nix-worker/nix-worker -export nixbuild=$NIX_BIN_DIR/nix-build - readLink() { ls -l "$1" | sed 's/.*->\ //' } @@ -70,7 +63,7 @@ clearStore() { mkdir "$NIX_STORE_DIR" rm -rf "$NIX_DB_DIR" mkdir "$NIX_DB_DIR" - $nixstore --init + nix-store --init clearProfiles rm -f "$NIX_STATE_DIR"/gcroots/auto/* rm -f "$NIX_STATE_DIR"/gcroots/ref @@ -81,7 +74,7 @@ clearManifests() { } startDaemon() { - $nixworker --daemon & + nix-worker --daemon & pidDaemon=$! trap "kill -9 $pidDaemon" EXIT export NIX_REMOTE=daemon diff --git a/tests/dependencies.sh b/tests/dependencies.sh index 46f60c9bd3..df204d185d 100644 --- a/tests/dependencies.sh +++ b/tests/dependencies.sh @@ -2,36 +2,36 @@ source common.sh clearStore -drvPath=$($nixinstantiate dependencies.nix) +drvPath=$(nix-instantiate dependencies.nix) echo "derivation is $drvPath" -$nixstore -q --tree "$drvPath" | grep ' +---.*builder1.sh' +nix-store -q --tree "$drvPath" | grep ' +---.*builder1.sh' # Test Graphviz graph generation. -$nixstore -q --graph "$drvPath" > $TEST_ROOT/graph +nix-store -q --graph "$drvPath" > $TEST_ROOT/graph if test -n "$dot"; then # Does it parse? $dot < $TEST_ROOT/graph fi -outPath=$($nixstore -rvv "$drvPath") || fail "build failed" +outPath=$(nix-store -rvv "$drvPath") || fail "build failed" # Test Graphviz graph generation. -$nixstore -q --graph "$outPath" > $TEST_ROOT/graph +nix-store -q --graph "$outPath" > $TEST_ROOT/graph if test -n "$dot"; then # Does it parse? $dot < $TEST_ROOT/graph fi -$nixstore -q --tree "$outPath" | grep '+---.*dependencies-input-2' +nix-store -q --tree "$outPath" | grep '+---.*dependencies-input-2' echo "output path is $outPath" text=$(cat "$outPath"/foobar) if test "$text" != "FOOBAR"; then exit 1; fi -deps=$($nixstore -quR "$drvPath") +deps=$(nix-store -quR "$drvPath") echo "output closure contains $deps" @@ -45,8 +45,8 @@ if echo "$deps" | grep -q "dependencies-input-1"; then exit 1; fi input2OutPath=$(echo "$deps" | grep "dependencies-input-2") # The referrers closure of input-2 should include outPath. -$nixstore -q --referrers-closure "$input2OutPath" | grep "$outPath" +nix-store -q --referrers-closure "$input2OutPath" | grep "$outPath" # Check that the derivers are set properly. -test $($nixstore -q --deriver "$outPath") = "$drvPath" -$nixstore -q --deriver "$input2OutPath" | grep -q -- "-input-2.drv" +test $(nix-store -q --deriver "$outPath") = "$drvPath" +nix-store -q --deriver "$input2OutPath" | grep -q -- "-input-2.drv" diff --git a/tests/export-graph.sh b/tests/export-graph.sh index 607849a7c8..7adbefd120 100644 --- a/tests/export-graph.sh +++ b/tests/export-graph.sh @@ -4,23 +4,23 @@ clearStore clearProfiles checkRef() { - $nixstore -q --references ./result | grep -q "$1" || fail "missing reference $1" + nix-store -q --references ./result | grep -q "$1" || fail "missing reference $1" } # Test the export of the runtime dependency graph. -outPath=$($nixbuild ./export-graph.nix -A runtimeGraph) +outPath=$(nix-build ./export-graph.nix -A runtimeGraph) -test $($nixstore -q --references ./result | wc -l) = 2 || fail "bad nr of references" +test $(nix-store -q --references ./result | wc -l) = 2 || fail "bad nr of references" checkRef input-2 for i in $(cat $outPath); do checkRef $i; done # Test the export of the build-time dependency graph. -$nixstore --gc # should force rebuild of input-1 +nix-store --gc # should force rebuild of input-1 -outPath=$($nixbuild ./export-graph.nix -A buildGraph) +outPath=$(nix-build ./export-graph.nix -A buildGraph) checkRef input-1 checkRef input-1.drv diff --git a/tests/export.sh b/tests/export.sh index c7d0a81767..1368197420 100644 --- a/tests/export.sh +++ b/tests/export.sh @@ -2,16 +2,16 @@ source common.sh clearStore -outPath=$($nixbuild dependencies.nix) +outPath=$(nix-build dependencies.nix) -$nixstore --export $outPath > $TEST_ROOT/exp +nix-store --export $outPath > $TEST_ROOT/exp -$nixstore --export $($nixstore -qR $outPath) > $TEST_ROOT/exp_all +nix-store --export $(nix-store -qR $outPath) > $TEST_ROOT/exp_all clearStore -if $nixstore --import < $TEST_ROOT/exp; then +if nix-store --import < $TEST_ROOT/exp; then echo "importing a non-closure should fail" exit 1 fi @@ -19,13 +19,13 @@ fi clearStore -$nixstore --import < $TEST_ROOT/exp_all +nix-store --import < $TEST_ROOT/exp_all -$nixstore --export $($nixstore -qR $outPath) > $TEST_ROOT/exp_all2 +nix-store --export $(nix-store -qR $outPath) > $TEST_ROOT/exp_all2 clearStore # Regression test: the derivers in exp_all2 are empty, which shouldn't # cause a failure. -$nixstore --import < $TEST_ROOT/exp_all2 +nix-store --import < $TEST_ROOT/exp_all2 diff --git a/tests/fallback.sh b/tests/fallback.sh index 24889a4528..f3a6b50515 100644 --- a/tests/fallback.sh +++ b/tests/fallback.sh @@ -2,19 +2,19 @@ source common.sh clearStore -drvPath=$($nixinstantiate simple.nix) +drvPath=$(nix-instantiate simple.nix) echo "derivation is $drvPath" -outPath=$($nixstore -q --fallback "$drvPath") +outPath=$(nix-store -q --fallback "$drvPath") echo "output path is $outPath" # Build with a substitute that fails. This should fail. export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh -if $nixstore -r "$drvPath"; then echo unexpected fallback; exit 1; fi +if nix-store -r "$drvPath"; then echo unexpected fallback; exit 1; fi # Build with a substitute that fails. This should fall back to a source build. export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh -$nixstore -r --fallback "$drvPath" +nix-store -r --fallback "$drvPath" text=$(cat "$outPath"/hello) if test "$text" != "Hello World!"; then exit 1; fi diff --git a/tests/filter-source.sh b/tests/filter-source.sh index 73f3530245..f7a096ed60 100644 --- a/tests/filter-source.sh +++ b/tests/filter-source.sh @@ -10,7 +10,7 @@ touch $TEST_ROOT/filterin/bak touch $TEST_ROOT/filterin/bla.c.bak ln -s xyzzy $TEST_ROOT/filterin/link -$NIX_BIN_DIR/nix-build ./filter-source.nix -o $TEST_ROOT/filterout +nix-build ./filter-source.nix -o $TEST_ROOT/filterout set -x test ! -e $TEST_ROOT/filterout/foo/bar diff --git a/tests/fixed.sh b/tests/fixed.sh index 91c1220830..164791564b 100644 --- a/tests/fixed.sh +++ b/tests/fixed.sh @@ -6,31 +6,31 @@ export IMPURE_VAR1=foo export IMPURE_VAR2=bar echo 'testing good...' -$nixbuild fixed.nix -A good +nix-build fixed.nix -A good echo 'testing good2...' -$nixbuild fixed.nix -A good2 +nix-build fixed.nix -A good2 echo 'testing bad...' -$nixbuild fixed.nix -A bad && fail "should fail" +nix-build fixed.nix -A bad && fail "should fail" echo 'testing reallyBad...' -$nixinstantiate fixed.nix -A reallyBad && fail "should fail" +nix-instantiate fixed.nix -A reallyBad && fail "should fail" # While we're at it, check attribute selection a bit more. echo 'testing attribute selection...' -test $($nixinstantiate fixed.nix -A good.1 | wc -l) = 1 +test $(nix-instantiate fixed.nix -A good.1 | wc -l) = 1 # Test parallel builds of derivations that produce the same output. # Only one should run at the same time. echo 'testing parallelSame...' clearStore -$nixbuild fixed.nix -A parallelSame -j2 +nix-build fixed.nix -A parallelSame -j2 # Fixed-output derivations with a recursive SHA-256 hash should # produce the same path as "nix-store --add". echo 'testing sameAsAdd...' -out=$($nixbuild fixed.nix -A sameAsAdd) +out=$(nix-build fixed.nix -A sameAsAdd) # This is what fixed.builder2 produces... rm -rf $TEST_ROOT/fixed @@ -39,14 +39,14 @@ mkdir $TEST_ROOT/fixed/bla echo "Hello World!" > $TEST_ROOT/fixed/foo ln -s foo $TEST_ROOT/fixed/bar -out2=$($nixstore --add $TEST_ROOT/fixed) +out2=$(nix-store --add $TEST_ROOT/fixed) echo $out2 test "$out" = "$out2" || exit 1 -out3=$($nixstore --add-fixed --recursive sha256 $TEST_ROOT/fixed) +out3=$(nix-store --add-fixed --recursive sha256 $TEST_ROOT/fixed) echo $out3 test "$out" = "$out3" || exit 1 -out4=$($nixstore --print-fixed-path --recursive sha256 "1ixr6yd3297ciyp9im522dfxpqbkhcw0pylkb2aab915278fqaik" fixed) +out4=$(nix-store --print-fixed-path --recursive sha256 "1ixr6yd3297ciyp9im522dfxpqbkhcw0pylkb2aab915278fqaik" fixed) echo $out4 test "$out" = "$out4" || exit 1 diff --git a/tests/gc-concurrent.sh b/tests/gc-concurrent.sh index 74251d7cbc..0bc5a12d31 100644 --- a/tests/gc-concurrent.sh +++ b/tests/gc-concurrent.sh @@ -2,14 +2,14 @@ source common.sh clearStore -drvPath1=$($nixinstantiate gc-concurrent.nix -A test1) -outPath1=$($nixstore -q $drvPath1) +drvPath1=$(nix-instantiate gc-concurrent.nix -A test1) +outPath1=$(nix-store -q $drvPath1) -drvPath2=$($nixinstantiate gc-concurrent.nix -A test2) -outPath2=$($nixstore -q $drvPath2) +drvPath2=$(nix-instantiate gc-concurrent.nix -A test2) +outPath2=$(nix-store -q $drvPath2) -drvPath3=$($nixinstantiate simple.nix) -outPath3=$($nixstore -r $drvPath3) +drvPath3=$(nix-instantiate simple.nix) +outPath3=$(nix-store -r $drvPath3) ! test -e $outPath3.lock touch $outPath3.lock @@ -19,16 +19,16 @@ ln -s $drvPath2 "$NIX_STATE_DIR"/gcroots/foo ln -s $outPath3 "$NIX_STATE_DIR"/gcroots/foo2 # Start build #1 in the background. It starts immediately. -$nixstore -rvv "$drvPath1" & +nix-store -rvv "$drvPath1" & pid1=$! # Start build #2 in the background after 10 seconds. -(sleep 10 && $nixstore -rvv "$drvPath2") & +(sleep 10 && nix-store -rvv "$drvPath2") & pid2=$! # Run the garbage collector while the build is running. sleep 6 -$NIX_BIN_DIR/nix-collect-garbage +nix-collect-garbage # Wait for build #1/#2 to finish. echo waiting for pid $pid1 to finish... @@ -53,6 +53,6 @@ rm -f "$NIX_STATE_DIR"/gcroots/foo* ! test -e $outPath3.lock # If we run the collector now, it should delete outPath1/2. -$NIX_BIN_DIR/nix-collect-garbage +nix-collect-garbage ! test -e $outPath1 ! test -e $outPath2 diff --git a/tests/gc-runtime.sh b/tests/gc-runtime.sh index 7a50f9f41b..df662bd0ea 100644 --- a/tests/gc-runtime.sh +++ b/tests/gc-runtime.sh @@ -12,9 +12,9 @@ set -m # enable job control, needed for kill profiles="$NIX_STATE_DIR"/profiles rm -f $profiles/* -$nixenv -p $profiles/test -f ./gc-runtime.nix -i gc-runtime +nix-env -p $profiles/test -f ./gc-runtime.nix -i gc-runtime -outPath=$($nixenv -p $profiles/test -q --no-name --out-path gc-runtime) +outPath=$(nix-env -p $profiles/test -q --no-name --out-path gc-runtime) echo $outPath echo "backgrounding program..." @@ -23,12 +23,12 @@ sleep 2 # hack - wait for the program to get started child=$! echo PID=$child -$nixenv -p $profiles/test -e gc-runtime -$nixenv -p $profiles/test --delete-generations old +nix-env -p $profiles/test -e gc-runtime +nix-env -p $profiles/test --delete-generations old cp $TOP/scripts/find-runtime-roots.pl $TEST_ROOT/foo.pl chmod +x $TEST_ROOT/foo.pl -NIX_ROOT_FINDER=$TEST_ROOT/foo.pl $nixstore --gc +NIX_ROOT_FINDER=$TEST_ROOT/foo.pl nix-store --gc kill -- -$child diff --git a/tests/gc.sh b/tests/gc.sh index e1b3a08204..a375a35c2e 100644 --- a/tests/gc.sh +++ b/tests/gc.sh @@ -1,27 +1,27 @@ source common.sh -drvPath=$($nixinstantiate dependencies.nix) -outPath=$($nixstore -rvv "$drvPath") +drvPath=$(nix-instantiate dependencies.nix) +outPath=$(nix-store -rvv "$drvPath") # Set a GC root. rm -f "$NIX_STATE_DIR"/gcroots/foo ln -sf $outPath "$NIX_STATE_DIR"/gcroots/foo -$nixstore --gc --print-roots | grep $outPath -$nixstore --gc --print-live | grep $outPath -$nixstore --gc --print-dead | grep $drvPath -if $nixstore --gc --print-dead | grep $outPath; then false; fi +nix-store --gc --print-roots | grep $outPath +nix-store --gc --print-live | grep $outPath +nix-store --gc --print-dead | grep $drvPath +if nix-store --gc --print-dead | grep $outPath; then false; fi -$nixstore --gc --print-dead +nix-store --gc --print-dead inUse=$(readLink $outPath/input-2) -if $nixstore --delete $inUse; then false; fi +if nix-store --delete $inUse; then false; fi test -e $inUse -if $nixstore --delete $outPath; then false; fi +if nix-store --delete $outPath; then false; fi test -e $outPath -$NIX_BIN_DIR/nix-collect-garbage +nix-collect-garbage # Check that the root and its dependencies haven't been deleted. cat $outPath/foobar @@ -32,7 +32,7 @@ if test -e $drvPath; then false; fi rm "$NIX_STATE_DIR"/gcroots/foo -$NIX_BIN_DIR/nix-collect-garbage +nix-collect-garbage # Check that the output has been GC'd. if test -e $outPath/foobar; then false; fi diff --git a/tests/hash.sh b/tests/hash.sh index 5022ea2469..de18028eaa 100644 --- a/tests/hash.sh +++ b/tests/hash.sh @@ -2,7 +2,7 @@ source common.sh try () { printf "%s" "$2" > $TEST_ROOT/vector - hash=$($nixhash $EXTRA --flat --type "$1" $TEST_ROOT/vector) + hash=$(nix-hash $EXTRA --flat --type "$1" $TEST_ROOT/vector) if test "$hash" != "$3"; then echo "hash $1, expected $3, got $hash" exit 1 @@ -28,7 +28,7 @@ try sha256 "abc" "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s" EXTRA= try2 () { - hash=$($nixhash --type "$1" $TEST_ROOT/hash-path) + hash=$(nix-hash --type "$1" $TEST_ROOT/hash-path) if test "$hash" != "$2"; then echo "hash $1, expected $2, got $hash" exit 1 @@ -56,7 +56,7 @@ ln -s x $TEST_ROOT/hash-path/hello try2 md5 "f78b733a68f5edbdf9413899339eaa4a" # Conversion. -test $($nixhash --type sha256 --to-base32 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") = "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s" -test $($nixhash --type sha256 --to-base16 "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s") = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" -test $($nixhash --type sha1 --to-base32 "800d59cfcd3c05e900cb4e214be48f6b886a08df") = "vw46m23bizj4n8afrc0fj19wrp7mj3c0" -test $($nixhash --type sha1 --to-base16 "vw46m23bizj4n8afrc0fj19wrp7mj3c0") = "800d59cfcd3c05e900cb4e214be48f6b886a08df" +test $(nix-hash --type sha256 --to-base32 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") = "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s" +test $(nix-hash --type sha256 --to-base16 "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s") = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" +test $(nix-hash --type sha1 --to-base32 "800d59cfcd3c05e900cb4e214be48f6b886a08df") = "vw46m23bizj4n8afrc0fj19wrp7mj3c0" +test $(nix-hash --type sha1 --to-base16 "vw46m23bizj4n8afrc0fj19wrp7mj3c0") = "800d59cfcd3c05e900cb4e214be48f6b886a08df" diff --git a/tests/init.sh b/tests/init.sh index 0e17740f36..63e939dff1 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -18,22 +18,19 @@ mkdir "$NIX_DB_DIR" mkdir "$NIX_CONF_DIR" mkdir $NIX_BIN_DIR -ln -s $nixstore $NIX_BIN_DIR/ -ln -s $nixinstantiate $NIX_BIN_DIR/ -ln -s $nixhash $NIX_BIN_DIR/ -ln -s $nixenv $NIX_BIN_DIR/ -ln -s $nixworker $NIX_BIN_DIR/ +ln -s $TOP/src/nix-store/nix-store $NIX_BIN_DIR/ +ln -s $TOP/src/nix-instantiate/nix-instantiate $NIX_BIN_DIR/ +ln -s $TOP/src/nix-hash/nix-hash $NIX_BIN_DIR/ +ln -s $TOP/src/nix-env/nix-env $NIX_BIN_DIR/ +ln -s $TOP/src/nix-worker/nix-worker $NIX_BIN_DIR/ ln -s $TOP/src/bsdiff-*/bsdiff $NIX_BIN_DIR/ ln -s $TOP/src/bsdiff-*/bspatch $NIX_BIN_DIR/ 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-build $NIX_BIN_DIR/ -ln -s $TOP/scripts/nix-install-package $NIX_BIN_DIR/ ln -s $TOP/scripts/nix-pull $NIX_BIN_DIR/ -mkdir $NIX_BIN_DIR/nix +mkdir -p $NIX_BIN_DIR/nix/substituters ln -s $NIX_BZIP2 $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/copy-from-other-stores.pl $NIX_BIN_DIR/nix/substituters cat > "$NIX_CONF_DIR"/nix.conf < $NIX_BIN_DIR/nix/download-using-manifests.pl < $NIX_BIN_DIR/nix/substituters/download-using-manifests.pl < $TEST_ROOT/foo.nixpkg < lang/$i.out; then + if ! nix-instantiate --parse-only - < lang/$i.nix > lang/$i.out; then echo "FAIL: $i should parse" fail=1 fi @@ -25,7 +25,7 @@ done for i in lang/eval-fail-*.nix; do echo "evaluating $i (should fail)"; i=$(basename $i .nix) - if $nixinstantiate --eval-only lang/$i.nix; then + if nix-instantiate --eval-only lang/$i.nix; then echo "FAIL: $i shouldn't evaluate" fail=1 fi @@ -40,7 +40,7 @@ for i in lang/eval-okay-*.nix; do if test -e lang/$i.flags; then flags=$(cat lang/$i.flags) fi - if ! NIX_PATH=lang/dir3:lang/dir4 $nixinstantiate $flags --eval-only --strict lang/$i.nix > lang/$i.out; then + if ! NIX_PATH=lang/dir3:lang/dir4 nix-instantiate $flags --eval-only --strict lang/$i.nix > lang/$i.out; then echo "FAIL: $i should evaluate" fail=1 elif ! diff lang/$i.out lang/$i.exp; then @@ -50,7 +50,7 @@ for i in lang/eval-okay-*.nix; do fi if test -e lang/$i.exp.xml; then - if ! $nixinstantiate --eval-only --xml --no-location --strict \ + if ! nix-instantiate --eval-only --xml --no-location --strict \ lang/$i.nix > lang/$i.out.xml; then echo "FAIL: $i should evaluate" fail=1 diff --git a/tests/logging.sh b/tests/logging.sh index dffedcfe59..8cedb47065 100644 --- a/tests/logging.sh +++ b/tests/logging.sh @@ -4,7 +4,7 @@ clearStore # Produce an escaped log file. set -x -$nixbuild --log-type escapes -vv dependencies.nix 2> $TEST_ROOT/log.esc +nix-build --log-type escapes -vv dependencies.nix 2> $TEST_ROOT/log.esc # Convert it to an XML representation. $TOP/src/nix-log2xml/nix-log2xml < $TEST_ROOT/log.esc > $TEST_ROOT/log.xml diff --git a/tests/misc.sh b/tests/misc.sh index 9be2ac2f04..5d88aae63e 100644 --- a/tests/misc.sh +++ b/tests/misc.sh @@ -3,14 +3,14 @@ source common.sh # Tests miscellaneous commands. # Do all commands have help? -$nixenv --help | grep -q install -$nixstore --help | grep -q realise -$nixinstantiate --help | grep -q eval-only -$nixhash --help | grep -q base32 +nix-env --help | grep -q install +nix-store --help | grep -q realise +nix-instantiate --help | grep -q eval-only +nix-hash --help | grep -q base32 # Can we ask for the version number? -$nixenv --version | grep "$version" +nix-env --version | grep "$version" # Usage errors. -$nixenv --foo 2>&1 | grep "no operation" -$nixenv -q --foo 2>&1 | grep "unknown flag" +nix-env --foo 2>&1 | grep "no operation" +nix-env -q --foo 2>&1 | grep "unknown flag" diff --git a/tests/negative-caching.sh b/tests/negative-caching.sh index e618e9443e..7cbab00e4f 100644 --- a/tests/negative-caching.sh +++ b/tests/negative-caching.sh @@ -7,16 +7,16 @@ set +e opts="--option build-cache-failure true --print-build-trace" # This build should fail, and the failure should be cached. -log=$($nixbuild $opts negative-caching.nix -A fail 2>&1) && fail "should fail" +log=$(nix-build $opts negative-caching.nix -A fail 2>&1) && fail "should fail" echo "$log" | grep -q "@ build-failed" || fail "no build-failed trace" # Do it again. The build shouldn't be tried again. -log=$($nixbuild $opts negative-caching.nix -A fail 2>&1) && fail "should fail" +log=$(nix-build $opts negative-caching.nix -A fail 2>&1) && fail "should fail" echo "$log" | grep -q "FAIL" && fail "failed build not cached" echo "$log" | grep -q "@ build-failed .* cached" || fail "trace doesn't say cached" # Check that --keep-going works properly with cached failures. -log=$($nixbuild $opts --keep-going negative-caching.nix -A depOnFail 2>&1) && fail "should fail" +log=$(nix-build $opts --keep-going negative-caching.nix -A depOnFail 2>&1) && fail "should fail" echo "$log" | grep -q "FAIL" && fail "failed build not cached (2)" echo "$log" | grep -q "@ build-failed .* cached" || fail "trace doesn't say cached (2)" echo "$log" | grep -q "@ build-succeeded .*-succeed" || fail "didn't keep going" diff --git a/tests/nix-build.sh b/tests/nix-build.sh index aab3615cc5..d575e9aae9 100644 --- a/tests/nix-build.sh +++ b/tests/nix-build.sh @@ -2,7 +2,7 @@ source common.sh clearStore -(cd $TEST_ROOT && $nixbuild ../dependencies.nix) +(cd $TEST_ROOT && nix-build ../dependencies.nix) test "$(cat $TEST_ROOT/result/foobar)" = FOOBAR # The result should be retained by a GC. @@ -10,10 +10,10 @@ echo A target=$(readLink $TEST_ROOT/result) echo B echo target is $target -$nixstore --gc +nix-store --gc test -e $target/foobar # But now it should be gone. rm $TEST_ROOT/result -$nixstore --gc +nix-store --gc if test -e $target/foobar; then false; fi diff --git a/tests/nix-pull.sh b/tests/nix-pull.sh index 9fc3992f62..9a89676cb9 100644 --- a/tests/nix-pull.sh +++ b/tests/nix-pull.sh @@ -9,11 +9,11 @@ clearStore clearManifests pullCache -drvPath=$($nixinstantiate dependencies.nix) -outPath=$($nixstore -q $drvPath) +drvPath=$(nix-instantiate dependencies.nix) +outPath=$(nix-store -q $drvPath) echo "building $outPath using substitutes..." -$nixstore -r $outPath +nix-store -r $outPath cat $outPath/input-2/bar @@ -22,12 +22,12 @@ clearManifests pullCache echo "building $drvPath using substitutes..." -$nixstore -r $drvPath +nix-store -r $drvPath cat $outPath/input-2/bar # Check that the derivers are set properly. -test $($nixstore -q --deriver "$outPath") = "$drvPath" -$nixstore -q --deriver $(readLink $outPath/input-2) | grep -q -- "-input-2.drv" +test $(nix-store -q --deriver "$outPath") = "$drvPath" +nix-store -q --deriver $(readLink $outPath/input-2) | grep -q -- "-input-2.drv" clearManifests diff --git a/tests/nix-push.sh b/tests/nix-push.sh index 0cef0c22a2..69f05141af 100644 --- a/tests/nix-push.sh +++ b/tests/nix-push.sh @@ -1,7 +1,7 @@ source common.sh -drvPath=$($nixinstantiate dependencies.nix) -outPath=$($nixstore -r $drvPath) +drvPath=$(nix-instantiate dependencies.nix) +outPath=$(nix-store -r $drvPath) echo "pushing $drvPath" diff --git a/tests/parallel.sh b/tests/parallel.sh index 565c6f735a..13349e875f 100644 --- a/tests/parallel.sh +++ b/tests/parallel.sh @@ -8,7 +8,7 @@ clearStore rm -f $SHARED.cur $SHARED.max -outPath=$($nixbuild -j10000 parallel.nix) +outPath=$(nix-build -j10000 parallel.nix) echo "output path is $outPath" @@ -27,9 +27,9 @@ clearStore rm -f $SHARED.cur $SHARED.max -drvPath=$($nixinstantiate parallel.nix --argstr sleepTime 15) +drvPath=$(nix-instantiate parallel.nix --argstr sleepTime 15) -cmd="$nixstore -j1 -r $drvPath" +cmd="nix-store -j1 -r $drvPath" $cmd & pid1=$! diff --git a/tests/referrers.sh b/tests/referrers.sh index a0c195d5ab..d4604aec93 100644 --- a/tests/referrers.sh +++ b/tests/referrers.sh @@ -6,7 +6,7 @@ max=500 reference=$NIX_STORE_DIR/abcdef touch $reference -(echo $reference && echo && echo 0) | $nixstore --register-validity +(echo $reference && echo && echo 0) | nix-store --register-validity echo "making registration..." @@ -22,11 +22,11 @@ done > $TEST_ROOT/reg_info echo "registering..." -$nixstore --register-validity < $TEST_ROOT/reg_info +nix-store --register-validity < $TEST_ROOT/reg_info echo "collecting garbage..." ln -sfn $reference "$NIX_STATE_DIR"/gcroots/ref -$nixstore --gc +nix-store --gc if test "$(sqlite3 ./test-tmp/db/db.sqlite 'select count(*) from Refs')" -ne 0; then echo "referrers not cleaned up" diff --git a/tests/secure-drv-outputs.sh b/tests/secure-drv-outputs.sh index 25dd6bfc01..3cb8899967 100644 --- a/tests/secure-drv-outputs.sh +++ b/tests/secure-drv-outputs.sh @@ -10,11 +10,11 @@ clearManifests startDaemon # Determine the output path of the "good" derivation. -goodOut=$($nixstore -q $($nixinstantiate ./secure-drv-outputs.nix -A good)) +goodOut=$(nix-store -q $(nix-instantiate ./secure-drv-outputs.nix -A good)) # Instantiate the "bad" derivation. -badDrv=$($nixinstantiate ./secure-drv-outputs.nix -A bad) -badOut=$($nixstore -q $badDrv) +badDrv=$(nix-instantiate ./secure-drv-outputs.nix -A bad) +badOut=$(nix-store -q $badDrv) # Rewrite the bad derivation to produce the output path of the good # derivation. @@ -23,12 +23,12 @@ sed -e "s|$badOut|$goodOut|g" < $badDrv > $TEST_ROOT/bad.drv # Add the manipulated derivation to the store and build it. This # should fail. -if badDrv2=$($nixstore --add $TEST_ROOT/bad.drv); then - $nixstore -r "$badDrv2" +if badDrv2=$(nix-store --add $TEST_ROOT/bad.drv); then + nix-store -r "$badDrv2" fi # Now build the good derivation. -goodOut2=$($nixbuild ./secure-drv-outputs.nix -A good) +goodOut2=$(nix-build ./secure-drv-outputs.nix -A good) test "$goodOut" = "$goodOut2" if ! test -e "$goodOut"/good; then diff --git a/tests/simple.sh b/tests/simple.sh index 4f9f6e964a..af8bccc2b4 100644 --- a/tests/simple.sh +++ b/tests/simple.sh @@ -1,12 +1,12 @@ source common.sh -drvPath=$($nixinstantiate simple.nix) +drvPath=$(nix-instantiate simple.nix) -test "$($nixstore -q --binding system "$drvPath")" = "$system" +test "$(nix-store -q --binding system "$drvPath")" = "$system" echo "derivation is $drvPath" -outPath=$($nixstore -rvv "$drvPath") +outPath=$(nix-store -rvv "$drvPath") echo "output path is $outPath" @@ -15,10 +15,10 @@ if test "$text" != "Hello World!"; then exit 1; fi # Directed delete: $outPath is not reachable from a root, so it should # be deleteable. -$nixstore --delete $outPath +nix-store --delete $outPath if test -e $outPath/hello; then false; fi -outPath="$(NIX_STORE_DIR=/foo $nixinstantiate --readonly-mode hash-check.nix)" +outPath="$(NIX_STORE_DIR=/foo nix-instantiate --readonly-mode hash-check.nix)" if test "$outPath" != "/foo/lfy1s6ca46rm5r6w4gg9hc0axiakjcnm-dependencies.drv"; then echo "hashDerivationModulo appears broken, got $outPath" exit 1 diff --git a/tests/substitutes.sh b/tests/substitutes.sh index b48576c8c3..0c6adf2601 100644 --- a/tests/substitutes.sh +++ b/tests/substitutes.sh @@ -3,20 +3,20 @@ source common.sh clearStore # Instantiate. -drvPath=$($nixinstantiate simple.nix) +drvPath=$(nix-instantiate simple.nix) echo "derivation is $drvPath" # Find the output path. -outPath=$($nixstore -qvv "$drvPath") +outPath=$(nix-store -qvv "$drvPath") echo "output path is $outPath" echo $outPath > $TEST_ROOT/sub-paths export NIX_SUBSTITUTERS=$(pwd)/substituter.sh -$nixstore -r "$drvPath" --dry-run 2>&1 | grep -q "1.00 MiB.*2.00 MiB" +nix-store -r "$drvPath" --dry-run 2>&1 | grep -q "1.00 MiB.*2.00 MiB" -$nixstore -rvv "$drvPath" +nix-store -rvv "$drvPath" text=$(cat "$outPath"/hello) if test "$text" != "Hallo Wereld"; then echo "wrong substitute output: $text"; exit 1; fi diff --git a/tests/substitutes2.sh b/tests/substitutes2.sh index ad0bfcc268..bd914575cc 100644 --- a/tests/substitutes2.sh +++ b/tests/substitutes2.sh @@ -3,11 +3,11 @@ source common.sh clearStore # Instantiate. -drvPath=$($nixinstantiate simple.nix) +drvPath=$(nix-instantiate simple.nix) echo "derivation is $drvPath" # Find the output path. -outPath=$($nixstore -qvvvvv "$drvPath") +outPath=$(nix-store -qvvvvv "$drvPath") echo "output path is $outPath" echo $outPath > $TEST_ROOT/sub-paths @@ -15,7 +15,7 @@ echo $outPath > $TEST_ROOT/sub-paths # First try a substituter that fails, then one that succeeds export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh:$(pwd)/substituter.sh -$nixstore -j0 -rvv "$drvPath" +nix-store -j0 -rvv "$drvPath" text=$(cat "$outPath"/hello) if test "$text" != "Hallo Wereld"; then echo "wrong substitute output: $text"; exit 1; fi diff --git a/tests/timeout.sh b/tests/timeout.sh index f27739fb2b..2101d13a78 100644 --- a/tests/timeout.sh +++ b/tests/timeout.sh @@ -2,14 +2,14 @@ source common.sh -drvPath=$($nixinstantiate timeout.nix) +drvPath=$(nix-instantiate timeout.nix) -test "$($nixstore -q --binding system "$drvPath")" = "$system" +test "$(nix-store -q --binding system "$drvPath")" = "$system" echo "derivation is $drvPath" failed=0 -messages="`$nixstore -r --timeout 2 $drvPath 2>&1 || failed=1`" +messages="`nix-store -r --timeout 2 $drvPath 2>&1 || failed=1`" if test $failed -ne 0; then echo "error: \`nix-store' succeeded; should have timed out" >&2 exit 1 diff --git a/tests/user-envs.sh b/tests/user-envs.sh index 647223ef8c..025a5ff817 100644 --- a/tests/user-envs.sh +++ b/tests/user-envs.sh @@ -5,110 +5,110 @@ clearProfiles set -x # Query installed: should be empty. -test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 0 +test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 0 # Query available: should contain several. -test "$($nixenv -p $profiles/test -f ./user-envs.nix -qa '*' | wc -l)" -eq 5 +test "$(nix-env -p $profiles/test -f ./user-envs.nix -qa '*' | wc -l)" -eq 5 # Query descriptions. -$nixenv -p $profiles/test -f ./user-envs.nix -qa '*' --description | grep silly +nix-env -p $profiles/test -f ./user-envs.nix -qa '*' --description | grep silly # Install "foo-1.0". -$nixenv -p $profiles/test -f ./user-envs.nix -i foo-1.0 +nix-env -p $profiles/test -f ./user-envs.nix -i foo-1.0 # Query installed: should contain foo-1.0 now (which should be # executable). -test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 1 -$nixenv -p $profiles/test -q '*' | grep -q foo-1.0 +test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 1 +nix-env -p $profiles/test -q '*' | grep -q foo-1.0 test "$($profiles/test/bin/foo)" = "foo-1.0" # Store the path of foo-1.0. -outPath10=$($nixenv -p $profiles/test -q --out-path --no-name '*' | grep foo-1.0) +outPath10=$(nix-env -p $profiles/test -q --out-path --no-name '*' | grep foo-1.0) echo "foo-1.0 = $outPath10" test -n "$outPath10" # Install "foo-2.0pre1": should remove foo-1.0. -$nixenv -p $profiles/test -f ./user-envs.nix -i foo-2.0pre1 +nix-env -p $profiles/test -f ./user-envs.nix -i foo-2.0pre1 # Query installed: should contain foo-2.0pre1 now. -test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 1 -$nixenv -p $profiles/test -q '*' | grep -q foo-2.0pre1 +test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 1 +nix-env -p $profiles/test -q '*' | grep -q foo-2.0pre1 test "$($profiles/test/bin/foo)" = "foo-2.0pre1" # Upgrade "foo": should install foo-2.0. -$nixenv -p $profiles/test -f ./user-envs.nix -u foo +nix-env -p $profiles/test -f ./user-envs.nix -u foo # Query installed: should contain foo-2.0 now. -test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 1 -$nixenv -p $profiles/test -q '*' | grep -q foo-2.0 +test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 1 +nix-env -p $profiles/test -q '*' | grep -q foo-2.0 test "$($profiles/test/bin/foo)" = "foo-2.0" # Store the path of foo-2.0. -outPath20=$($nixenv -p $profiles/test -q --out-path --no-name '*' | grep foo-2.0) +outPath20=$(nix-env -p $profiles/test -q --out-path --no-name '*' | grep foo-2.0) test -n "$outPath20" # Install bar-0.1, uninstall foo. -$nixenv -p $profiles/test -f ./user-envs.nix -i bar-0.1 -$nixenv -p $profiles/test -f ./user-envs.nix -e foo +nix-env -p $profiles/test -f ./user-envs.nix -i bar-0.1 +nix-env -p $profiles/test -f ./user-envs.nix -e foo # Query installed: should only contain bar-0.1 now. -if $nixenv -p $profiles/test -q '*' | grep -q foo; then false; fi -$nixenv -p $profiles/test -q '*' | grep -q bar +if nix-env -p $profiles/test -q '*' | grep -q foo; then false; fi +nix-env -p $profiles/test -q '*' | grep -q bar # Rollback: should bring "foo" back. -$nixenv -p $profiles/test --rollback -$nixenv -p $profiles/test -q '*' | grep -q foo-2.0 -$nixenv -p $profiles/test -q '*' | grep -q bar +nix-env -p $profiles/test --rollback +nix-env -p $profiles/test -q '*' | grep -q foo-2.0 +nix-env -p $profiles/test -q '*' | grep -q bar # Rollback again: should remove "bar". -$nixenv -p $profiles/test --rollback -$nixenv -p $profiles/test -q '*' | grep -q foo-2.0 -if $nixenv -p $profiles/test -q '*' | grep -q bar; then false; fi +nix-env -p $profiles/test --rollback +nix-env -p $profiles/test -q '*' | grep -q foo-2.0 +if nix-env -p $profiles/test -q '*' | grep -q bar; then false; fi # Count generations. -$nixenv -p $profiles/test --list-generations -test "$($nixenv -p $profiles/test --list-generations | wc -l)" -eq 5 +nix-env -p $profiles/test --list-generations +test "$(nix-env -p $profiles/test --list-generations | wc -l)" -eq 5 # Install foo-1.0, now using its store path. echo $outPath10 -$nixenv -p $profiles/test -i "$outPath10" -$nixenv -p $profiles/test -q '*' | grep -q foo-1.0 +nix-env -p $profiles/test -i "$outPath10" +nix-env -p $profiles/test -q '*' | grep -q foo-1.0 # Uninstall foo-1.0, using a symlink to its store path. ln -sfn $outPath10/bin/foo $TEST_ROOT/symlink -$nixenv -p $profiles/test -e $TEST_ROOT/symlink -if $nixenv -p $profiles/test -q '*' | grep -q foo; then false; fi +nix-env -p $profiles/test -e $TEST_ROOT/symlink +if nix-env -p $profiles/test -q '*' | grep -q foo; then false; fi # Install foo-1.0, now using a symlink to its store path. -$nixenv -p $profiles/test -i $TEST_ROOT/symlink -$nixenv -p $profiles/test -q '*' | grep -q foo +nix-env -p $profiles/test -i $TEST_ROOT/symlink +nix-env -p $profiles/test -q '*' | grep -q foo # Delete all old generations. -$nixenv -p $profiles/test --delete-generations old +nix-env -p $profiles/test --delete-generations old # Run the garbage collector. This should get rid of foo-2.0 but not # foo-1.0. -$NIX_BIN_DIR/nix-collect-garbage +nix-collect-garbage test -e "$outPath10" if test -e "$outPath20"; then false; fi # Uninstall everything -$nixenv -p $profiles/test -f ./user-envs.nix -e '*' -test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 0 +nix-env -p $profiles/test -f ./user-envs.nix -e '*' +test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 0 # Installing "foo" should only install the newest foo. -$nixenv -p $profiles/test -f ./user-envs.nix -i foo -test "$($nixenv -p $profiles/test -q '*' | grep foo- | wc -l)" -eq 1 -$nixenv -p $profiles/test -q '*' | grep -q foo-2.0 +nix-env -p $profiles/test -f ./user-envs.nix -i foo +test "$(nix-env -p $profiles/test -q '*' | grep foo- | wc -l)" -eq 1 +nix-env -p $profiles/test -q '*' | grep -q foo-2.0 # On the other hand, this should install both (and should fail due to # a collision). -$nixenv -p $profiles/test -f ./user-envs.nix -e '*' -if $nixenv -p $profiles/test -f ./user-envs.nix -i foo-1.0 foo-2.0; then false; fi +nix-env -p $profiles/test -f ./user-envs.nix -e '*' +if nix-env -p $profiles/test -f ./user-envs.nix -i foo-1.0 foo-2.0; then false; fi # Installing "*" should install one foo and one bar. -$nixenv -p $profiles/test -f ./user-envs.nix -e '*' -$nixenv -p $profiles/test -f ./user-envs.nix -i '*' -test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 2 -$nixenv -p $profiles/test -q '*' | grep -q foo-2.0 -$nixenv -p $profiles/test -q '*' | grep -q bar-0.1.1 +nix-env -p $profiles/test -f ./user-envs.nix -e '*' +nix-env -p $profiles/test -f ./user-envs.nix -i '*' +test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 2 +nix-env -p $profiles/test -q '*' | grep -q foo-2.0 +nix-env -p $profiles/test -q '*' | grep -q bar-0.1.1 diff --git a/tests/verify.sh b/tests/verify.sh index 39609c7cec..e0d68e849d 100644 --- a/tests/verify.sh +++ b/tests/verify.sh @@ -1,3 +1,3 @@ source common.sh -$nixstore --verify +nix-store --verify From 5090c34ee1251dd8f0a57332feff0c99489f7faa Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Oct 2011 22:40:17 +0000 Subject: [PATCH 08/23] * Set the executable bit on scripts. --- scripts/Makefile.am | 3 +++ scripts/copy-from-other-stores.pl.in | 0 scripts/download-using-manifests.pl.in | 0 scripts/find-runtime-roots.pl.in | 0 scripts/nix-build.in | 0 scripts/nix-channel.in | 0 scripts/nix-collect-garbage.in | 0 scripts/nix-copy-closure.in | 0 scripts/nix-generate-patches.in | 0 scripts/nix-install-package.in | 0 scripts/nix-prefetch-url.in | 0 scripts/nix-pull.in | 0 scripts/nix-push.in | 0 scripts/nix-reduce-build.in | 0 14 files changed, 3 insertions(+) mode change 100644 => 100755 scripts/copy-from-other-stores.pl.in mode change 100644 => 100755 scripts/download-using-manifests.pl.in mode change 100644 => 100755 scripts/find-runtime-roots.pl.in mode change 100644 => 100755 scripts/nix-build.in mode change 100644 => 100755 scripts/nix-channel.in mode change 100644 => 100755 scripts/nix-collect-garbage.in mode change 100644 => 100755 scripts/nix-copy-closure.in mode change 100644 => 100755 scripts/nix-generate-patches.in mode change 100644 => 100755 scripts/nix-install-package.in mode change 100644 => 100755 scripts/nix-prefetch-url.in mode change 100644 => 100755 scripts/nix-pull.in mode change 100644 => 100755 scripts/nix-push.in mode change 100644 => 100755 scripts/nix-reduce-build.in diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 42ed0158e9..5f80d351ac 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -37,3 +37,6 @@ EXTRA_DIST = nix-collect-garbage.in \ nix-reduce-build.in \ nix-http-export.cgi.in \ nix-generate-patches.in + +clean: + rm -f $(bin_SCRIPTS) $(noinst_SCRIPTS) diff --git a/scripts/copy-from-other-stores.pl.in b/scripts/copy-from-other-stores.pl.in old mode 100644 new mode 100755 diff --git a/scripts/download-using-manifests.pl.in b/scripts/download-using-manifests.pl.in old mode 100644 new mode 100755 diff --git a/scripts/find-runtime-roots.pl.in b/scripts/find-runtime-roots.pl.in old mode 100644 new mode 100755 diff --git a/scripts/nix-build.in b/scripts/nix-build.in old mode 100644 new mode 100755 diff --git a/scripts/nix-channel.in b/scripts/nix-channel.in old mode 100644 new mode 100755 diff --git a/scripts/nix-collect-garbage.in b/scripts/nix-collect-garbage.in old mode 100644 new mode 100755 diff --git a/scripts/nix-copy-closure.in b/scripts/nix-copy-closure.in old mode 100644 new mode 100755 diff --git a/scripts/nix-generate-patches.in b/scripts/nix-generate-patches.in old mode 100644 new mode 100755 diff --git a/scripts/nix-install-package.in b/scripts/nix-install-package.in old mode 100644 new mode 100755 diff --git a/scripts/nix-prefetch-url.in b/scripts/nix-prefetch-url.in old mode 100644 new mode 100755 diff --git a/scripts/nix-pull.in b/scripts/nix-pull.in old mode 100644 new mode 100755 diff --git a/scripts/nix-push.in b/scripts/nix-push.in old mode 100644 new mode 100755 diff --git a/scripts/nix-reduce-build.in b/scripts/nix-reduce-build.in old mode 100644 new mode 100755 From a2a317eb0bc418577461105790c70b363a10cc34 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 11 Oct 2011 09:31:55 +0000 Subject: [PATCH 09/23] * Distribute GeneratePatches.pm. --- perl/Makefile.am | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/perl/Makefile.am b/perl/Makefile.am index a459bdc87c..d41340af03 100644 --- a/perl/Makefile.am +++ b/perl/Makefile.am @@ -2,11 +2,13 @@ perlversion := $(shell perl -e 'use Config; print $$Config{version};') perlarchname := $(shell perl -e 'use Config; print $$Config{archname};') perllibdir = $(libdir)/perl5/site_perl/$(perlversion)/$(perlarchname) -all: lib/Nix/Config.pm +PERL_MODULES = lib/Nix/Store.pm lib/Nix/Manifest.pm lib/Nix/GeneratePatches.pm lib/Nix/Config.pm.in -install-exec-local: lib/Nix/*.pm lib/Nix/Config.pm +all: $(PERL_MODULES:.in=) + +install-exec-local: $(PERL_MODULES:.in=) $(INSTALL) -d $(DESTDIR)$(perllibdir)/Nix - $(INSTALL_DATA) lib/Nix/*.pm $(DESTDIR)$(perllibdir)/Nix + $(INSTALL_DATA) $(PERL_MODULES:.in=) $(DESTDIR)$(perllibdir)/Nix $(INSTALL) -d $(DESTDIR)$(perllibdir)/auto/Nix/Store ln -sfn $(pkglibdir)/libNixStore.so $(DESTDIR)$(perllibdir)/auto/Nix/Store/Store.so @@ -24,6 +26,6 @@ AM_CXXFLAGS = \ lib/Nix/Store.cc: lib/Nix/Store.xs xsubpp $^ -output $@ -EXTRA_DIST = lib/Nix/Store.pm lib/Nix/Manifest.pm lib/Nix/Config.pm.in lib/Nix/Store.xs +EXTRA_DIST = $(PERL_MODULES) lib/Nix/Store.xs include ../substitute.mk From 7d314b8c959ca5c3dda8aea9c74079f4be63e19e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 11 Oct 2011 11:14:30 +0000 Subject: [PATCH 11/23] * Work around a race condition starting the Nix daemon. --- tests/common.sh.in | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/common.sh.in b/tests/common.sh.in index 567f5b4606..62ac669df6 100644 --- a/tests/common.sh.in +++ b/tests/common.sh.in @@ -32,7 +32,7 @@ export REAL_DATA_DIR=@datadir@ export REAL_STORE_DIR=@storedir@ export NIX_BUILD_HOOK= export PERL=perl -export PERL5LIB=$TOP/perl/lib +export PERL5LIB=$TOP/perl/lib:$PERL5LIB export NIX_BZIP2="@bzip2_bin_test@/bzip2" if test "${NIX_BZIP2:0:1}" != "/"; then NIX_BZIP2=`pwd`/${NIX_BZIP2} @@ -74,7 +74,14 @@ clearManifests() { } startDaemon() { + # Start the daemon, wait for the socket to appear. !!! + # ‘nix-worker’ should have an option to fork into the background. + rm -f $NIX_STATE_DIR/daemon-socket/socket nix-worker --daemon & + for ((i = 0; i < 30; i++)); do + if [ -e $NIX_STATE_DIR/daemon-socket/socket ]; then break; fi + sleep 1 + done pidDaemon=$! trap "kill -9 $pidDaemon" EXIT export NIX_REMOTE=daemon From c362e4d718cb31e532a4e2d708d07a57bc3bdf55 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 11 Oct 2011 11:45:36 +0000 Subject: [PATCH 12/23] * Move SSH.pm. --- perl/Makefile.am | 2 +- {scripts => perl/lib/Nix}/SSH.pm | 0 scripts/Makefile.am | 2 -- scripts/build-remote.pl.in | 4 ++-- scripts/nix-copy-closure.in | 11 +++++------ 5 files changed, 8 insertions(+), 11 deletions(-) rename {scripts => perl/lib/Nix}/SSH.pm (100%) diff --git a/perl/Makefile.am b/perl/Makefile.am index d41340af03..e6a5f9b5e7 100644 --- a/perl/Makefile.am +++ b/perl/Makefile.am @@ -2,7 +2,7 @@ perlversion := $(shell perl -e 'use Config; print $$Config{version};') perlarchname := $(shell perl -e 'use Config; print $$Config{archname};') perllibdir = $(libdir)/perl5/site_perl/$(perlversion)/$(perlarchname) -PERL_MODULES = lib/Nix/Store.pm lib/Nix/Manifest.pm lib/Nix/GeneratePatches.pm lib/Nix/Config.pm.in +PERL_MODULES = lib/Nix/Store.pm lib/Nix/Manifest.pm lib/Nix/GeneratePatches.pm lib/Nix/SSH.pm lib/Nix/Config.pm.in all: $(PERL_MODULES:.in=) diff --git a/scripts/SSH.pm b/perl/lib/Nix/SSH.pm similarity index 100% rename from scripts/SSH.pm rename to perl/lib/Nix/SSH.pm diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 5f80d351ac..a5703760d1 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -13,7 +13,6 @@ install-exec-local: download-using-manifests.pl copy-from-other-stores.pl find-r $(INSTALL) -d $(DESTDIR)$(sysconfdir)/profile.d $(INSTALL_PROGRAM) nix-profile.sh $(DESTDIR)$(sysconfdir)/profile.d/nix.sh $(INSTALL) -d $(DESTDIR)$(libexecdir)/nix - $(INSTALL_DATA) SSH.pm $(DESTDIR)$(libexecdir)/nix $(INSTALL_PROGRAM) find-runtime-roots.pl $(DESTDIR)$(libexecdir)/nix $(INSTALL_PROGRAM) build-remote.pl $(DESTDIR)$(libexecdir)/nix $(INSTALL) -d $(DESTDIR)$(libexecdir)/nix/substituters @@ -27,7 +26,6 @@ EXTRA_DIST = nix-collect-garbage.in \ nix-pull.in nix-push.in nix-profile.sh.in \ nix-prefetch-url.in nix-install-package.in \ nix-channel.in \ - SSH.pm \ nix-build.in \ download-using-manifests.pl.in \ copy-from-other-stores.pl.in \ diff --git a/scripts/build-remote.pl.in b/scripts/build-remote.pl.in index e943b0d9e3..e8c76086da 100755 --- a/scripts/build-remote.pl.in +++ b/scripts/build-remote.pl.in @@ -1,9 +1,9 @@ -#! @perl@ -w -I@libexecdir@/nix +#! @perl@ -w @perlFlags@ use Fcntl ':flock'; use English '-no_match_vars'; use IO::Handle; -use SSH qw/sshOpts openSSHConnection/; +use Nix::SSH qw/sshOpts openSSHConnection/; no warnings('once'); diff --git a/scripts/nix-copy-closure.in b/scripts/nix-copy-closure.in index c037f003f0..966f860d0b 100755 --- a/scripts/nix-copy-closure.in +++ b/scripts/nix-copy-closure.in @@ -1,8 +1,7 @@ -#! @perl@ -w -I@libexecdir@/nix +#! @perl@ -w @perlFlags@ -use SSH; - -my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@"; +use Nix::SSH; +use Nix::Config; if (scalar @ARGV < 1) { @@ -61,7 +60,7 @@ if ($toMode) { # Copy TO the remote machine. my @allStorePaths; # Get the closure of this path. - my $pid = open(READ, "set -f; $binDir/nix-store --query --requisites @storePaths|") or die; + my $pid = open(READ, "set -f; $Nix::Config::binDir/nix-store --query --requisites @storePaths|") or die; while () { chomp; @@ -130,7 +129,7 @@ else { # Copy FROM the remote machine. print STDERR " $_\n" foreach @missing; my $extraOpts = ""; $extraOpts .= "--sign" if $sign == 1; - system("set -f; ssh $sshHost @sshOpts 'nix-store --export $extraOpts @missing $compressor' | $decompressor @bindir@/nix-store --import") == 0 + system("set -f; ssh $sshHost @sshOpts 'nix-store --export $extraOpts @missing $compressor' | $decompressor $Nix::Config::binDir/nix-store --import") == 0 or die "copying store paths from remote machine `$sshHost' failed: $?"; } From 2492914fbcd1d616c89b83fda0ee08551486273e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 11 Oct 2011 13:06:59 +0000 Subject: [PATCH 13/23] * Move the remote building test from the NixOS tree to the Nix tree. --- release.nix | 9 +++- tests/remote-builds.nix | 97 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 tests/remote-builds.nix diff --git a/release.nix b/release.nix index cc210d2c6d..5a64374271 100644 --- a/release.nix +++ b/release.nix @@ -1,5 +1,5 @@ -{ nixpkgs ? ../nixpkgs -, nix ? { outPath = ./.; rev = 1234; } +{ nixpkgs ? , nixos ? +, nix ? { outPath = ../nix-export; rev = 1234; } , officialRelease ? false }: @@ -140,6 +140,11 @@ let deb_ubuntu1010x86_64 = makeDeb_x86_64 (diskImageFuns: diskImageFuns.ubuntu1010x86_64) 50; + # System tests. + tests.remote_builds = (import ./tests/remote-builds.nix rec { + inherit nixpkgs nixos; nix = build { inherit system; }; system = "x86_64-linux"; + }).test; + }; diff --git a/tests/remote-builds.nix b/tests/remote-builds.nix new file mode 100644 index 0000000000..201ca9dba1 --- /dev/null +++ b/tests/remote-builds.nix @@ -0,0 +1,97 @@ +# Test Nix's remote build feature. + +{ nixpkgs, nixos, system, nix }: + +with import "${nixos}/lib/testing.nix" { inherit nixpkgs system; }; + +makeTest ({ pkgs, ... }: + +let + + # The configuration of the build slaves. + slave = + { config, pkgs, ... }: + { services.openssh.enable = true; + virtualisation.writableStore = true; + environment.nix = nix; + }; + + # Trivial Nix expression to build remotely. + expr = config: nr: pkgs.writeText "expr.nix" + '' + let utils = builtins.storePath ${config.system.build.extraUtils}; in + derivation { + name = "hello-${toString nr}"; + system = "i686-linux"; + PATH = "''${utils}/bin"; + builder = "''${utils}/bin/sh"; + args = [ "-c" "echo Hello; mkdir $out; cat /proc/sys/kernel/hostname > $out/host; sleep 3" ]; + } + ''; + +in + +{ + + nodes = + { slave1 = slave; + slave2 = slave; + + client = + { config, pkgs, ... }: + { nix.maxJobs = 0; # force remote building + nix.distributedBuilds = true; + nix.buildMachines = + [ { hostName = "slave1"; + sshUser = "root"; + sshKey = "/root/.ssh/id_dsa"; + system = "i686-linux"; + maxJobs = 1; + } + { hostName = "slave2"; + sshUser = "root"; + sshKey = "/root/.ssh/id_dsa"; + system = "i686-linux"; + maxJobs = 1; + } + ]; + virtualisation.writableStore = true; + virtualisation.pathsInNixDB = [ config.system.build.extraUtils ]; + environment.nix = nix; + }; + }; + + testScript = { nodes }: + '' + startAll; + + # Create an SSH key on the client. + my $key = `${pkgs.openssh}/bin/ssh-keygen -t dsa -f key -N ""`; + $client->succeed("mkdir -m 700 /root/.ssh"); + $client->copyFileFromHost("key", "/root/.ssh/id_dsa"); + $client->succeed("chmod 600 /root/.ssh/id_dsa"); + + # Install the SSH key on the slaves. + foreach my $slave ($slave1, $slave2) { + $slave->succeed("mkdir -m 700 /root/.ssh"); + $slave->copyFileFromHost("key.pub", "/root/.ssh/authorized_keys"); + $slave->waitForJob("sshd"); + $client->succeed("ssh -o StrictHostKeyChecking=no " . $slave->name() . " 'echo hello world'"); + } + + # Perform a build and check that it was performed on the slave. + my $out = $client->succeed("nix-build ${expr nodes.client.config 1}"); + $slave1->succeed("test -e $out"); + + # And a parallel build. + my ($out1, $out2) = split /\s/, + $client->succeed("nix-store -r \$(nix-instantiate ${expr nodes.client.config 2} ${expr nodes.client.config 3})"); + $slave1->succeed("test -e $out1 -o -e $out2"); + $slave2->succeed("test -e $out1 -o -e $out2"); + + # Test whether the build hook automatically skips unavailable slaves. + $slave1->block; + $client->succeed("nix-build ${expr nodes.client.config 4}"); + ''; + +}) From d43a148204a983bf676750f50640969f8edf7350 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 11 Oct 2011 13:58:47 +0000 Subject: [PATCH 14/23] * Add a test for nix-copy-closure. --- release.nix | 4 +++ tests/nix-copy-closure.nix | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/nix-copy-closure.nix diff --git a/release.nix b/release.nix index 5a64374271..4f3e5fac02 100644 --- a/release.nix +++ b/release.nix @@ -145,6 +145,10 @@ let inherit nixpkgs nixos; nix = build { inherit system; }; system = "x86_64-linux"; }).test; + tests.nix_copy_closure = (import ./tests/nix-copy-closure.nix rec { + inherit nixpkgs nixos; nix = build { inherit system; }; system = "x86_64-linux"; + }).test; + }; diff --git a/tests/nix-copy-closure.nix b/tests/nix-copy-closure.nix new file mode 100644 index 0000000000..5b00a9a5c8 --- /dev/null +++ b/tests/nix-copy-closure.nix @@ -0,0 +1,53 @@ +# Test ‘nix-copy-closure’. + +{ nixpkgs, nixos, system, nix }: + +with import "${nixos}/lib/testing.nix" { inherit nixpkgs system; }; + +makeTest ({ pkgs, ... }: let pkgA = pkgs.aterm; pkgB = pkgs.wget; in { + + nodes = + { client = + { config, pkgs, ... }: + { virtualisation.writableStore = true; + virtualisation.pathsInNixDB = [ pkgA ]; + environment.nix = nix; + }; + + server = + { config, pkgs, ... }: + { services.openssh.enable = true; + virtualisation.writableStore = true; + virtualisation.pathsInNixDB = [ pkgB ]; + environment.nix = nix; + }; + }; + + testScript = { nodes }: + '' + startAll; + + # Create an SSH key on the client. + my $key = `${pkgs.openssh}/bin/ssh-keygen -t dsa -f key -N ""`; + $client->succeed("mkdir -m 700 /root/.ssh"); + $client->copyFileFromHost("key", "/root/.ssh/id_dsa"); + $client->succeed("chmod 600 /root/.ssh/id_dsa"); + + # Install the SSH key on the server. + $server->succeed("mkdir -m 700 /root/.ssh"); + $server->copyFileFromHost("key.pub", "/root/.ssh/authorized_keys"); + $server->waitForJob("sshd"); + $client->succeed("ssh -o StrictHostKeyChecking=no " . $server->name() . " 'echo hello world'"); + + # Copy the closure of package A from the client to the server. + $server->fail("nix-store --check-validity ${pkgA}"); + $client->succeed("nix-copy-closure --to server --gzip ${pkgA} >&2"); + $server->succeed("nix-store --check-validity ${pkgA}"); + + # Copy the closure of package B from the server to the client. + $client->fail("nix-store --check-validity ${pkgB}"); + $client->succeed("nix-copy-closure --from server --gzip ${pkgB} >&2"); + $client->succeed("nix-store --check-validity ${pkgB}"); + ''; + +}) From 67617574280a5db534e5b5c643a3b880d1b9336c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 11 Oct 2011 15:41:13 +0000 Subject: [PATCH 15/23] * Use the Store API bindings in nix-copy-closure. --- perl/Makefile.am | 1 + perl/lib/Nix/Store.pm | 2 +- perl/lib/Nix/Store.xs | 41 ++++++++++++++++++++++++++++--------- scripts/nix-copy-closure.in | 31 +++------------------------- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/perl/Makefile.am b/perl/Makefile.am index e6a5f9b5e7..eded469f92 100644 --- a/perl/Makefile.am +++ b/perl/Makefile.am @@ -5,6 +5,7 @@ perllibdir = $(libdir)/perl5/site_perl/$(perlversion)/$(perlarchname) PERL_MODULES = lib/Nix/Store.pm lib/Nix/Manifest.pm lib/Nix/GeneratePatches.pm lib/Nix/SSH.pm lib/Nix/Config.pm.in all: $(PERL_MODULES:.in=) + ln -sfn $(abs_builddir)/.libs/libNixStore.so lib/Store.so install-exec-local: $(PERL_MODULES:.in=) $(INSTALL) -d $(DESTDIR)$(perllibdir)/Nix diff --git a/perl/lib/Nix/Store.pm b/perl/lib/Nix/Store.pm index af69debeda..bef6e7460c 100644 --- a/perl/lib/Nix/Store.pm +++ b/perl/lib/Nix/Store.pm @@ -12,7 +12,7 @@ our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); -our @EXPORT = qw( ); +our @EXPORT = qw(isValidPath topoSortPaths computeFSClosure followLinksToStorePath); our $VERSION = '0.15'; diff --git a/perl/lib/Nix/Store.xs b/perl/lib/Nix/Store.xs index dd5cffdbb7..af71ad955c 100644 --- a/perl/lib/Nix/Store.xs +++ b/perl/lib/Nix/Store.xs @@ -39,8 +39,7 @@ void init() doInit(); -int isValidPath(path) - char * path +int isValidPath(char * path) CODE: try { doInit(); @@ -52,8 +51,7 @@ int isValidPath(path) RETVAL -SV * queryReferences(path) - char * path +SV * queryReferences(char * path) PPCODE: try { doInit(); @@ -66,8 +64,7 @@ SV * queryReferences(path) } -SV * queryPathHash(path) - char * path +SV * queryPathHash(char * path) PPCODE: try { doInit(); @@ -79,8 +76,7 @@ SV * queryPathHash(path) } -SV * queryDeriver(path) - char * path +SV * queryDeriver(char * path) PPCODE: try { doInit(); @@ -92,8 +88,7 @@ SV * queryDeriver(path) } -SV * queryPathInfo(path) - char * path +SV * queryPathInfo(char * path) PPCODE: try { doInit(); @@ -127,3 +122,29 @@ SV * computeFSClosure(int flipDirection, int includeOutputs, ...) } catch (Error & e) { croak(e.what()); } + + +SV * topoSortPaths(...) + PPCODE: + try { + doInit(); + PathSet paths; + for (int n = 0; n < items; ++n) paths.insert(SvPV_nolen(ST(n))); + Paths sorted = topoSortPaths(*store, paths); + for (Paths::iterator i = sorted.begin(); i != sorted.end(); ++i) + XPUSHs(sv_2mortal(newSVpv(i->c_str(), 0))); + } catch (Error & e) { + croak(e.what()); + } + + +SV * followLinksToStorePath(char * path) + CODE: + try { + doInit(); + RETVAL = newSVpv(followLinksToStorePath(path).c_str(), 0); + } catch (Error & e) { + croak(e.what()); + } + OUTPUT: + RETVAL diff --git a/scripts/nix-copy-closure.in b/scripts/nix-copy-closure.in index 966f860d0b..db76b7165e 100755 --- a/scripts/nix-copy-closure.in +++ b/scripts/nix-copy-closure.in @@ -2,6 +2,7 @@ use Nix::SSH; use Nix::Config; +use Nix::Store; if (scalar @ARGV < 1) { @@ -57,19 +58,8 @@ openSSHConnection $sshHost or die "$0: unable to start SSH\n"; if ($toMode) { # Copy TO the remote machine. - my @allStorePaths; - # Get the closure of this path. - my $pid = open(READ, "set -f; $Nix::Config::binDir/nix-store --query --requisites @storePaths|") or die; - - while () { - chomp; - die "bad: $_" unless /^\//; - push @allStorePaths, $_; - } - - close READ or die "nix-store failed: $?"; - + my @allStorePaths = reverse(topoSortPaths(computeFSClosure(0, 0, map { followLinksToStorePath $_ } @storePaths))); # Ask the remote host which paths are invalid. open(READ, "set -f; ssh $sshHost @sshOpts nix-store --check-validity --print-invalid @allStorePaths|"); @@ -80,7 +70,6 @@ if ($toMode) { # Copy TO the remote machine. } close READ or die; - # Export the store paths and import them on the remote machine. if (scalar @missing > 0) { print STDERR "copying these missing paths:\n"; @@ -93,7 +82,6 @@ if ($toMode) { # Copy TO the remote machine. } - else { # Copy FROM the remote machine. # Query the closure of the given store paths on the remote @@ -102,27 +90,14 @@ else { # Copy FROM the remote machine. my $pid = open(READ, "set -f; ssh @sshOpts $sshHost nix-store --query --requisites @storePaths|") or die; - my @allStorePaths; - while () { chomp; die "bad: $_" unless /^\//; - push @allStorePaths, $_; + push @missing, $_ unless isValidPath($_); } close READ or die "nix-store on remote machine `$sshHost' failed: $?"; - - # What paths are already valid locally? - open(READ, "set -f; @bindir@/nix-store --check-validity --print-invalid @allStorePaths|"); - my @missing = (); - while () { - chomp; - push @missing, $_; - } - close READ or die; - - # Export the store paths on the remote machine and import them on locally. if (scalar @missing > 0) { print STDERR "copying these missing paths:\n"; From f186a9141efd20b1236b9df29de1bf4b1f2098ce Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 18 Oct 2011 21:21:22 +0000 Subject: [PATCH 16/23] =?UTF-8?q?*=20nix-copy-closure:=20support=20?= =?UTF-8?q?=E2=80=98--dry-run=E2=80=99=20and=20=E2=80=98--include-outputs?= =?UTF-8?q?=E2=80=99.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/nix-copy-closure.in | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/scripts/nix-copy-closure.in b/scripts/nix-copy-closure.in index db76b7165e..172acd9e7d 100755 --- a/scripts/nix-copy-closure.in +++ b/scripts/nix-copy-closure.in @@ -24,6 +24,10 @@ my $decompressor = ""; my $toMode = 1; +my $includeOutputs = 0; + +my $dryRun = 0; + # !!! Copied from nix-pack-closure, should put this in a module. my @storePaths = (); @@ -44,6 +48,12 @@ while (@ARGV) { elsif ($arg eq "--to") { $toMode = 1; } + elsif ($arg eq "--include-outputs") { + $includeOutputs = 1; + } + elsif ($arg eq "--dry-run") { + $dryRun = 1; + } elsif (!defined $sshHost) { $sshHost = $arg; } @@ -59,7 +69,7 @@ openSSHConnection $sshHost or die "$0: unable to start SSH\n"; if ($toMode) { # Copy TO the remote machine. # Get the closure of this path. - my @allStorePaths = reverse(topoSortPaths(computeFSClosure(0, 0, map { followLinksToStorePath $_ } @storePaths))); + my @allStorePaths = reverse(topoSortPaths(computeFSClosure(0, $includeOutputs, map { followLinksToStorePath $_ } @storePaths))); # Ask the remote host which paths are invalid. open(READ, "set -f; ssh $sshHost @sshOpts nix-store --check-validity --print-invalid @allStorePaths|"); @@ -74,10 +84,11 @@ if ($toMode) { # Copy TO the remote machine. if (scalar @missing > 0) { print STDERR "copying these missing paths:\n"; print STDERR " $_\n" foreach @missing; - my $extraOpts = ""; - $extraOpts .= "--sign" if $sign == 1; - system("set -f; nix-store --export $extraOpts @missing $compressor | ssh $sshHost @sshOpts '$decompressor nix-store --import'") == 0 - or die "copying store paths to remote machine `$sshHost' failed: $?"; + unless ($dryRun) { + my $extraOpts = $sign ? "--sign" : ""; + system("set -f; nix-store --export $extraOpts @missing $compressor | ssh $sshHost @sshOpts '$decompressor nix-store --import'") == 0 + or die "copying store paths to remote machine `$sshHost' failed: $?"; + } } } @@ -87,8 +98,9 @@ else { # Copy FROM the remote machine. # Query the closure of the given store paths on the remote # machine. Paths are assumed to be store paths; there is no # resolution (following of symlinks). + my $extraOpts = $includeOutputs ? "--include-outputs" : ""; my $pid = open(READ, - "set -f; ssh @sshOpts $sshHost nix-store --query --requisites @storePaths|") or die; + "set -f; ssh @sshOpts $sshHost nix-store --query --requisites $extraOpts @storePaths|") or die; while () { chomp; @@ -102,10 +114,11 @@ else { # Copy FROM the remote machine. if (scalar @missing > 0) { print STDERR "copying these missing paths:\n"; print STDERR " $_\n" foreach @missing; - my $extraOpts = ""; - $extraOpts .= "--sign" if $sign == 1; - system("set -f; ssh $sshHost @sshOpts 'nix-store --export $extraOpts @missing $compressor' | $decompressor $Nix::Config::binDir/nix-store --import") == 0 - or die "copying store paths from remote machine `$sshHost' failed: $?"; + 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") == 0 + or die "copying store paths from remote machine `$sshHost' failed: $?"; + } } } From 00b41e46ed02d16aeea1375c14a84df02a91efba Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 19 Oct 2011 21:34:13 +0000 Subject: [PATCH 17/23] * Print a consistent message. --- scripts/nix-pull.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/nix-pull.in b/scripts/nix-pull.in index 8fb256179c..f3cba0c026 100755 --- a/scripts/nix-pull.in +++ b/scripts/nix-pull.in @@ -73,7 +73,7 @@ sub processURL { # Otherwise, just get the uncompressed manifest. else { - print "obtaining list of Nix archives at `$url'...\n"; + print "fetching list of Nix archives at `$url'...\n"; $manifest = downloadFile $url; } From a12095d3be095ba9d88631e21ef6d43f1ddb5cee Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 27 Oct 2011 19:06:23 +0000 Subject: [PATCH 18/23] * In printValueAsXML, handle the case where a "type" attribute is not a string. This happens in the NixOS option system. * Remove a bogus comparison of a unsigned integer with -1. --- src/libexpr/eval.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index d0bdaf2382..2b97b76fb7 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -170,8 +170,8 @@ EvalState::EvalState() size_t size = 32 * 1024 * 1024; #if HAVE_SYSCONF && defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES) long pageSize = sysconf(_SC_PAGESIZE); - long pages = sysconf (_SC_PHYS_PAGES); - if (pageSize != -1 && size != -1) + long pages = sysconf(_SC_PHYS_PAGES); + if (pageSize != -1) size = (pageSize * pages) / 4; // 25% of RAM if (size > maxSize) size = maxSize; #endif @@ -1108,7 +1108,10 @@ bool EvalState::isDerivation(Value & v) { if (v.type != tAttrs) return false; Bindings::iterator i = v.attrs->find(sType); - return i != v.attrs->end() && forceStringNoCtx(*i->value) == "derivation"; + if (i == v.attrs->end()) return false; + forceValue(*i->value); + if (i->value->type != tString) return false; + return forceStringNoCtx(*i->value) == "derivation"; } From 325b5a8aee89a12c30fbfcf74503f5105be0b230 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Nov 2011 19:14:54 +0000 Subject: [PATCH 19/23] * Fix permission on /nix/store in the manual for multi-user installs (reported by Silvio Frischknecht). --- doc/manual/installation.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual/installation.xml b/doc/manual/installation.xml index bed96cd885..9e73fb69a2 100644 --- a/doc/manual/installation.xml +++ b/doc/manual/installation.xml @@ -314,7 +314,7 @@ bit turned on (like /tmp): $ chgrp nixbld /nix/store -$ chmod 1777 /nix/store +$ chmod 1775 /nix/store From d7b87bebe3ac8f47e387c79e03ceb5915e71d249 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 3 Nov 2011 18:47:10 +0000 Subject: [PATCH 20/23] * The Nix configuration file is usually /etc/nix/nix.conf. --- doc/manual/installation.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual/installation.xml b/doc/manual/installation.xml index 9e73fb69a2..755f539070 100644 --- a/doc/manual/installation.xml +++ b/doc/manual/installation.xml @@ -323,7 +323,7 @@ $ chmod 1775 /nix/store specifying the build users group in the build-users-group option in the Nix configuration -file (/nix/etc/nix/nix.conf): +file (usually /etc/nix/nix.conf): build-users-group = nixbld From daed9aeac557af4ec8d3d8f00b4f3f2b8f90408a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 3 Nov 2011 19:22:24 +0000 Subject: [PATCH 21/23] --- doc/manual/conf-file.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual/conf-file.xml b/doc/manual/conf-file.xml index 8fb3ff99de..10e6d08cde 100644 --- a/doc/manual/conf-file.xml +++ b/doc/manual/conf-file.xml @@ -6,7 +6,7 @@ A number of persistent settings of Nix are stored in the file -prefix/etc/nix/nix.conf. +sysconfdir/nix/nix.conf. This file is a list of name = value pairs, one per line. Comments start with a # character. An example From fa69ff57269dfd24ff04810c04d130e3e5d94154 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 5 Nov 2011 21:06:24 +0000 Subject: [PATCH 22/23] * Fix the broken reference to bunzip2 in the channel unpack script. --- corepkgs/channels/unpack.sh.in | 2 +- externals/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/corepkgs/channels/unpack.sh.in b/corepkgs/channels/unpack.sh.in index fc85e4ad2e..6e5939f4f2 100644 --- a/corepkgs/channels/unpack.sh.in +++ b/corepkgs/channels/unpack.sh.in @@ -14,7 +14,7 @@ for ((n = 0; n < ${#inputs[*]}; n += 2)); do echo "unpacking channel $channelName" - @bunzip2@ < $channelTarball | @tar@ xf - + @bzip2@ -d < $channelTarball | @tar@ xf - if test -e */channel-name; then channelName="$(@coreutils@/cat */channel-name)" diff --git a/externals/Makefile.am b/externals/Makefile.am index 884d87bf17..ec2e5c6d35 100644 --- a/externals/Makefile.am +++ b/externals/Makefile.am @@ -23,7 +23,7 @@ build-bzip2: $(BZIP2) install-exec-local:: build-bzip2 mkdir -p $(DESTDIR)${bzip2_bin} - $(INSTALL_PROGRAM) $(bzip2_bin_test)/bzip2 $(bzip2_bin_test)/bunzip2 $(DESTDIR)${bzip2_bin} + $(INSTALL_PROGRAM) $(bzip2_bin_test)/bzip2 $(DESTDIR)${bzip2_bin} endif From a6a3f3a8c26fdd6900880c13e924e6879d6c714c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 5 Nov 2011 21:23:01 +0000 Subject: [PATCH 23/23] * Fix race condition in the test. --- tests/nix-copy-closure.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/nix-copy-closure.nix b/tests/nix-copy-closure.nix index 5b00a9a5c8..7e2cf3a088 100644 --- a/tests/nix-copy-closure.nix +++ b/tests/nix-copy-closure.nix @@ -37,6 +37,7 @@ makeTest ({ pkgs, ... }: let pkgA = pkgs.aterm; pkgB = pkgs.wget; in { $server->succeed("mkdir -m 700 /root/.ssh"); $server->copyFileFromHost("key.pub", "/root/.ssh/authorized_keys"); $server->waitForJob("sshd"); + $client->waitForJob("network-interfaces"); $client->succeed("ssh -o StrictHostKeyChecking=no " . $server->name() . " 'echo hello world'"); # Copy the closure of package A from the client to the server.