From af99941279b80c962ec9cae3e5fa32976a3f5744 Mon Sep 17 00:00:00 2001 From: regnat Date: Mon, 25 Oct 2021 15:53:01 +0200 Subject: Make experimental-features a proper type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rather than having them plain strings scattered through the whole codebase, create an enum containing all the known experimental features. This means that - Nix can now `warn` when an unkwown experimental feature is passed (making it much nicer to spot typos and spot deprecated features) - It’s now easy to remove a feature altogether (once the feature isn’t experimental anymore or is dropped) by just removing the field for the enum and letting the compiler point us to all the now invalid usages of it. --- src/libcmd/installables.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcmd') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 0f0fcf39e..5758b52ad 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -714,7 +714,7 @@ BuiltPaths getBuiltPaths(ref evalStore, ref store, const DerivedPa "the derivation '%s' doesn't have an output named '%s'", store->printStorePath(bfd.drvPath), output); if (settings.isExperimentalFeatureEnabled( - "ca-derivations")) { + Xp::CaDerivations)) { auto outputId = DrvOutput{outputHashes.at(output), output}; auto realisation = -- cgit v1.2.3 From 3a0277305a5d86f29e5bdc1c425c45e4bd7dbe71 Mon Sep 17 00:00:00 2001 From: regnat Date: Fri, 26 Nov 2021 16:56:25 +0100 Subject: =?UTF-8?q?Don=E2=80=99t=20try=20to=20complete=20flakes=20is=20the?= =?UTF-8?q?=20feature=20isn=E2=80=99t=20enabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #5661 --- src/libcmd/installables.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/libcmd') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 5758b52ad..ef200b1d2 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -291,6 +291,9 @@ void completeFlakeRefWithFragment( void completeFlakeRef(ref store, std::string_view prefix) { + if (!settings.isExperimentalFeatureEnabled(Xp::Flakes)) + return; + if (prefix == "") completions->add("."); -- cgit v1.2.3 From 33e96820d52dcfea387214f84ff2271959b3467b Mon Sep 17 00:00:00 2001 From: Yorick van Pelt Date: Sat, 11 Dec 2021 16:02:08 +0100 Subject: EvalCommand::getEvalState: use gc tracable allocator for EvalState --- src/libcmd/command.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/libcmd') diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index fd3edfc46..429cd32cc 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -73,8 +73,13 @@ ref EvalCommand::getEvalStore() ref EvalCommand::getEvalState() { - if (!evalState) - evalState = std::make_shared(searchPath, getEvalStore(), getStore()); + if (!evalState) evalState = +#if HAVE_BOEHMGC + std::allocate_shared(traceable_allocator(), +#else + std::make_shared( +#endif + searchPath, getEvalStore(), getStore()); return ref(evalState); } -- cgit v1.2.3 From 1da1b2b345ccf32220a2628622ee8b170d9d521a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Wed, 22 Dec 2021 12:37:59 +0100 Subject: Don't insert spaces when completing attribute paths --- src/libcmd/installables.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/libcmd') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index ef200b1d2..5f118b8d0 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -203,6 +203,8 @@ void SourceExprCommand::completeInstallable(std::string_view prefix) Value v2; state->autoCallFunction(*autoArgs, v1, v2); + completionType = ctAttrs; + if (v2.type() == nAttrs) { for (auto & i : *v2.attrs) { std::string name = i.name; @@ -232,7 +234,9 @@ void completeFlakeRefWithFragment( prefix. */ try { auto hash = prefix.find('#'); - if (hash != std::string::npos) { + if (hash == std::string::npos) { + completeFlakeRef(evalState->store, prefix); + } else { auto fragment = prefix.substr(hash + 1); auto flakeRefS = std::string(prefix.substr(0, hash)); // FIXME: do tilde expansion. @@ -248,6 +252,8 @@ void completeFlakeRefWithFragment( flake. */ attrPathPrefixes.push_back(""); + completionType = ctAttrs; + for (auto & attrPathPrefixS : attrPathPrefixes) { auto attrPathPrefix = parseAttrPath(*evalState, attrPathPrefixS); auto attrPathS = attrPathPrefixS + std::string(fragment); @@ -285,8 +291,6 @@ void completeFlakeRefWithFragment( } catch (Error & e) { warn(e.msg()); } - - completeFlakeRef(evalState->store, prefix); } void completeFlakeRef(ref store, std::string_view prefix) -- cgit v1.2.3 From c4a03bc4ae7ac89dfca3ada27d1a7946d568d4d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Wed, 22 Dec 2021 16:37:58 +0100 Subject: Fix attr path completion after a dot --- src/libcmd/installables.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcmd') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 5f118b8d0..6c20bb7b1 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -191,7 +191,7 @@ void SourceExprCommand::completeInstallable(std::string_view prefix) auto sep = prefix_.rfind('.'); std::string searchWord; if (sep != std::string::npos) { - searchWord = prefix_.substr(sep, std::string::npos); + searchWord = prefix_.substr(sep + 1, std::string::npos); prefix_ = prefix_.substr(0, sep); } else { searchWord = prefix_; -- cgit v1.2.3 From 6448ea84ab537600d3f350867063bc305b3bb910 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 17 Jan 2022 13:58:26 +0100 Subject: Factor out --from / --to logic --- src/libcmd/command.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++------- src/libcmd/command.hh | 17 ++++++++++++++++ 2 files changed, 64 insertions(+), 7 deletions(-) (limited to 'src/libcmd') diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 429cd32cc..5e6d4a857 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -73,13 +73,16 @@ ref EvalCommand::getEvalStore() ref EvalCommand::getEvalState() { - if (!evalState) evalState = -#if HAVE_BOEHMGC - std::allocate_shared(traceable_allocator(), -#else - std::make_shared( -#endif - searchPath, getEvalStore(), getStore()); + if (!evalState) + evalState = + #if HAVE_BOEHMGC + std::allocate_shared(traceable_allocator(), + searchPath, getEvalStore(), getStore()) + #else + std::make_shared( + searchPath, getEvalStore(), getStore()) + #endif + ; return ref(evalState); } @@ -156,6 +159,43 @@ void StorePathsCommand::run(ref store, BuiltPaths && paths) run(store, std::move(sorted)); } +CopyCommand::CopyCommand() + : BuiltPathsCommand(true) +{ + addFlag({ + .longName = "from", + .description = "URL of the source Nix store.", + .labels = {"store-uri"}, + .handler = {&srcUri}, + }); + + addFlag({ + .longName = "to", + .description = "URL of the destination Nix store.", + .labels = {"store-uri"}, + .handler = {&dstUri}, + }); +} + +ref CopyCommand::createStore() +{ + return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri); +} + +void CopyCommand::run(ref store) +{ + if (srcUri.empty() && dstUri.empty()) + throw UsageError("you must pass '--from' and/or '--to'"); + + BuiltPathsCommand::run(store); +} + +void CopyCommand::run(ref srcStore, BuiltPaths && paths) +{ + ref dstStore = dstUri.empty() ? openStore() : openStore(dstUri); + run(srcStore, dstStore, std::move(paths)); +} + void StorePathCommand::run(ref store, std::vector && storePaths) { if (storePaths.size() != 1) diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh index 07f398468..0c3e29e25 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -176,6 +176,23 @@ public: bool useDefaultInstallables() override { return !all; } }; +/* A command that copies something between `--from` and `--to` + stores. */ +struct CopyCommand : virtual BuiltPathsCommand +{ + std::string srcUri, dstUri; + + CopyCommand(); + + ref createStore() override; + + void run(ref store) override; + + void run(ref srcStore, BuiltPaths && paths) override; + + virtual void run(ref srcStore, ref dstStore, BuiltPaths && paths) = 0; +}; + struct StorePathsCommand : public BuiltPathsCommand { StorePathsCommand(bool recursive = false); -- cgit v1.2.3 From 4dda1f92aae05dd9d633152458d65a3815bcd03c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 17 Jan 2022 19:45:21 +0100 Subject: Add command 'nix store copy-log' Fixes #5222. --- src/libcmd/command.cc | 67 +++++++++++++++++++++++---------------------------- src/libcmd/command.hh | 30 ++++++++++------------- 2 files changed, 43 insertions(+), 54 deletions(-) (limited to 'src/libcmd') diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 5e6d4a857..6d183dfad 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -54,6 +54,36 @@ void StoreCommand::run() run(getStore()); } +CopyCommand::CopyCommand() +{ + addFlag({ + .longName = "from", + .description = "URL of the source Nix store.", + .labels = {"store-uri"}, + .handler = {&srcUri}, + }); + + addFlag({ + .longName = "to", + .description = "URL of the destination Nix store.", + .labels = {"store-uri"}, + .handler = {&dstUri}, + }); +} + +ref CopyCommand::createStore() +{ + return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri); +} + +ref CopyCommand::getDstStore() +{ + if (srcUri.empty() && dstUri.empty()) + throw UsageError("you must pass '--from' and/or '--to'"); + + return dstUri.empty() ? openStore() : openStore(dstUri); +} + EvalCommand::EvalCommand() { } @@ -159,43 +189,6 @@ void StorePathsCommand::run(ref store, BuiltPaths && paths) run(store, std::move(sorted)); } -CopyCommand::CopyCommand() - : BuiltPathsCommand(true) -{ - addFlag({ - .longName = "from", - .description = "URL of the source Nix store.", - .labels = {"store-uri"}, - .handler = {&srcUri}, - }); - - addFlag({ - .longName = "to", - .description = "URL of the destination Nix store.", - .labels = {"store-uri"}, - .handler = {&dstUri}, - }); -} - -ref CopyCommand::createStore() -{ - return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri); -} - -void CopyCommand::run(ref store) -{ - if (srcUri.empty() && dstUri.empty()) - throw UsageError("you must pass '--from' and/or '--to'"); - - BuiltPathsCommand::run(store); -} - -void CopyCommand::run(ref srcStore, BuiltPaths && paths) -{ - ref dstStore = dstUri.empty() ? openStore() : openStore(dstUri); - run(srcStore, dstStore, std::move(paths)); -} - void StorePathCommand::run(ref store, std::vector && storePaths) { if (storePaths.size() != 1) diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh index 0c3e29e25..bd2a0a7ee 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -43,6 +43,19 @@ private: std::shared_ptr _store; }; +/* A command that copies something between `--from` and `--to` + stores. */ +struct CopyCommand : virtual StoreCommand +{ + std::string srcUri, dstUri; + + CopyCommand(); + + ref createStore() override; + + ref getDstStore(); +}; + struct EvalCommand : virtual StoreCommand, MixEvalArgs { EvalCommand(); @@ -176,23 +189,6 @@ public: bool useDefaultInstallables() override { return !all; } }; -/* A command that copies something between `--from` and `--to` - stores. */ -struct CopyCommand : virtual BuiltPathsCommand -{ - std::string srcUri, dstUri; - - CopyCommand(); - - ref createStore() override; - - void run(ref store) override; - - void run(ref srcStore, BuiltPaths && paths) override; - - virtual void run(ref srcStore, ref dstStore, BuiltPaths && paths) = 0; -}; - struct StorePathsCommand : public BuiltPathsCommand { StorePathsCommand(bool recursive = false); -- cgit v1.2.3 From 3876238546c82e4cda4f257b9b1e3e6d53d07658 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 18 Jan 2022 17:28:18 +0100 Subject: Add Installable::toDrvPaths() This is needed to get the path of a derivation that might not exist (e.g. for 'nix store copy-log'). InstallableStorePath::toDerivedPaths() cannot be used for this because it calls readDerivation(), so it fails if the store doesn't have the derivation. --- src/libcmd/installables.cc | 39 ++++++++++++++++++++++++++++++++------- src/libcmd/installables.hh | 11 +++++++++-- 2 files changed, 41 insertions(+), 9 deletions(-) (limited to 'src/libcmd') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 6c20bb7b1..0c2db0399 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -345,6 +345,18 @@ Installable::getCursor(EvalState & state) return cursors[0]; } +static StorePath getDeriver( + ref store, + const Installable & i, + const StorePath & drvPath) +{ + auto derivers = store->queryValidDerivers(drvPath); + if (derivers.empty()) + throw Error("'%s' does not have a known deriver", i.what()); + // FIXME: use all derivers? + return *derivers.begin(); +} + struct InstallableStorePath : Installable { ref store; @@ -353,7 +365,7 @@ struct InstallableStorePath : Installable InstallableStorePath(ref store, StorePath && storePath) : store(store), storePath(std::move(storePath)) { } - std::string what() override { return store->printStorePath(storePath); } + std::string what() const override { return store->printStorePath(storePath); } DerivedPaths toDerivedPaths() override { @@ -374,6 +386,15 @@ struct InstallableStorePath : Installable } } + StorePathSet toDrvPaths(ref store) override + { + if (storePath.isDerivation()) { + return {storePath}; + } else { + return {getDeriver(store, *this, storePath)}; + } + } + std::optional getStorePath() override { return storePath; @@ -402,6 +423,14 @@ DerivedPaths InstallableValue::toDerivedPaths() return res; } +StorePathSet InstallableValue::toDrvPaths(ref store) +{ + StorePathSet res; + for (auto & drv : toDerivations()) + res.insert(drv.drvPath); + return res; +} + struct InstallableAttrPath : InstallableValue { SourceExprCommand & cmd; @@ -412,7 +441,7 @@ struct InstallableAttrPath : InstallableValue : InstallableValue(state), cmd(cmd), v(allocRootValue(v)), attrPath(attrPath) { } - std::string what() override { return attrPath; } + std::string what() const override { return attrPath; } std::pair toValue(EvalState & state) override { @@ -836,11 +865,7 @@ StorePathSet toDerivations( [&](const DerivedPath::Opaque & bo) { if (!useDeriver) throw Error("argument '%s' did not evaluate to a derivation", i->what()); - auto derivers = store->queryValidDerivers(bo.path); - if (derivers.empty()) - throw Error("'%s' does not have a known deriver", i->what()); - // FIXME: use all derivers? - drvPaths.insert(*derivers.begin()); + drvPaths.insert(getDeriver(store, *i, bo.path)); }, [&](const DerivedPath::Built & bfd) { drvPaths.insert(bfd.drvPath); diff --git a/src/libcmd/installables.hh b/src/libcmd/installables.hh index 79931ad3e..ced6b3f10 100644 --- a/src/libcmd/installables.hh +++ b/src/libcmd/installables.hh @@ -33,10 +33,15 @@ struct Installable { virtual ~Installable() { } - virtual std::string what() = 0; + virtual std::string what() const = 0; virtual DerivedPaths toDerivedPaths() = 0; + virtual StorePathSet toDrvPaths(ref store) + { + throw Error("'%s' cannot be converted to a derivation path", what()); + } + DerivedPath toDerivedPath(); UnresolvedApp toApp(EvalState & state); @@ -81,6 +86,8 @@ struct InstallableValue : Installable virtual std::vector toDerivations() = 0; DerivedPaths toDerivedPaths() override; + + StorePathSet toDrvPaths(ref store) override; }; struct InstallableFlake : InstallableValue @@ -99,7 +106,7 @@ struct InstallableFlake : InstallableValue Strings && prefixes, const flake::LockFlags & lockFlags); - std::string what() override { return flakeRef.to_string() + "#" + *attrPaths.begin(); } + std::string what() const override { return flakeRef.to_string() + "#" + *attrPaths.begin(); } std::vector getActualAttrPaths(); -- cgit v1.2.3 From 49b0bb020663b7283549754a826b1346c93a8bbb Mon Sep 17 00:00:00 2001 From: Kevin Amado Date: Sat, 27 Nov 2021 12:40:24 -0500 Subject: forceValue: make pos mandatory - Make passing the position to `forceValue` mandatory, this way we remember people that the position is important for better error messages - Add pos to all `forceValue` calls --- src/libcmd/installables.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/libcmd') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 0c2db0399..268861ce8 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -198,8 +198,9 @@ void SourceExprCommand::completeInstallable(std::string_view prefix) prefix_ = ""; } - Value &v1(*findAlongAttrPath(*state, prefix_, *autoArgs, root).first); - state->forceValue(v1); + auto [v, pos] = findAlongAttrPath(*state, prefix_, *autoArgs, root); + Value &v1(*v); + state->forceValue(v1, pos); Value v2; state->autoCallFunction(*autoArgs, v1, v2); @@ -446,7 +447,7 @@ struct InstallableAttrPath : InstallableValue std::pair toValue(EvalState & state) override { auto [vRes, pos] = findAlongAttrPath(state, attrPath, *cmd.getAutoArgs(state), **v); - state.forceValue(*vRes); + state.forceValue(*vRes, pos); return {vRes, pos}; } @@ -496,7 +497,7 @@ Value * InstallableFlake::getFlakeOutputs(EvalState & state, const flake::Locked auto aOutputs = vFlake->attrs->get(state.symbols.create("outputs")); assert(aOutputs); - state.forceValue(*aOutputs->value); + state.forceValue(*aOutputs->value, aOutputs->value->determinePos(noPos)); return aOutputs->value; } @@ -608,7 +609,7 @@ std::pair InstallableFlake::toValue(EvalState & state) for (auto & attrPath : getActualAttrPaths()) { try { auto [v, pos] = findAlongAttrPath(state, attrPath, *emptyArgs, *vOutputs); - state.forceValue(*v); + state.forceValue(*v, pos); return {v, pos}; } catch (AttrPathNotFound & e) { } -- cgit v1.2.3 From c3896e19d0001b4f729017aa96d0a44b6e479a52 Mon Sep 17 00:00:00 2001 From: Kevin Amado Date: Fri, 21 Jan 2022 10:43:16 -0500 Subject: forceAttrs: make pos mandatory --- src/libcmd/installables.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcmd') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 268861ce8..ec4f8f6f9 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -522,7 +522,7 @@ ref openEvalCache( auto vFlake = state.allocValue(); flake::callFlake(state, *lockedFlake, *vFlake); - state.forceAttrs(*vFlake); + state.forceAttrs(*vFlake, noPos); auto aOutputs = vFlake->attrs->get(state.symbols.create("outputs")); assert(aOutputs); -- cgit v1.2.3 From 43509cc69d24d3b8def894a2d47338b7873dc0f4 Mon Sep 17 00:00:00 2001 From: Thomas Koch Date: Sun, 30 Jan 2022 20:59:58 +0200 Subject: use LOWDOWN_LIBS variable fixes: #5931 --- src/libcmd/local.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcmd') diff --git a/src/libcmd/local.mk b/src/libcmd/local.mk index 8b0662753..7a2f83cc7 100644 --- a/src/libcmd/local.mk +++ b/src/libcmd/local.mk @@ -8,7 +8,7 @@ libcmd_SOURCES := $(wildcard $(d)/*.cc) libcmd_CXXFLAGS += -I src/libutil -I src/libstore -I src/libexpr -I src/libmain -I src/libfetchers -libcmd_LDFLAGS += -llowdown -pthread +libcmd_LDFLAGS += $(LOWDOWN_LIBS) -pthread libcmd_LIBS = libstore libutil libexpr libmain libfetchers -- cgit v1.2.3 From bd383d1b6f91c4fe7ac21c52771e92027f649fa0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 4 Feb 2022 00:31:33 +0100 Subject: Make most calls to determinePos() lazy --- src/libcmd/installables.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcmd') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index ec4f8f6f9..38a177f80 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -497,7 +497,7 @@ Value * InstallableFlake::getFlakeOutputs(EvalState & state, const flake::Locked auto aOutputs = vFlake->attrs->get(state.symbols.create("outputs")); assert(aOutputs); - state.forceValue(*aOutputs->value, aOutputs->value->determinePos(noPos)); + state.forceValue(*aOutputs->value, [&]() { return aOutputs->value->determinePos(noPos); }); return aOutputs->value; } -- cgit v1.2.3 From f222fba4dca69919d28468467e6e5c4c859cfc13 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Thu, 3 Feb 2022 20:51:47 -0600 Subject: Allow missing flake.nix for --override-input target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At this point, we don’t know if the input is a flake or not. So, we should allow the user to override the input with a directory without a flake.nix. Ideally, we could figure whether the input was originally a flake or not, but that would require instantiating the whole flake. So just allow it to be missing here, and rely on checks later on to verify the input for us. --- src/libcmd/installables.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcmd') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 38a177f80..5e8b62e1a 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -97,7 +97,7 @@ MixFlakeOptions::MixFlakeOptions() lockFlags.writeLockFile = false; lockFlags.inputOverrides.insert_or_assign( flake::parseInputPath(inputPath), - parseFlakeRef(flakeRef, absPath("."))); + parseFlakeRef(flakeRef, absPath("."), true)); }} }); -- cgit v1.2.3 From cdc90c2776ee5542fd4d4e1aaa06d1d826daecb0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 11 Feb 2022 15:50:12 +0100 Subject: parseInstallables(): Don't try the flake attr path prefixes when no fragment is specified Fixes #5880. --- src/libcmd/installables.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcmd') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 5e8b62e1a..9f138b420 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -709,7 +709,7 @@ std::vector> SourceExprCommand::parseInstallables( getEvalState(), std::move(flakeRef), fragment == "" ? getDefaultFlakeAttrPaths() : Strings{fragment}, - getDefaultFlakeAttrPathPrefixes(), + fragment == "" ? Strings{} : getDefaultFlakeAttrPathPrefixes(), lockFlags)); continue; } catch (...) { -- cgit v1.2.3 From 023e45977745ffd6c16eec299a00affd65176669 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 14 Feb 2022 20:39:44 +0100 Subject: InstallableFlake: Default attr paths cleanup This removes some duplicated logic, and fixes "nix bundle" parsing its installable twice. --- src/libcmd/installables.cc | 16 ++++++++++------ src/libcmd/installables.hh | 5 +++-- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src/libcmd') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 9f138b420..644954977 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -545,13 +545,14 @@ InstallableFlake::InstallableFlake( SourceExprCommand * cmd, ref state, FlakeRef && flakeRef, - Strings && attrPaths, - Strings && prefixes, + std::string_view fragment, + Strings attrPaths, + Strings prefixes, const flake::LockFlags & lockFlags) : InstallableValue(state), flakeRef(flakeRef), - attrPaths(attrPaths), - prefixes(prefixes), + attrPaths(fragment == "" ? attrPaths : Strings{(std::string) fragment}), + prefixes(fragment == "" ? Strings{} : prefixes), lockFlags(lockFlags) { if (cmd && cmd->getAutoArgs(*state)->size()) @@ -566,6 +567,8 @@ std::tuple InstallableF auto root = cache->getRoot(); for (auto & attrPath : getActualAttrPaths()) { + debug("trying flake output attribute '%s'", attrPath); + auto attr = root->findAlongAttrPath( parseAttrPath(*state, attrPath), true @@ -708,8 +711,9 @@ std::vector> SourceExprCommand::parseInstallables( this, getEvalState(), std::move(flakeRef), - fragment == "" ? getDefaultFlakeAttrPaths() : Strings{fragment}, - fragment == "" ? Strings{} : getDefaultFlakeAttrPathPrefixes(), + fragment, + getDefaultFlakeAttrPaths(), + getDefaultFlakeAttrPathPrefixes(), lockFlags)); continue; } catch (...) { diff --git a/src/libcmd/installables.hh b/src/libcmd/installables.hh index ced6b3f10..3d2563e4b 100644 --- a/src/libcmd/installables.hh +++ b/src/libcmd/installables.hh @@ -102,8 +102,9 @@ struct InstallableFlake : InstallableValue SourceExprCommand * cmd, ref state, FlakeRef && flakeRef, - Strings && attrPaths, - Strings && prefixes, + std::string_view fragment, + Strings attrPaths, + Strings prefixes, const flake::LockFlags & lockFlags); std::string what() const override { return flakeRef.to_string() + "#" + *attrPaths.begin(); } -- cgit v1.2.3 From 162fbe31ffe4c2b2d7648e5df2d5a0c9b4a44996 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 11 Feb 2022 18:11:08 +0100 Subject: Replace defaultBla.$system with bla.$system.default This also simplifies some InstallableFlake logic and fixes 'nix bundle' parsing its installable twice. Fixes #5532. --- src/libcmd/installables.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/libcmd') diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 644954977..c07e39628 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -158,7 +158,10 @@ SourceExprCommand::SourceExprCommand() Strings SourceExprCommand::getDefaultFlakeAttrPaths() { - return {"defaultPackage." + settings.thisSystem.get()}; + return { + "packages." + settings.thisSystem.get() + ".default", + "defaultPackage." + settings.thisSystem.get() + }; } Strings SourceExprCommand::getDefaultFlakeAttrPathPrefixes() -- cgit v1.2.3