From ca3d96222a21ffb1b8ee3c1dcb8ea5a917e7d216 Mon Sep 17 00:00:00 2001 From: Wouter den Breejen Date: Mon, 8 Oct 2007 12:47:47 +0000 Subject: [PATCH] Merged R9207 --- scripts/nix-channel.in | 33 ++++++++++------- scripts/nix-prefetch-url.in | 2 +- scripts/nix-pull.in | 6 ++-- scripts/nix-push.in | 2 +- src/libexpr/primops.cc | 53 ++++++++++++++++++++++++++++ src/libstore/gc.cc | 4 ++- src/libstore/local-store.cc | 32 +++++++++++++++-- src/libstore/local-store.hh | 6 ++-- src/libstore/pathlocks.cc | 6 ++-- src/libstore/worker-protocol.hh | 22 ++++++------ tests/Makefile.am | 12 +++---- tests/common.sh.in | 11 ++++-- tests/fallback.nix.in | 7 ---- tests/fallback.sh | 12 ++++--- tests/fixed.builder2.sh | 2 ++ tests/fixed.nix.in | 12 ++++++- tests/fixed.sh | 15 ++++++++ tests/init.sh | 1 + tests/lang/eval-okay-listToAttrs.nix | 8 +++++ tests/lang/eval-okay-listToAttrs.out | 1 + tests/nix-pull.sh | 4 ++- tests/remote-store.sh | 17 +++++++++ tests/simple.builder.sh | 2 +- tests/substituter.sh | 27 +++++++++----- tests/substituter2.sh | 21 +++++++++-- tests/substitutes.nix.in | 6 ---- tests/substitutes.sh | 14 ++++---- tests/substitutes2.nix.in | 6 ---- tests/substitutes2.sh | 18 ++++------ 29 files changed, 258 insertions(+), 104 deletions(-) delete mode 100644 tests/fallback.nix.in create mode 100644 tests/lang/eval-okay-listToAttrs.nix create mode 100644 tests/lang/eval-okay-listToAttrs.out create mode 100644 tests/remote-store.sh delete mode 100644 tests/substitutes.nix.in delete mode 100644 tests/substitutes2.nix.in diff --git a/scripts/nix-channel.in b/scripts/nix-channel.in index 1ef9c5844..1efb1a03a 100644 --- a/scripts/nix-channel.in +++ b/scripts/nix-channel.in @@ -2,7 +2,7 @@ use strict; -my $rootsDir = "@localstatedir@/nix/gcroots/channels"; +my $rootsDir = "@localstatedir@/nix/gcroots"; my $stateDir = $ENV{"NIX_STATE_DIR"}; $stateDir = "@localstatedir@/nix" unless defined $stateDir; @@ -10,8 +10,8 @@ $stateDir = "@localstatedir@/nix" unless defined $stateDir; # Turn on caching in nix-prefetch-url. my $channelCache = "$stateDir/channel-cache"; -$ENV{'NIX_DOWNLOAD_CACHE'} = $channelCache; mkdir $channelCache, 0755 unless -e $channelCache; +$ENV{'NIX_DOWNLOAD_CACHE'} = $channelCache if -W $channelCache; # Figure out the name of the `.nix-channels' file to use. @@ -76,16 +76,25 @@ sub removeChannel { sub update { readChannels; - # Remove all the old manifests. - for my $manifest (glob "$stateDir/manifests/*.nixmanifest") { - unlink $manifest or die "cannot remove `$manifest': $!"; - } + # Do we have write permission to the manifests directory? If not, + # then just skip pulling the manifest and just download the Nix + # expressions. If the user is a non-privileged user in a + # multi-user Nix installation, he at least gets installation from + # source. + if (-W "$stateDir/manifests") { + + # Remove all the old manifests. + for my $manifest (glob "$stateDir/manifests/*.nixmanifest") { + unlink $manifest or die "cannot remove `$manifest': $!"; + } + + # Pull cache manifests. + foreach my $url (@channels) { + #print "pulling cache manifest from `$url'\n"; + system("@bindir@/nix-pull", "--skip-wrong-store", "$url/MANIFEST") == 0 + or die "cannot pull cache manifest from `$url'"; + } - # Pull cache manifests. - foreach my $url (@channels) { - #print "pulling cache manifest from `$url'\n"; - system("@bindir@/nix-pull", "--skip-wrong-store", "$url/MANIFEST") == 0 - or die "cannot pull cache manifest from `$url'"; } # Create a Nix expression that fetches and unpacks the channel Nix @@ -112,7 +121,7 @@ sub update { my $userName = getpwuid($<); die "who ARE you? go away" unless defined $userName; - my $rootFile = "$rootsDir/$userName"; + my $rootFile = "$rootsDir/per-user/$userName/channels"; # Instantiate the Nix expression. print "unpacking channel Nix expressions...\n"; diff --git a/scripts/nix-prefetch-url.in b/scripts/nix-prefetch-url.in index 186804d8e..5621d5204 100644 --- a/scripts/nix-prefetch-url.in +++ b/scripts/nix-prefetch-url.in @@ -37,7 +37,7 @@ fi doDownload() { - @curl@ $cacheFlags --fail -# --show-error --location --max-redirs 20 --disable-epsv \ + @curl@ $cacheFlags --fail -# --location --max-redirs 20 --disable-epsv \ --cookie-jar $tmpPath/cookies "$url" -o $tmpFile } diff --git a/scripts/nix-pull.in b/scripts/nix-pull.in index f1f01f4d2..2776d0b17 100644 --- a/scripts/nix-pull.in +++ b/scripts/nix-pull.in @@ -40,7 +40,9 @@ sub downloadFile { my $url = shift; $ENV{"PRINT_PATH"} = 1; $ENV{"QUIET"} = 1; - my ($dummy, $path) = `@bindir@/nix-prefetch-url '$url'`; + my ($dummy, $path) = `$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; return $path; } @@ -74,7 +76,7 @@ sub processURL { } if (readManifest($manifest, \%narFiles, \%localPaths, \%patches) < 3) { - die "manifest `$url' is too old (i.e., for Nix <= 0.7)\n"; + die "`$url' is not manifest or it is too old (i.e., for Nix <= 0.7)\n"; } if ($skipWrongStore) { diff --git a/scripts/nix-push.in b/scripts/nix-push.in index e5bd404a2..992622fbb 100644 --- a/scripts/nix-push.in +++ b/scripts/nix-push.in @@ -265,7 +265,7 @@ print STDERR "uploading manifest...\n"; if ($localCopy) { copyFile $manifest, $localManifestFile; } else { - system("$curl --show-error --upload-file " . + system("$curl --show-error --upload-file " . "'$manifest' '$manifestPutURL' > /dev/null") == 0 or die "curl failed on $manifest: $?"; } diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index d18f3274b..f696d8267 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -298,6 +298,17 @@ static Expr prim_getEnv(EvalState & state, const ATermVector & args) return makeStr(getEnv(name)); } +/* for debugging purposes. print the first arg on stdout (perhaps stderr should be used?) + * and return the second + */ +static Expr prim_trace(EvalState & state, const ATermVector & args) +{ + //string str = evalStringNoCtx(state, args[0]); + + Expr a = evalExpr(state, args[0]); + printf("traced value: %s\n", atPrint(a).c_str()); + return evalExpr(state, args[1]); +} static Expr prim_relativise(EvalState & state, const ATermVector & args) { @@ -892,6 +903,39 @@ static Expr prim_hasAttr(EvalState & state, const ATermVector & args) } +/* takes + * param: list of { attr="attr"; value=value } + * returns an attribute set + * */ +static Expr prim_listToAttrs(EvalState & state, const ATermVector & args) +{ + try { + ATermMap res = ATermMap(); + + ATermList list; + list = evalList(state, args[0]); + for (ATermIterator i(list); i; ++i){ + // *i should now contain a pointer to the list item expression + ATermList attrs; + Expr evaledExpr = evalExpr(state, *i); + if (matchAttrs(evaledExpr, attrs)){ + Expr e = evalExpr(state, makeSelect(evaledExpr, toATerm("attr"))); + string attr = evalStringNoCtx(state,e); + ATerm value; + Expr r = makeSelect(evaledExpr, toATerm("value")); + res.set(toATerm(attr), makeAttrRHS(r, makeNoPos())); + } + else { + throw EvalError(format("passed list item is a %s (value: %s). Set { attr=\"name\"; value=nix expr; } expected.") % showType(evaledExpr) % showValue(evaledExpr)); + } + } // for + return makeAttrs(res); + } catch (Error & e) { + e.addPrefix(format("while calling listToAttrs ")); + throw; + } +} + static Expr prim_removeAttrs(EvalState & state, const ATermVector & args) { ATermMap attrs; @@ -906,6 +950,12 @@ static Expr prim_removeAttrs(EvalState & state, const ATermVector & args) return makeAttrs(attrs); } +/* Determine whether the argument is a list. */ +static Expr prim_isAttrs(EvalState & state, const ATermVector & args) +{ + ATermList list; + return makeBool(matchAttrs(evalExpr(state, args[0]), list)); +} /************************************************************* * Lists @@ -1049,6 +1099,7 @@ void EvalState::addPrimOps() addPrimOp("abort", 1, prim_abort); addPrimOp("throw", 1, prim_throw); addPrimOp("__getEnv", 1, prim_getEnv); + addPrimOp("__trace", 2, prim_trace); addPrimOp("relativise", 2, prim_relativise); @@ -1071,7 +1122,9 @@ void EvalState::addPrimOps() addPrimOp("__attrNames", 1, prim_attrNames); addPrimOp("__getAttr", 2, prim_getAttr); addPrimOp("__hasAttr", 2, prim_hasAttr); + addPrimOp("__isAttrs", 1, prim_isAttrs); addPrimOp("removeAttrs", 2, prim_removeAttrs); + addPrimOp("__listToAttrs", 1, prim_listToAttrs); // Lists addPrimOp("__isList", 1, prim_isList); diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 59d039349..5f8cf2f92 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -61,6 +61,8 @@ void createSymlink(const Path & link, const Path & target, bool careful) /* Create directories up to `gcRoot'. */ createDirs(dirOf(link)); + /* !!! shouldn't removing and creating the symlink be atomic? */ + /* Remove the old symlink. */ if (pathExists(link)) { if (careful && (!isLink(link) || !isInStore(readLink(link)))) @@ -68,7 +70,7 @@ void createSymlink(const Path & link, const Path & target, bool careful) unlink(link.c_str()); } - /* And create the new own. */ + /* And create the new one. */ if (symlink(target.c_str(), link.c_str()) == -1) throw SysError(format("symlinking `%1%' to `%2%'") % link % target); diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 338def8d6..457c98ab0 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -161,6 +161,7 @@ static TableId dbSharedState = 0; static void upgradeStore07(); static void upgradeStore09(); +static void upgradeStore11(); void checkStoreNotSymlink() @@ -245,6 +246,8 @@ LocalStore::LocalStore(bool reserveSpace) upgradeStore07(); if (curSchema == 2) upgradeStore09(); + if (curSchema == 3) + upgradeStore11(); writeFile(schemaFN, (format("%1%") % nixSchemaVersion).str()); } } @@ -1926,10 +1929,10 @@ static void upgradeStore09() { /* !!! we should disallow concurrent upgrades */ - printMsg(lvlError, "upgrading Nix store to new schema (this may take a while)..."); - if (!pathExists(nixDBPath + "/referers")) return; + printMsg(lvlError, "upgrading Nix store to new schema (this may take a while)..."); + /* Transaction txn(nixDB); @@ -1970,4 +1973,29 @@ static void upgradeStore09() } +/* Upgrade from schema 3 (Nix 0.10) to schema 4 (Nix >= 0.11). The + only thing to do here is to delete the substitutes table and get + rid of invalid but substitutable references/referrers. */ +static void upgradeStore11() +{ + if (!pathExists(nixDBPath + "/substitutes")) return; + + printMsg(lvlError, "upgrading Nix store to new schema (this may take a while)..."); + + Transaction txn(nixDB); + TableId dbSubstitutes = nixDB.openTable("substitutes"); + + Paths subKeys; + nixDB.enumTable(txn, dbSubstitutes, subKeys); + for (Paths::iterator i = subKeys.begin(); i != subKeys.end(); ++i) { + if (!isValidPathTxn(txn, *i)) + invalidateStorePath(txn, *i); + } + + txn.commit(); + nixDB.closeTable(dbSubstitutes); + nixDB.deleteTable("substitutes"); +} + + } diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 97fdb5c20..c1a702fa3 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -13,9 +13,9 @@ class Transaction; /* Nix store and database schema version. Version 1 (or 0) was Nix <= - 0.7. Version 2 was Nix 0.8 and 0.9. Version 3 is Nix 0.10 and - up. */ -const int nixSchemaVersion = 3; + 0.7. Version 2 was Nix 0.8 and 0.9. Version 3 is Nix 0.10. + Version 4 is Nix 0.11. */ +const int nixSchemaVersion = 4; extern string drvsLogDir; diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index 03ba4f212..821d4d02f 100644 --- a/src/libstore/pathlocks.cc +++ b/src/libstore/pathlocks.cc @@ -161,10 +161,8 @@ void PathLocks::lockPaths(const PathSet & _paths, const string & waitMsg) debug(format("locking path `%1%'") % path); - if (lockedPaths.find(lockPath) != lockedPaths.end()) { - debug(format("already holding lock on `%1%'") % lockPath); - continue; - } + if (lockedPaths.find(lockPath) != lockedPaths.end()) + throw Error("deadlock: trying to re-acquire self-held lock"); AutoCloseFD fd; diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh index 497ab4bd6..46d03ea79 100644 --- a/src/libstore/worker-protocol.hh +++ b/src/libstore/worker-protocol.hh @@ -10,27 +10,27 @@ namespace nix { typedef enum { - wopQuit, //0 - wopIsValidPath, + wopQuit = 0, //0 + wopIsValidPath, + wopHasSubstitutes = 3, wopIsValidStatePath, wopIsValidComponentOrStatePath, - wopHasSubstitutes, wopQueryPathHash, wopQueryStatePathDrv, wopQueryStoreReferences, wopQueryStateReferences, - wopQueryStoreReferrers, //10 - wopQueryStateReferrers, + wopQueryStoreReferrers, + wopQueryStateReferrers, //10 wopAddToStore, wopAddTextToStore, - wopBuildDerivations, //14 TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! HANGS SOMETIMES !!!!! + wopBuildDerivations, //13 wopEnsurePath, wopAddTempRoot, wopAddIndirectRoot, wopSyncWithGC, wopFindRoots, - wopCollectGarbage, //20 - wopExportPath, + wopCollectGarbage, + wopExportPath, //20 wopImportPath, wopQueryDeriver, wopQueryDerivers, @@ -39,15 +39,15 @@ typedef enum { wopIsStateComponent, wopStorePathRequisites, wopSetStateRevisions, - wopQueryStateRevisions, //30 - wopQueryAvailableStateRevisions, + wopQueryStateRevisions, + wopQueryAvailableStateRevisions, //30 wopCommitStatePath, wopScanAndUpdateAllReferences, wopGetSharedWith, wopToNonSharedPathSet, wopRevertToRevision, wopShareState, - wopUnShareState, + wopUnShareState, //37 } WorkerOp; diff --git a/tests/Makefile.am b/tests/Makefile.am index bfb8508a0..bab9e8ee4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,14 +2,11 @@ TESTS_ENVIRONMENT = $(SHELL) -e extra1 = $(shell pwd)/test-tmp/shared -simple.sh: simple.nix +simple.sh substitutes.sh substitutes2.sh fallback.sh: simple.nix dependencies.sh gc.sh nix-push.sh nix-pull.in logging.sh nix-build.sh install-package.sh check-refs.sh: dependencies.nix locking.sh: locking.nix parallel.sh: parallel.nix build-hook.sh: build-hook.nix -substitutes.sh: substitutes.nix -substitutes2.sh: substitutes2.nix -fallback.sh: fallback.nix gc-concurrent.sh: gc-concurrent.nix gc-concurrent2.nix user-envs.sh: user-envs.nix fixed.sh: fixed.nix @@ -21,7 +18,8 @@ TESTS = init.sh hash.sh lang.sh add.sh simple.sh dependencies.sh \ locking.sh parallel.sh build-hook.sh substitutes.sh substitutes2.sh \ fallback.sh nix-push.sh gc.sh gc-concurrent.sh verify.sh nix-pull.sh \ referrers.sh user-envs.sh logging.sh nix-build.sh misc.sh fixed.sh \ - gc-runtime.sh install-package.sh check-refs.sh filter-source.sh + gc-runtime.sh install-package.sh check-refs.sh filter-source.sh \ + remote-store.sh XFAIL_TESTS = @@ -36,11 +34,9 @@ EXTRA_DIST = $(TESTS) \ locking.nix.in locking.builder.sh \ parallel.nix.in parallel.builder.sh \ build-hook.nix.in build-hook.hook.sh \ - substitutes.nix.in substituter.sh \ - substitutes2.nix.in substituter2.sh \ + substituter.sh substituter2.sh \ gc-concurrent.nix.in gc-concurrent.builder.sh \ gc-concurrent2.nix.in gc-concurrent2.builder.sh \ - fallback.nix.in \ user-envs.nix.in user-envs.builder.sh \ fixed.nix.in fixed.builder1.sh fixed.builder2.sh \ gc-runtime.nix.in \ diff --git a/tests/common.sh.in b/tests/common.sh.in index 50316af14..d1c8a833f 100644 --- a/tests/common.sh.in +++ b/tests/common.sh.in @@ -2,7 +2,7 @@ set -e export TEST_ROOT=$(pwd)/test-tmp export NIX_STORE_DIR -if ! NIX_STORE_DIR=$(readlink -f $TEST_ROOT/store); then +if ! NIX_STORE_DIR=$(readlink -f $TEST_ROOT/store 2> /dev/null); then # Maybe the build directory is symlinked. export NIX_IGNORE_SYMLINK_STORE=1 NIX_STORE_DIR=$TEST_ROOT/store @@ -19,7 +19,9 @@ export NIX_LIBEXEC_DIR=$TEST_ROOT/bin export NIX_ROOT_FINDER= export SHARED=$TEST_ROOT/shared -export NIX_REMOTE= +if test -z "$FORCE_NIX_REMOTE"; then + export NIX_REMOTE= +fi export REAL_BIN_DIR=@bindir@ export REAL_LIBEXEC_DIR=@libexecdir@ @@ -46,6 +48,7 @@ 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() { @@ -66,3 +69,7 @@ clearProfiles() { profiles="$NIX_STATE_DIR"/profiles rm -f $profiles/* } + +clearManifests() { + rm -f $NIX_STATE_DIR/manifests/* +} diff --git a/tests/fallback.nix.in b/tests/fallback.nix.in deleted file mode 100644 index e47b59823..000000000 --- a/tests/fallback.nix.in +++ /dev/null @@ -1,7 +0,0 @@ -derivation { - name = "fall-back"; - system = "@system@"; - builder = "@shell@"; - args = ["-e" "-x" ./simple.builder.sh]; - goodPath = "@testPath@"; -} diff --git a/tests/fallback.sh b/tests/fallback.sh index 482e4ce5b..24889a452 100644 --- a/tests/fallback.sh +++ b/tests/fallback.sh @@ -1,15 +1,19 @@ source common.sh -drvPath=$($nixinstantiate fallback.nix) +clearStore + +drvPath=$($nixinstantiate simple.nix) echo "derivation is $drvPath" outPath=$($nixstore -q --fallback "$drvPath") echo "output path is $outPath" -# Register a non-existant substitute -(echo $outPath && echo "" && echo $TOP/no-such-program && echo 0 && echo 0) | $nixstore --register-substitutes +# 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 -# Build the derivation +# Build with a substitute that fails. This should fall back to a source build. +export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh $nixstore -r --fallback "$drvPath" text=$(cat "$outPath"/hello) diff --git a/tests/fixed.builder2.sh b/tests/fixed.builder2.sh index bc1a18d6e..31ea1579a 100644 --- a/tests/fixed.builder2.sh +++ b/tests/fixed.builder2.sh @@ -1,3 +1,5 @@ +echo dummy: $dummy +if test -n "$dummy"; then sleep 2; fi mkdir $out mkdir $out/bla echo "Hello World!" > $out/foo diff --git a/tests/fixed.nix.in b/tests/fixed.nix.in index ab2448871..47eff91e0 100644 --- a/tests/fixed.nix.in +++ b/tests/fixed.nix.in @@ -1,6 +1,6 @@ rec { - f = builder: mode: algo: hash: derivation { + f2 = dummy: builder: mode: algo: hash: derivation { name = "fixed"; system = "@system@"; builder = "@shell@"; @@ -9,8 +9,11 @@ rec { outputHashAlgo = algo; outputHash = hash; PATH = "@testPath@"; + inherit dummy; }; + f = f2 ""; + good = [ (f ./fixed.builder1.sh "flat" "md5" "8ddd8be4b179a529afa5f2ffae4b9858") (f ./fixed.builder1.sh "flat" "sha1" "a0b65939670bc2c010f4d5d6a0b3e4e4590fb92b") @@ -35,4 +38,11 @@ rec { (f ./fixed.builder1.sh "flat" "md5" "ddd8be4b179a529afa5f2ffae4b9858") ]; + # Test for building two derivations in parallel that produce the + # same output path because they're fixed-output derivations. + parallelSame = [ + (f2 "foo" ./fixed.builder2.sh "flat" "md5" "3670af73070fa14077ad74e0f5ea4e42") + (f2 "bar" ./fixed.builder2.sh "flat" "md5" "3670af73070fa14077ad74e0f5ea4e42") + ]; + } \ No newline at end of file diff --git a/tests/fixed.sh b/tests/fixed.sh index fc37e40f4..d0a284af4 100644 --- a/tests/fixed.sh +++ b/tests/fixed.sh @@ -1,18 +1,33 @@ source common.sh +clearStore + +echo 'testing good...' drvs=$($nixinstantiate fixed.nix -A good) echo $drvs $nixstore -r $drvs +echo 'testing good2...' drvs=$($nixinstantiate fixed.nix -A good2) echo $drvs $nixstore -r $drvs +echo 'testing bad...' drvs=$($nixinstantiate fixed.nix -A bad) echo $drvs if $nixstore -r $drvs; then false; fi +echo 'testing reallyBad...' if $nixinstantiate fixed.nix -A reallyBad; then false; fi # 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 parallel builds of derivations that produce the same output. +# Only one should run at the same time. +echo 'testing parallelSame...' +clearStore +drvs=$($nixinstantiate fixed.nix -A parallelSame) +echo $drvs +$nixstore -r $drvs -j2 diff --git a/tests/init.sh b/tests/init.sh index 8a47bb081..6fff25944 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -24,6 +24,7 @@ ln -s $storestatedir $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/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/ diff --git a/tests/lang/eval-okay-listToAttrs.nix b/tests/lang/eval-okay-listToAttrs.nix new file mode 100644 index 000000000..f5eae92cc --- /dev/null +++ b/tests/lang/eval-okay-listToAttrs.nix @@ -0,0 +1,8 @@ +# this test shows how to use listToAttrs and that evaluation is still lazy (throw isn't called) +let + asi = attr: value : { inherit attr value; }; + list = [ ( asi "a" "A" ) ( asi "b" "B" ) ]; + a = builtins.listToAttrs list; + b = builtins.listToAttrs ( list ++ list ); + r = builtins.listToAttrs [ (asi "result" [ a b ]) ( asi "throw" (throw "this should not be thrown")) ]; +in r.result diff --git a/tests/lang/eval-okay-listToAttrs.out b/tests/lang/eval-okay-listToAttrs.out new file mode 100644 index 000000000..4e779ff06 --- /dev/null +++ b/tests/lang/eval-okay-listToAttrs.out @@ -0,0 +1 @@ +List([Attrs([Bind("a",Str("A",[]),NoPos),Bind("b",Str("B",[]),NoPos)]),Attrs([Bind("a",Str("A",[]),NoPos),Bind("b",Str("B",[]),NoPos)])]) diff --git a/tests/nix-pull.sh b/tests/nix-pull.sh index a847510ce..5ef3e55ca 100644 --- a/tests/nix-pull.sh +++ b/tests/nix-pull.sh @@ -6,6 +6,7 @@ pullCache () { } clearStore +clearManifests pullCache drvPath=$($nixinstantiate dependencies.nix) @@ -17,6 +18,7 @@ $nixstore -r $outPath cat $outPath/input-2/bar clearStore +clearManifests pullCache echo "building $drvPath using substitutes..." @@ -28,4 +30,4 @@ cat $outPath/input-2/bar test $($nixstore -q --deriver "$outPath") = "$drvPath" $nixstore -q --deriver $(readLink $outPath/input-2) | grep -q -- "-input-2.drv" -$nixstore --clear-substitutes +clearManifests diff --git a/tests/remote-store.sh b/tests/remote-store.sh new file mode 100644 index 000000000..1e5a4356e --- /dev/null +++ b/tests/remote-store.sh @@ -0,0 +1,17 @@ +source common.sh + +export FORCE_NIX_REMOTE=1 + +echo '*** testing slave mode ***' +clearStore +clearManifests +NIX_REMOTE=slave $SHELL ./user-envs.sh + +echo '*** testing daemon mode ***' +clearStore +clearManifests +$nixworker --daemon & +pidDaemon=$! +NIX_REMOTE=daemon $SHELL ./user-envs.sh +kill -9 $pidDaemon +wait $pidDaemon || true diff --git a/tests/simple.builder.sh b/tests/simple.builder.sh index 536faec14..569e8ca88 100644 --- a/tests/simple.builder.sh +++ b/tests/simple.builder.sh @@ -1,7 +1,7 @@ echo "PATH=$PATH" # Verify that the PATH is empty. -if mkdir foo; then exit 1; fi +if mkdir foo 2> /dev/null; then exit 1; fi # Set a PATH (!!! impure). export PATH=$goodPath diff --git a/tests/substituter.sh b/tests/substituter.sh index 005e97605..96fb95b91 100755 --- a/tests/substituter.sh +++ b/tests/substituter.sh @@ -1,10 +1,19 @@ -#! /bin/sh -ex -echo $* - -case $* in - *) - mkdir $1 - echo $3 $4 > $1/hello - ;; -esac +#! /bin/sh -e +echo substituter args: $* >&2 +if test $1 = "--query-paths"; then + cat $TEST_ROOT/sub-paths +elif test $1 = "--query-info"; then + shift + for i in in $@; do + echo $i + echo "" # deriver + echo 0 # nr of refs + done +elif test $1 = "--substitute"; then + mkdir $2 + echo "Hallo Wereld" > $2/hello +else + echo "unknown substituter operation" + exit 1 +fi diff --git a/tests/substituter2.sh b/tests/substituter2.sh index c4e1bfec7..1bcf65a54 100755 --- a/tests/substituter2.sh +++ b/tests/substituter2.sh @@ -1,3 +1,18 @@ -#! /bin/sh -ex -echo $* -exit 1 +#! /bin/sh -e +echo substituter2 args: $* >&2 + +if test $1 = "--query-paths"; then + cat $TEST_ROOT/sub-paths +elif test $1 = "--query-info"; then + shift + for i in in $@; do + echo $i + echo "" # deriver + echo 0 # nr of refs + done +elif test $1 = "--substitute"; then + exit 1 +else + echo "unknown substituter operation" + exit 1 +fi diff --git a/tests/substitutes.nix.in b/tests/substitutes.nix.in deleted file mode 100644 index e34736216..000000000 --- a/tests/substitutes.nix.in +++ /dev/null @@ -1,6 +0,0 @@ -derivation { - name = "substitutes"; - system = "@system@"; - builder = "@shell@"; - args = ["-e" "-x" ./simple.builder.sh]; -} \ No newline at end of file diff --git a/tests/substitutes.sh b/tests/substitutes.sh index c44f012f5..042827314 100644 --- a/tests/substitutes.sh +++ b/tests/substitutes.sh @@ -1,22 +1,20 @@ source common.sh +clearStore + # Instantiate. -drvPath=$($nixinstantiate substitutes.nix) +drvPath=$($nixinstantiate simple.nix) echo "derivation is $drvPath" # Find the output path. outPath=$($nixstore -qvv "$drvPath") echo "output path is $outPath" -regSub() { - (echo $1 && echo "" && echo $2 && echo 3 && echo $outPath && echo Hallo && echo Wereld && echo 0) | $nixstore --register-substitutes -} - -# Register a substitute for the output path. -regSub $outPath $(pwd)/substituter.sh +echo $outPath > $TEST_ROOT/sub-paths +export NIX_SUBSTITUTERS=$(pwd)/substituter.sh $nixstore -rvv "$drvPath" text=$(cat "$outPath"/hello) -if test "$text" != "Hallo Wereld"; then exit 1; fi +if test "$text" != "Hallo Wereld"; then echo "wrong substitute output: $text"; exit 1; fi diff --git a/tests/substitutes2.nix.in b/tests/substitutes2.nix.in deleted file mode 100644 index 8ade1ba11..000000000 --- a/tests/substitutes2.nix.in +++ /dev/null @@ -1,6 +0,0 @@ -derivation { - name = "substitutes-2"; - system = "@system@"; - builder = "@shell@"; - args = ["-e" "-x" ./simple.builder.sh]; -} \ No newline at end of file diff --git a/tests/substitutes2.sh b/tests/substitutes2.sh index 416e81536..0bbc13913 100644 --- a/tests/substitutes2.sh +++ b/tests/substitutes2.sh @@ -1,25 +1,21 @@ source common.sh +clearStore + # Instantiate. -drvPath=$($nixinstantiate substitutes2.nix) +drvPath=$($nixinstantiate simple.nix) echo "derivation is $drvPath" # Find the output path. outPath=$($nixstore -qvvvvv "$drvPath") echo "output path is $outPath" -regSub() { - (echo $1 && echo "" && echo $2 && echo 3 && echo $outPath && echo Hallo && echo Wereld && echo 0) | $nixstore --register-substitutes -} +echo $outPath > $TEST_ROOT/sub-paths -# Register a substitute for the output path. -regSub $outPath $(pwd)/substituter.sh - -# Register another substitute for the output path. This one takes -# precedence over the previous one. It will fail. -regSub $outPath $(pwd)/substituter2.sh +# First try a substituter that fails, then one that succeeds +export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh:$(pwd)/substituter.sh $nixstore -rvv "$drvPath" text=$(cat "$outPath"/hello) -if test "$text" != "Hallo Wereld"; then exit 1; fi +if test "$text" != "Hallo Wereld"; then echo "wrong substitute output: $text"; exit 1; fi