From b6d794fb8df09b9b5d86f3fe2a2789631215f8b5 Mon Sep 17 00:00:00 2001 From: YI Date: Sun, 1 Mar 2020 16:11:22 +0800 Subject: [PATCH 1/6] display attr-path only when queried available --- doc/manual/command-ref/nix-env.xml | 3 ++- src/nix-env/nix-env.cc | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/manual/command-ref/nix-env.xml b/doc/manual/command-ref/nix-env.xml index d257a5e49..9c03ccce1 100644 --- a/doc/manual/command-ref/nix-env.xml +++ b/doc/manual/command-ref/nix-env.xml @@ -1066,7 +1066,8 @@ user environment elements, etc. --> the derivation, which can be used to unambiguously select it using the option available in commands that install derivations like - nix-env --install. + nix-env --install. This option only works + together with diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index a40d0c7e6..106dfe0b6 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -914,6 +914,8 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) throw UsageError(format("unknown flag '%1%'") % arg); } + if (printAttrPath && source != sAvailable) + throw UsageError("--attr-path(-P) only works with --available"); /* Obtain derivation information from the specified source. */ DrvInfos availElems, installedElems; From 59c37112a92b66663ac32a328f7b547f43bb2e72 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 13 Mar 2020 18:42:53 +0100 Subject: [PATCH 2/6] README.md: Remove reference to OpenSSL The OpenSSL files were removed in a6ca68a70c3bc0b2e6abad70346c99642a896f9f. https://salsa.debian.org/debian/nix/issues/3 --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index a953c0f71..61054f8f2 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,3 @@ of the manual. It helps you to get started with building Nix from source. ## License Nix is released under the LGPL v2.1 - -This product includes software developed by the OpenSSL Project for -use in the [OpenSSL Toolkit](https://www.OpenSSL.org/). From 68fe0d9809a269341901d95f33aebeacbed34afc Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 13 Mar 2020 21:24:35 -0400 Subject: [PATCH 3/6] Add missing `#include ` --- src/libexpr/eval.hh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index f3e8a34bd..eac53b894 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -7,6 +7,7 @@ #include "hash.hh" #include "config.hh" +#include #include #include #include From b244e65cdbc2949af70bd539bf8f3bd2fa952d07 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 19 Mar 2020 13:50:01 +0100 Subject: [PATCH 4/6] nix repl: Scan NixRepl for GC roots Fixes #3175. --- src/nix/repl.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nix/repl.cc b/src/nix/repl.cc index e6c811a7b..49418add2 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -32,6 +32,9 @@ extern "C" { #include "command.hh" #include "finally.hh" +#define GC_INCLUDE_NEW +#include + namespace nix { #define ESC_RED "\033[31m" @@ -42,7 +45,7 @@ namespace nix { #define ESC_CYA "\033[36m" #define ESC_END "\033[0m" -struct NixRepl +struct NixRepl : gc { string curDir; EvalState state; From ef74fafc0368944e6cfc3b804b4bcdddd6bcf9c0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 19 Mar 2020 13:52:28 +0100 Subject: [PATCH 5/6] nix repl: Put EvalState on the heap See 0629601da1d163a059fa19004256961f8ecdeb78. --- src/nix/repl.cc | 64 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 49418add2..27727bd25 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -48,7 +48,7 @@ namespace nix { struct NixRepl : gc { string curDir; - EvalState state; + std::unique_ptr state; Bindings * autoArgs; Strings loadedFiles; @@ -126,8 +126,8 @@ string removeWhitespace(string s) NixRepl::NixRepl(const Strings & searchPath, nix::ref store) - : state(searchPath, store) - , staticEnv(false, &state.staticBaseEnv) + : state(std::make_unique(searchPath, store)) + , staticEnv(false, &state->staticBaseEnv) , historyFile(getDataDir() + "/nix/repl-history") { curDir = absPath("."); @@ -356,8 +356,8 @@ StringSet NixRepl::completePrefix(string prefix) Expr * e = parseString(expr); Value v; - e->eval(state, *env, v); - state.forceAttrs(v); + e->eval(*state, *env, v); + state->forceAttrs(v); for (auto & i : *v.attrs) { string name = i.name; @@ -412,11 +412,11 @@ bool isVarName(const string & s) Path NixRepl::getDerivationPath(Value & v) { - auto drvInfo = getDerivation(state, v, false); + auto drvInfo = getDerivation(*state, v, false); if (!drvInfo) throw Error("expression does not evaluate to a derivation, so I can't build it"); Path drvPath = drvInfo->queryDrvPath(); - if (drvPath == "" || !state.store->isValidPath(state.store->parseStorePath(drvPath))) + if (drvPath == "" || !state->store->isValidPath(state->store->parseStorePath(drvPath))) throw Error("expression did not evaluate to a valid derivation"); return drvPath; } @@ -462,12 +462,12 @@ bool NixRepl::processLine(string line) } else if (command == ":l" || command == ":load") { - state.resetFileCache(); + state->resetFileCache(); loadFile(arg); } else if (command == ":r" || command == ":reload") { - state.resetFileCache(); + state->resetFileCache(); reloadFiles(); } @@ -479,13 +479,13 @@ bool NixRepl::processLine(string line) if (v.type == tPath || v.type == tString) { PathSet context; - auto filename = state.coerceToString(noPos, v, context); - pos.file = state.symbols.create(filename); + auto filename = state->coerceToString(noPos, v, context); + pos.file = state->symbols.create(filename); } else if (v.type == tLambda) { pos = v.lambda.fun->pos; } else { // assume it's a derivation - pos = findDerivationFilename(state, v, arg); + pos = findDerivationFilename(*state, v, arg); } // Open in EDITOR @@ -495,7 +495,7 @@ bool NixRepl::processLine(string line) runProgram(editor, args); // Reload right after exiting the editor - state.resetFileCache(); + state->resetFileCache(); reloadFiles(); } @@ -508,7 +508,7 @@ bool NixRepl::processLine(string line) Value v, f, result; evalString(arg, v); evalString("drv: (import {}).runCommand \"shell\" { buildInputs = [ drv ]; } \"\"", f); - state.callFunction(f, v, result, Pos()); + state->callFunction(f, v, result, Pos()); Path drvPath = getDerivationPath(result); runProgram(settings.nixBinDir + "/nix-shell", Strings{drvPath}); @@ -524,10 +524,10 @@ bool NixRepl::processLine(string line) but doing it in a child makes it easier to recover from problems / SIGINT. */ if (runProgram(settings.nixBinDir + "/nix", Strings{"build", "--no-link", drvPath}) == 0) { - auto drv = readDerivation(*state.store, drvPath); + auto drv = readDerivation(*state->store, drvPath); std::cout << std::endl << "this derivation produced the following outputs:" << std::endl; for (auto & i : drv.outputs) - std::cout << fmt(" %s -> %s\n", i.first, state.store->printStorePath(i.second.path)); + std::cout << fmt(" %s -> %s\n", i.first, state->store->printStorePath(i.second.path)); } } else if (command == ":i") { runProgram(settings.nixBinDir + "/nix-env", Strings{"-i", drvPath}); @@ -557,11 +557,11 @@ bool NixRepl::processLine(string line) isVarName(name = removeWhitespace(string(line, 0, p)))) { Expr * e = parseString(string(line, p + 1)); - Value & v(*state.allocValue()); + Value & v(*state->allocValue()); v.type = tThunk; v.thunk.env = env; v.thunk.expr = e; - addVarToScope(state.symbols.create(name), v); + addVarToScope(state->symbols.create(name), v); } else { Value v; evalString(line, v); @@ -578,21 +578,21 @@ void NixRepl::loadFile(const Path & path) loadedFiles.remove(path); loadedFiles.push_back(path); Value v, v2; - state.evalFile(lookupFileArg(state, path), v); - state.autoCallFunction(*autoArgs, v, v2); + state->evalFile(lookupFileArg(*state, path), v); + state->autoCallFunction(*autoArgs, v, v2); addAttrsToScope(v2); } void NixRepl::initEnv() { - env = &state.allocEnv(envSize); - env->up = &state.baseEnv; + env = &state->allocEnv(envSize); + env->up = &state->baseEnv; displ = 0; staticEnv.vars.clear(); varNames.clear(); - for (auto & i : state.staticBaseEnv.vars) + for (auto & i : state->staticBaseEnv.vars) varNames.insert(i.first); } @@ -616,7 +616,7 @@ void NixRepl::reloadFiles() void NixRepl::addAttrsToScope(Value & attrs) { - state.forceAttrs(attrs); + state->forceAttrs(attrs); for (auto & i : *attrs.attrs) addVarToScope(i.name, *i.value); std::cout << format("Added %1% variables.") % attrs.attrs->size() << std::endl; @@ -635,7 +635,7 @@ void NixRepl::addVarToScope(const Symbol & name, Value & v) Expr * NixRepl::parseString(string s) { - Expr * e = state.parseExprFromString(s, curDir, staticEnv); + Expr * e = state->parseExprFromString(s, curDir, staticEnv); return e; } @@ -643,8 +643,8 @@ Expr * NixRepl::parseString(string s) void NixRepl::evalString(string s, Value & v) { Expr * e = parseString(s); - e->eval(state, *env, v); - state.forceValue(v); + e->eval(*state, *env, v); + state->forceValue(v); } @@ -674,7 +674,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m str.flush(); checkInterrupt(); - state.forceValue(v); + state->forceValue(v); switch (v.type) { @@ -703,13 +703,13 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m case tAttrs: { seen.insert(&v); - bool isDrv = state.isDerivation(v); + bool isDrv = state->isDerivation(v); if (isDrv) { str << "«derivation "; - Bindings::iterator i = v.attrs->find(state.sDrvPath); + Bindings::iterator i = v.attrs->find(state->sDrvPath); PathSet context; - Path drvPath = i != v.attrs->end() ? state.coerceToPath(*i->pos, *i->value, context) : "???"; + Path drvPath = i != v.attrs->end() ? state->coerceToPath(*i->pos, *i->value, context) : "???"; str << drvPath << "»"; } @@ -812,7 +812,7 @@ struct CmdRepl : StoreCommand, MixEvalArgs void run(ref store) override { auto repl = std::make_unique(searchPath, openStore()); - repl->autoArgs = getAutoArgs(repl->state); + repl->autoArgs = getAutoArgs(*repl->state); repl->mainLoop(files); } }; From c5a488afc05372dd46e05559ef04ac9969808507 Mon Sep 17 00:00:00 2001 From: jakobrs Date: Thu, 19 Mar 2020 19:15:55 +0100 Subject: [PATCH 6/6] Remove the --delete option for --gc Running `nix-store --gc --delete` will, as of Nix 2.3.3, simply fail because the --delete option conflicts with the --delete operation. $ nix-store --gc --delete error: only one operation may be specified Try 'nix-store --help' for more information. Furthermore, it has been broken since at least Nix 0.16 (which was released sometime in 2010), which means that any scripts which depend on it should have been broken at least nine years ago. This commit simply formally removes the option. There should be no actual difference in behaviour as far as the user is concerned: it errors with the exact same error message. The manual has been edited to remove any references to the (now gone) --delete option. Other information: * Path for Nix 0.16 used: /nix/store/rp3sgmskn0p0pj1ia2qwd5al6f6pinz4-nix-0.16 --- doc/manual/command-ref/nix-store.xml | 17 ++++------------- src/nix-store/nix-store.cc | 1 - 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/doc/manual/command-ref/nix-store.xml b/doc/manual/command-ref/nix-store.xml index 113a3c2e4..e8bbd16e8 100644 --- a/doc/manual/command-ref/nix-store.xml +++ b/doc/manual/command-ref/nix-store.xml @@ -360,7 +360,6 @@ EOF - bytes @@ -407,14 +406,6 @@ the Nix store not reachable via file system references from a set of - - - This operation performs an actual garbage - collection. All dead paths are removed from the - store. This is the default. - - - By default, all unreachable paths are deleted. The following @@ -444,10 +435,10 @@ and keep-derivations variables in the Nix configuration file. -With , the collector prints the total -number of freed bytes when it finishes (or when it is interrupted). -With , it prints the number of bytes that -would be freed. +By default, the collector prints the total number of freed bytes +when it finishes (or when it is interrupted). With +, it prints the number of bytes that would +be freed. diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 45e152c47..c14d900ae 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -577,7 +577,6 @@ static void opGC(Strings opFlags, Strings opArgs) if (*i == "--print-roots") printRoots = true; else if (*i == "--print-live") options.action = GCOptions::gcReturnLive; else if (*i == "--print-dead") options.action = GCOptions::gcReturnDead; - else if (*i == "--delete") options.action = GCOptions::gcDeleteDead; else if (*i == "--max-freed") { long long maxFreed = getIntArg(*i, i, opFlags.end(), true); options.maxFreed = maxFreed >= 0 ? maxFreed : 0;