From 54888b92ded6c242ce4914628553d8b2c9c55d10 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Mar 2022 13:54:08 +0100 Subject: [PATCH 1/8] Move installables-related operations --- src/libcmd/command.cc | 2 +- src/libcmd/command.hh | 54 ---------------------------------- src/libcmd/installables.cc | 14 ++++----- src/libcmd/installables.hh | 60 ++++++++++++++++++++++++++++++++++++++ src/nix/app.cc | 2 +- src/nix/build.cc | 2 +- src/nix/develop.cc | 7 +++-- src/nix/diff-closures.cc | 4 +-- src/nix/profile.cc | 2 +- src/nix/run.cc | 2 +- src/nix/show-derivation.cc | 2 +- src/nix/why-depends.cc | 4 +-- 12 files changed, 81 insertions(+), 74 deletions(-) diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 6d183dfad..dc8fa9e5a 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -153,7 +153,7 @@ void BuiltPathsCommand::run(ref store) for (auto & p : store->queryAllValidPaths()) paths.push_back(BuiltPath::Opaque{p}); } else { - paths = toBuiltPaths(getEvalStore(), store, realiseMode, operateOn, installables); + paths = Installable::toBuiltPaths(getEvalStore(), store, realiseMode, operateOn, installables); if (recursive) { // XXX: This only computes the store path closure, ignoring // intermediate realisations diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh index bd2a0a7ee..0f6125f11 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -5,7 +5,6 @@ #include "common-eval-args.hh" #include "path.hh" #include "flake/lockfile.hh" -#include "store-api.hh" #include @@ -82,14 +81,6 @@ struct MixFlakeOptions : virtual Args, EvalCommand { return {}; } }; -/* How to handle derivations in commands that operate on store paths. */ -enum class OperateOn { - /* Operate on the output path. */ - Output, - /* Operate on the .drv path. */ - Derivation -}; - struct SourceExprCommand : virtual Args, MixFlakeOptions { std::optional file; @@ -113,19 +104,6 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions void completeInstallable(std::string_view prefix); }; -enum class Realise { - /* Build the derivation. Postcondition: the - derivation outputs exist. */ - Outputs, - /* Don't build the derivation. Postcondition: the store derivation - exists. */ - Derivation, - /* Evaluate in dry-run mode. Postcondition: nothing. */ - // FIXME: currently unused, but could be revived if we can - // evaluate derivations in-memory. - Nothing -}; - /* A command that operates on a list of "installables", which can be store paths, attribute paths, Nix expressions, etc. */ struct InstallablesCommand : virtual Args, SourceExprCommand @@ -238,38 +216,6 @@ static RegisterCommand registerCommand2(std::vector && name) return RegisterCommand(std::move(name), [](){ return make_ref(); }); } -BuiltPaths build( - ref evalStore, - ref store, Realise mode, - const std::vector> & installables, - BuildMode bMode = bmNormal); - -std::set toStorePaths( - ref evalStore, - ref store, - Realise mode, - OperateOn operateOn, - const std::vector> & installables); - -StorePath toStorePath( - ref evalStore, - ref store, - Realise mode, - OperateOn operateOn, - std::shared_ptr installable); - -std::set toDerivations( - ref store, - const std::vector> & installables, - bool useDeriver = false); - -BuiltPaths toBuiltPaths( - ref evalStore, - ref store, - Realise mode, - OperateOn operateOn, - const std::vector> & installables); - /* Helper function to generate args that invoke $EDITOR on filename:lineno. */ Strings editorFor(const Pos & pos); diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index c07e39628..b9afe5105 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -787,7 +787,7 @@ BuiltPaths getBuiltPaths(ref evalStore, ref store, const DerivedPa return res; } -BuiltPaths build( +BuiltPaths Installable::build( ref evalStore, ref store, Realise mode, @@ -812,7 +812,7 @@ BuiltPaths build( return getBuiltPaths(evalStore, store, pathsToBuild); } -BuiltPaths toBuiltPaths( +BuiltPaths Installable::toBuiltPaths( ref evalStore, ref store, Realise mode, @@ -820,19 +820,19 @@ BuiltPaths toBuiltPaths( const std::vector> & installables) { if (operateOn == OperateOn::Output) - return build(evalStore, store, mode, installables); + return Installable::build(evalStore, store, mode, installables); else { if (mode == Realise::Nothing) settings.readOnlyMode = true; BuiltPaths res; - for (auto & drvPath : toDerivations(store, installables, true)) + for (auto & drvPath : Installable::toDerivations(store, installables, true)) res.push_back(BuiltPath::Opaque{drvPath}); return res; } } -StorePathSet toStorePaths( +StorePathSet Installable::toStorePaths( ref evalStore, ref store, Realise mode, OperateOn operateOn, @@ -846,7 +846,7 @@ StorePathSet toStorePaths( return outPaths; } -StorePath toStorePath( +StorePath Installable::toStorePath( ref evalStore, ref store, Realise mode, OperateOn operateOn, @@ -860,7 +860,7 @@ StorePath toStorePath( return *paths.begin(); } -StorePathSet toDerivations( +StorePathSet Installable::toDerivations( ref store, const std::vector> & installables, bool useDeriver) diff --git a/src/libcmd/installables.hh b/src/libcmd/installables.hh index 3d2563e4b..f296434c5 100644 --- a/src/libcmd/installables.hh +++ b/src/libcmd/installables.hh @@ -5,6 +5,7 @@ #include "path-with-outputs.hh" #include "derived-path.hh" #include "eval.hh" +#include "store-api.hh" #include "flake/flake.hh" #include @@ -29,6 +30,27 @@ struct UnresolvedApp App resolve(ref evalStore, ref store); }; +enum class Realise { + /* Build the derivation. Postcondition: the + derivation outputs exist. */ + Outputs, + /* Don't build the derivation. Postcondition: the store derivation + exists. */ + Derivation, + /* Evaluate in dry-run mode. Postcondition: nothing. */ + // FIXME: currently unused, but could be revived if we can + // evaluate derivations in-memory. + Nothing +}; + +/* How to handle derivations in commands that operate on store paths. */ +enum class OperateOn { + /* Operate on the output path. */ + Output, + /* Operate on the .drv path. */ + Derivation +}; + struct Installable { virtual ~Installable() { } @@ -68,6 +90,39 @@ struct Installable { return FlakeRef::fromAttrs({{"type","indirect"}, {"id", "nixpkgs"}}); } + + static BuiltPaths build( + ref evalStore, + ref store, + Realise mode, + const std::vector> & installables, + BuildMode bMode = bmNormal); + + static std::set toStorePaths( + ref evalStore, + ref store, + Realise mode, + OperateOn operateOn, + const std::vector> & installables); + + static StorePath toStorePath( + ref evalStore, + ref store, + Realise mode, + OperateOn operateOn, + std::shared_ptr installable); + + static std::set toDerivations( + ref store, + const std::vector> & installables, + bool useDeriver = false); + + static BuiltPaths toBuiltPaths( + ref evalStore, + ref store, + Realise mode, + OperateOn operateOn, + const std::vector> & installables); }; struct InstallableValue : Installable @@ -131,4 +186,9 @@ ref openEvalCache( EvalState & state, std::shared_ptr lockedFlake); +BuiltPaths getBuiltPaths( + ref evalStore, + ref store, + const DerivedPaths & hopefullyBuiltPaths); + } diff --git a/src/nix/app.cc b/src/nix/app.cc index e104cc9c1..2563180fb 100644 --- a/src/nix/app.cc +++ b/src/nix/app.cc @@ -114,7 +114,7 @@ App UnresolvedApp::resolve(ref evalStore, ref store) installableContext.push_back( std::make_shared(store, ctxElt.toDerivedPath())); - auto builtContext = build(evalStore, store, Realise::Outputs, installableContext); + auto builtContext = Installable::build(evalStore, store, Realise::Outputs, installableContext); res.program = resolveString(*store, unresolved.program, builtContext); if (!store->isInStore(res.program)) throw Error("app program '%s' is not in the Nix store", res.program); diff --git a/src/nix/build.cc b/src/nix/build.cc index 6e31757a2..680db1c60 100644 --- a/src/nix/build.cc +++ b/src/nix/build.cc @@ -52,7 +52,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile void run(ref store) override { - auto buildables = build( + auto buildables = Installable::build( getEvalStore(), store, dryRun ? Realise::Derivation : Realise::Outputs, installables, buildMode); diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 92e31599a..8af5da9d0 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -307,7 +307,7 @@ struct Common : InstallableCommand, MixProfile for (auto & [installable_, dir_] : redirects) { auto dir = absPath(dir_); auto installable = parseInstallable(store, installable_); - auto builtPaths = toStorePaths( + auto builtPaths = Installable::toStorePaths( getEvalStore(), store, Realise::Nothing, OperateOn::Output, {installable}); for (auto & path: builtPaths) { auto from = store->printStorePath(path); @@ -347,7 +347,7 @@ struct Common : InstallableCommand, MixProfile if (path && hasSuffix(path->to_string(), "-env")) return *path; else { - auto drvs = toDerivations(store, {installable}); + auto drvs = Installable::toDerivations(store, {installable}); if (drvs.size() != 1) throw Error("'%s' needs to evaluate to a single derivation, but it evaluated to %d derivations", @@ -511,7 +511,8 @@ struct CmdDevelop : Common, MixEnvironment nixpkgsLockFlags); shell = store->printStorePath( - toStorePath(getEvalStore(), store, Realise::Outputs, OperateOn::Output, bashInstallable)) + "/bin/bash"; + Installable::toStorePath(getEvalStore(), store, Realise::Outputs, OperateOn::Output, bashInstallable)) + + "/bin/bash"; } catch (Error &) { ignoreException(); } diff --git a/src/nix/diff-closures.cc b/src/nix/diff-closures.cc index 734c41e0e..0621d662c 100644 --- a/src/nix/diff-closures.cc +++ b/src/nix/diff-closures.cc @@ -131,9 +131,9 @@ struct CmdDiffClosures : SourceExprCommand void run(ref store) override { auto before = parseInstallable(store, _before); - auto beforePath = toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, before); + auto beforePath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, before); auto after = parseInstallable(store, _after); - auto afterPath = toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, after); + auto afterPath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, after); printClosureDiff(store, beforePath, afterPath, ""); } }; diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 82507db2c..c1bf62357 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -252,7 +252,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile manifest.elements.emplace_back(std::move(element)); } else { - auto buildables = build(getEvalStore(), store, Realise::Outputs, {installable}, bmNormal); + auto buildables = Installable::build(getEvalStore(), store, Realise::Outputs, {installable}, bmNormal); for (auto & buildable : buildables) { ProfileElement element; diff --git a/src/nix/run.cc b/src/nix/run.cc index a67c23bcb..033263c36 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -91,7 +91,7 @@ struct CmdShell : InstallablesCommand, MixEnvironment void run(ref store) override { - auto outPaths = toStorePaths(getEvalStore(), store, Realise::Outputs, OperateOn::Output, installables); + auto outPaths = Installable::toStorePaths(getEvalStore(), store, Realise::Outputs, OperateOn::Output, installables); auto accessor = store->getFSAccessor(); diff --git a/src/nix/show-derivation.cc b/src/nix/show-derivation.cc index c614be68d..61a02c9b3 100644 --- a/src/nix/show-derivation.cc +++ b/src/nix/show-derivation.cc @@ -40,7 +40,7 @@ struct CmdShowDerivation : InstallablesCommand void run(ref store) override { - auto drvPaths = toDerivations(store, installables, true); + auto drvPaths = Installable::toDerivations(store, installables, true); if (recursive) { StorePathSet closure; diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index f7a3ec3a0..1d9ab28ba 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -82,9 +82,9 @@ struct CmdWhyDepends : SourceExprCommand void run(ref store) override { auto package = parseInstallable(store, _package); - auto packagePath = toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, package); + auto packagePath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, package); auto dependency = parseInstallable(store, _dependency); - auto dependencyPath = toStorePath(getEvalStore(), store, Realise::Derivation, operateOn, dependency); + auto dependencyPath = Installable::toStorePath(getEvalStore(), store, Realise::Derivation, operateOn, dependency); auto dependencyPathHash = dependencyPath.hashPart(); StorePathSet closure; From 161f798aa13b56c5f71120a8cb5788409d9ab815 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Mar 2022 20:37:46 +0100 Subject: [PATCH 2/8] nix profile: Support CA derivations --- src/libcmd/installables.cc | 4 +- src/libcmd/installables.hh | 1 - src/nix/profile.cc | 95 ++++++++++++++++++-------------------- tests/nix-profile.sh | 19 ++++++++ 4 files changed, 66 insertions(+), 53 deletions(-) diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index b9afe5105..f18be5287 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -470,7 +470,6 @@ std::vector InstallableAttrPath::toDerivations for (auto & drvInfo : drvInfos) { res.push_back({ state->store->parseStorePath(drvInfo.queryDrvPath()), - state->store->maybeParseStorePath(drvInfo.queryOutPath()), drvInfo.queryOutputName() }); } @@ -584,9 +583,8 @@ std::tuple InstallableF auto drvPath = attr->forceDerivation(); - auto drvInfo = DerivationInfo{ + auto drvInfo = DerivationInfo { std::move(drvPath), - state->store->maybeParseStorePath(attr->getAttr(state->sOutPath)->getString()), attr->getAttr(state->sOutputName)->getString() }; diff --git a/src/libcmd/installables.hh b/src/libcmd/installables.hh index f296434c5..e172b71b0 100644 --- a/src/libcmd/installables.hh +++ b/src/libcmd/installables.hh @@ -134,7 +134,6 @@ struct InstallableValue : Installable struct DerivationInfo { StorePath drvPath; - std::optional outPath; std::string outputName; }; diff --git a/src/nix/profile.cc b/src/nix/profile.cc index c1bf62357..48834d15b 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -61,6 +61,27 @@ struct ProfileElement { return std::tuple(describe(), storePaths) < std::tuple(other.describe(), other.storePaths); } + + void updateStorePaths(ref evalStore, ref store, Installable & installable) + { + // FIXME: respect meta.outputsToInstall + storePaths.clear(); + for (auto & buildable : getBuiltPaths(evalStore, store, installable.toDerivedPaths())) { + std::visit(overloaded { + [&](const BuiltPath::Opaque & bo) { + storePaths.insert(bo.path); + }, + [&](const BuiltPath::Built & bfd) { + // TODO: Why are we querying if we know the output + // names already? Is it just to figure out what the + // default one is? + for (auto & output : store->queryDerivationOutputMap(bfd.drvPath)) { + storePaths.insert(output.second); + } + }, + }, buildable.raw()); + } + } }; struct ProfileManifest @@ -232,53 +253,25 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile { ProfileManifest manifest(*getEvalState(), *profile); - std::vector pathsToBuild; + auto builtPaths = Installable::build(getEvalStore(), store, Realise::Outputs, installables, bmNormal); for (auto & installable : installables) { - if (auto installable2 = std::dynamic_pointer_cast(installable)) { - auto [attrPath, resolvedRef, drv] = installable2->toDerivation(); + ProfileElement element; - ProfileElement element; - if (!drv.outPath) - throw UnimplementedError("CA derivations are not yet supported by 'nix profile'"); - element.storePaths = {*drv.outPath}; // FIXME + if (auto installable2 = std::dynamic_pointer_cast(installable)) { + // FIXME: make build() return this? + auto [attrPath, resolvedRef, drv] = installable2->toDerivation(); element.source = ProfileElementSource{ installable2->flakeRef, resolvedRef, attrPath, }; - - pathsToBuild.push_back(DerivedPath::Built{drv.drvPath, StringSet{drv.outputName}}); - - manifest.elements.emplace_back(std::move(element)); - } else { - auto buildables = Installable::build(getEvalStore(), store, Realise::Outputs, {installable}, bmNormal); - - for (auto & buildable : buildables) { - ProfileElement element; - - std::visit(overloaded { - [&](const BuiltPath::Opaque & bo) { - pathsToBuild.push_back(bo); - element.storePaths.insert(bo.path); - }, - [&](const BuiltPath::Built & bfd) { - // TODO: Why are we querying if we know the output - // names already? Is it just to figure out what the - // default one is? - for (auto & output : store->queryDerivationOutputMap(bfd.drvPath)) { - pathsToBuild.push_back(DerivedPath::Built{bfd.drvPath, {output.first}}); - element.storePaths.insert(output.second); - } - }, - }, buildable.raw()); - - manifest.elements.emplace_back(std::move(element)); - } } - } - store->buildPaths(pathsToBuild); + element.updateStorePaths(getEvalStore(), store, *installable); + + manifest.elements.push_back(std::move(element)); + } updateProfile(manifest.build(store)); } @@ -407,8 +400,8 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf auto matchers = getMatchers(store); - // FIXME: code duplication - std::vector pathsToBuild; + std::vector> installables; + std::vector indices; auto upgradedCount = 0; @@ -423,32 +416,30 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf Activity act(*logger, lvlChatty, actUnknown, fmt("checking '%s' for updates", element.source->attrPath)); - InstallableFlake installable( + auto installable = std::make_shared( this, getEvalState(), FlakeRef(element.source->originalRef), "", - {element.source->attrPath}, - {}, + Strings{element.source->attrPath}, + Strings{}, lockFlags); - auto [attrPath, resolvedRef, drv] = installable.toDerivation(); + auto [attrPath, resolvedRef, drv] = installable->toDerivation(); if (element.source->resolvedRef == resolvedRef) continue; printInfo("upgrading '%s' from flake '%s' to '%s'", element.source->attrPath, element.source->resolvedRef, resolvedRef); - if (!drv.outPath) - throw UnimplementedError("CA derivations are not yet supported by 'nix profile'"); - element.storePaths = {*drv.outPath}; // FIXME element.source = ProfileElementSource{ - installable.flakeRef, + installable->flakeRef, resolvedRef, attrPath, }; - pathsToBuild.push_back(DerivedPath::Built{drv.drvPath, {drv.outputName}}); + installables.push_back(installable); + indices.push_back(i); } } @@ -465,7 +456,13 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf warn ("Use 'nix profile list' to see the current profile."); } - store->buildPaths(pathsToBuild); + auto builtPaths = Installable::build(getEvalStore(), store, Realise::Outputs, installables, bmNormal); + + for (size_t i = 0; i < installables.size(); ++i) { + auto & installable = installables.at(i); + auto & element = manifest.elements[indices.at(i)]; + element.updateStorePaths(getEvalStore(), store, *installable); + } updateProfile(manifest.build(store)); } diff --git a/tests/nix-profile.sh b/tests/nix-profile.sh index f134d70a4..0ab69db22 100644 --- a/tests/nix-profile.sh +++ b/tests/nix-profile.sh @@ -22,7 +22,11 @@ cat > $flake1Dir/flake.nix < $flake1Dir/who printf 1.0 > $flake1Dir/version +printf false > $flake1Dir/ca.nix cp ./config.nix $flake1Dir/ @@ -66,3 +71,17 @@ nix profile diff-closures | grep 'Version 3 -> 4' # Test wipe-history. nix profile wipe-history [[ $(nix profile history | grep Version | wc -l) -eq 1 ]] + +# Test upgrade to CA package. +printf true > $flake1Dir/ca.nix +printf 3.0 > $flake1Dir/version +nix profile upgrade --extra-experimental-features ca-derivations 0 +nix profile history | grep "packages.$system.default: 1.0 -> 3.0" + +# Test new install of CA package. +nix profile remove 0 +printf 4.0 > $flake1Dir/version +printf Utrecht > $flake1Dir/who +nix profile install --extra-experimental-features ca-derivations $flake1Dir +[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello Utrecht" ]] +[[ $(nix path-info --json $(realpath $TEST_HOME/.nix-profile/bin/hello) | jq -r .[].ca) =~ fixed:r:sha256: ]] From f9375778aedf365436de8200a97c0c292df65ea3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Mar 2022 20:56:40 +0100 Subject: [PATCH 3/8] nix profile: Add a test for non-flake packages --- tests/nix-profile.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/nix-profile.sh b/tests/nix-profile.sh index 0ab69db22..549840767 100644 --- a/tests/nix-profile.sh +++ b/tests/nix-profile.sh @@ -13,7 +13,7 @@ cat > $flake1Dir/flake.nix < ∅' nix profile diff-closures | grep 'Version 3 -> 4' +# Test installing a non-flake package. +nix profile install --file ./simple.nix '' +[[ $(cat $TEST_HOME/.nix-profile/hello) = "Hello World!" ]] +nix profile remove 1 +nix profile install $(nix-build --no-out-link ./simple.nix) +[[ $(cat $TEST_HOME/.nix-profile/hello) = "Hello World!" ]] + # Test wipe-history. nix profile wipe-history [[ $(nix profile history | grep Version | wc -l) -eq 1 ]] From 5d208cbe416ed38693cd33643731fd001135a582 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Mar 2022 21:36:46 +0100 Subject: [PATCH 4/8] mk/run_test.sh: Add missing backslash --- mk/run_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mk/run_test.sh b/mk/run_test.sh index b876859f8..7e95df2ac 100755 --- a/mk/run_test.sh +++ b/mk/run_test.sh @@ -28,7 +28,7 @@ run_test "$1" # See https://github.com/NixOS/nix/issues/3605 for more info if [[ $status -ne 0 && $status -ne 99 && \ "$(uname)" == "Darwin" && \ - "$log" =~ "unexpected EOF reading a line" + "$log" =~ "unexpected EOF reading a line" \ ]]; then echo "$post_run_msg [${yellow}FAIL$normal] (possibly flaky, so will be retried)" echo "$log" | sed 's/^/ /' From d2586188fe8745c34e5a97032d045f8b74100a98 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Mar 2022 21:48:25 +0100 Subject: [PATCH 5/8] tests/common.sh.in: Add enableFeatures helper --- tests/build-remote-content-addressed-floating.sh | 2 +- tests/ca/build.sh | 2 +- tests/ca/common.sh | 2 +- tests/ca/duplicate-realisation-in-closure.sh | 2 -- tests/ca/nix-copy.sh | 3 --- tests/ca/nix-run.sh | 2 -- tests/ca/nix-shell.sh | 2 -- tests/ca/post-hook.sh | 2 -- tests/ca/recursive.sh | 2 -- tests/ca/signatures.sh | 3 --- tests/common.sh.in | 7 ++++++- tests/nix-profile.sh | 6 ++++-- 12 files changed, 13 insertions(+), 22 deletions(-) diff --git a/tests/build-remote-content-addressed-floating.sh b/tests/build-remote-content-addressed-floating.sh index 13ef47d2d..1f474dde0 100644 --- a/tests/build-remote-content-addressed-floating.sh +++ b/tests/build-remote-content-addressed-floating.sh @@ -2,7 +2,7 @@ source common.sh file=build-hook-ca-floating.nix -sed -i 's/experimental-features .*/& ca-derivations/' "$NIX_CONF_DIR"/nix.conf +enableFeatures "ca-derivations ca-references" CONTENT_ADDRESSED=true diff --git a/tests/ca/build.sh b/tests/ca/build.sh index c8877f87f..92f8b429a 100644 --- a/tests/ca/build.sh +++ b/tests/ca/build.sh @@ -37,7 +37,7 @@ testCutoffFor () { } testCutoff () { - # Don't directly build depenentCA, that way we'll make sure we dodn't rely on + # Don't directly build dependentCA, that way we'll make sure we don't rely on # dependent derivations always being already built. #testDerivation dependentCA testCutoffFor transitivelyDependentCA diff --git a/tests/ca/common.sh b/tests/ca/common.sh index c5aa34334..b9d415863 100644 --- a/tests/ca/common.sh +++ b/tests/ca/common.sh @@ -1,5 +1,5 @@ source ../common.sh -sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf +enableFeatures "ca-derivations ca-references" restartDaemon diff --git a/tests/ca/duplicate-realisation-in-closure.sh b/tests/ca/duplicate-realisation-in-closure.sh index 74c5d25fd..da9cd8fb4 100644 --- a/tests/ca/duplicate-realisation-in-closure.sh +++ b/tests/ca/duplicate-realisation-in-closure.sh @@ -2,8 +2,6 @@ source ./common.sh requireDaemonNewerThan "2.4pre20210625" -sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf - export REMOTE_STORE_DIR="$TEST_ROOT/remote_store" export REMOTE_STORE="file://$REMOTE_STORE_DIR" diff --git a/tests/ca/nix-copy.sh b/tests/ca/nix-copy.sh index 2e0dea2d2..7a8307a4e 100755 --- a/tests/ca/nix-copy.sh +++ b/tests/ca/nix-copy.sh @@ -2,9 +2,6 @@ source common.sh -# Globally enable the ca derivations experimental flag -sed -i 's/experimental-features = .*/& ca-derivations ca-references/' "$NIX_CONF_DIR/nix.conf" - export REMOTE_STORE_DIR="$TEST_ROOT/remote_store" export REMOTE_STORE="file://$REMOTE_STORE_DIR" diff --git a/tests/ca/nix-run.sh b/tests/ca/nix-run.sh index 81402af10..5f46518e8 100755 --- a/tests/ca/nix-run.sh +++ b/tests/ca/nix-run.sh @@ -2,8 +2,6 @@ source common.sh -sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf - FLAKE_PATH=path:$PWD nix run --no-write-lock-file $FLAKE_PATH#runnable diff --git a/tests/ca/nix-shell.sh b/tests/ca/nix-shell.sh index 7f1a3a73e..1c5a6639f 100755 --- a/tests/ca/nix-shell.sh +++ b/tests/ca/nix-shell.sh @@ -2,8 +2,6 @@ source common.sh -sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf - CONTENT_ADDRESSED=true cd .. source ./nix-shell.sh diff --git a/tests/ca/post-hook.sh b/tests/ca/post-hook.sh index 1c9d4f700..705bde9d4 100755 --- a/tests/ca/post-hook.sh +++ b/tests/ca/post-hook.sh @@ -4,8 +4,6 @@ source common.sh requireDaemonNewerThan "2.4pre20210626" -sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf - export NIX_TESTS_CA_BY_DEFAULT=1 cd .. source ./post-hook.sh diff --git a/tests/ca/recursive.sh b/tests/ca/recursive.sh index 648bf0a91..0354d23b4 100755 --- a/tests/ca/recursive.sh +++ b/tests/ca/recursive.sh @@ -4,8 +4,6 @@ source common.sh requireDaemonNewerThan "2.4pre20210623" -sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf - export NIX_TESTS_CA_BY_DEFAULT=1 cd .. source ./recursive.sh diff --git a/tests/ca/signatures.sh b/tests/ca/signatures.sh index 0c7d974ea..eb18a4130 100644 --- a/tests/ca/signatures.sh +++ b/tests/ca/signatures.sh @@ -1,8 +1,5 @@ source common.sh -# Globally enable the ca derivations experimental flag -sed -i 's/experimental-features = .*/& ca-derivations ca-references/' "$NIX_CONF_DIR/nix.conf" - clearStore clearCache diff --git a/tests/common.sh.in b/tests/common.sh.in index e485329ba..d12aebdad 100644 --- a/tests/common.sh.in +++ b/tests/common.sh.in @@ -173,10 +173,15 @@ needLocalStore() { } # Just to make it easy to find which tests should be fixed -buggyNeedLocalStore () { +buggyNeedLocalStore() { needLocalStore } +enableFeatures() { + local features="$1" + sed -i 's/experimental-features .*/& '"$features"'/' "$NIX_CONF_DIR"/nix.conf +} + set -x if [[ -n "${NIX_DAEMON_PACKAGE:-}" ]]; then diff --git a/tests/nix-profile.sh b/tests/nix-profile.sh index 549840767..be80e089a 100644 --- a/tests/nix-profile.sh +++ b/tests/nix-profile.sh @@ -3,6 +3,8 @@ source common.sh clearStore clearProfiles +enableFeatures "ca-derivations ca-references" + # Make a flake. flake1Dir=$TEST_ROOT/flake1 mkdir -p $flake1Dir @@ -82,13 +84,13 @@ nix profile wipe-history # Test upgrade to CA package. printf true > $flake1Dir/ca.nix printf 3.0 > $flake1Dir/version -nix profile upgrade --extra-experimental-features ca-derivations 0 +nix profile upgrade 0 nix profile history | grep "packages.$system.default: 1.0 -> 3.0" # Test new install of CA package. nix profile remove 0 printf 4.0 > $flake1Dir/version printf Utrecht > $flake1Dir/who -nix profile install --extra-experimental-features ca-derivations $flake1Dir +nix profile install $flake1Dir [[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello Utrecht" ]] [[ $(nix path-info --json $(realpath $TEST_HOME/.nix-profile/bin/hello) | jq -r .[].ca) =~ fixed:r:sha256: ]] From b0d65b3d11496b81ed00616ce5d8e4db1229bb8c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Mar 2022 22:22:23 +0100 Subject: [PATCH 6/8] Silence kill output --- tests/common.sh.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/common.sh.in b/tests/common.sh.in index d12aebdad..b341993f7 100644 --- a/tests/common.sh.in +++ b/tests/common.sh.in @@ -109,10 +109,10 @@ startDaemon() { killDaemon() { kill $pidDaemon for i in {0..100}; do - kill -0 $pidDaemon || break + kill -0 $pidDaemon 2> /dev/null || break sleep 0.1 done - kill -9 $pidDaemon || true + kill -9 $pidDaemon 2> /dev/null || true wait $pidDaemon || true trap "" EXIT } From 3a3821bcd7c71e27ad1f6861e0d37d322f721b2b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Mar 2022 22:22:55 +0100 Subject: [PATCH 7/8] Remove obsolete todo --- tests/common.sh.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/common.sh.in b/tests/common.sh.in index b341993f7..8ce28d318 100644 --- a/tests/common.sh.in +++ b/tests/common.sh.in @@ -87,8 +87,7 @@ startDaemon() { if [[ "$NIX_REMOTE" == daemon ]]; then return fi - # Start the daemon, wait for the socket to appear. !!! - # ‘nix-daemon’ should have an option to fork into the background. + # Start the daemon, wait for the socket to appear. rm -f $NIX_DAEMON_SOCKET_PATH PATH=$DAEMON_PATH nix-daemon& pidDaemon=$! From d4538034b7fba772a5f87c2efa66dbbd76760142 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Mar 2022 23:08:49 +0100 Subject: [PATCH 8/8] nix profile test: Restart daemon Fixes nix-daemon: src/libstore/sqlite.cc:97: nix::SQLiteStmt::Use::Use(nix::SQLiteStmt&): Assertion `stmt.stmt' failed. which happens because the daemon doesn't properly handle the case where ca-derivations isn't enabled at daemon startup. --- tests/nix-profile.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/nix-profile.sh b/tests/nix-profile.sh index be80e089a..a7a4d4fa2 100644 --- a/tests/nix-profile.sh +++ b/tests/nix-profile.sh @@ -4,6 +4,7 @@ clearStore clearProfiles enableFeatures "ca-derivations ca-references" +restartDaemon # Make a flake. flake1Dir=$TEST_ROOT/flake1