| From 519d541fdc71508793ece6e087d2c1a231378558 Mon Sep 17 00:00:00 2001 |
| From: Skyler Grey <skyler3665@gmail.com> |
| Date: Wed, 20 Jul 2022 14:45:45 +0100 |
| Subject: [PATCH 1/4] Make --expr always include nixpkgs |
| |
| --- |
| src/libcmd/installables.cc | 7 +++++-- |
| 1 file changed, 5 insertions(+), 2 deletions(-) |
| |
| diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
| index 59162c4df03..7dc3f7435ee 100644 |
| --- a/src/libcmd/installables.cc |
| +++ b/src/libcmd/installables.cc |
| @@ -778,8 +778,11 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
| } else if (file) |
| state->evalFile(lookupFileArg(*state, *file), *vFile); |
| else { |
| - auto e = state->parseExprFromString(*expr, absPath(".")); |
| - state->eval(e, *vFile); |
| + Strings e = {}; |
| + e.push_back("with (builtins.getFlake \"nixpkgs\")"); |
| + e.push_back(*expr); |
| + auto parsed = state->parseExprFromString(concatStringsSep(";", e), absPath(".")); |
| + state->eval(parsed, *vFile); |
| } |
| |
| for (auto & s : ss) { |
| |
| From 29b83de5671901e5e8755c17b840139a6f8650db Mon Sep 17 00:00:00 2001 |
| From: Skyler Grey <skyler3665@gmail.com> |
| Date: Wed, 20 Jul 2022 14:46:17 +0100 |
| Subject: [PATCH 2/4] Stop --expr requiring --impure flag |
| |
| --- |
| src/libcmd/installables.cc | 2 +- |
| 1 file changed, 1 insertion(+), 1 deletion(-) |
| |
| diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
| index 7dc3f7435ee..43e759b3e93 100644 |
| --- a/src/libcmd/installables.cc |
| +++ b/src/libcmd/installables.cc |
| @@ -767,7 +767,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
| throw UsageError("'--file' and '--expr' are exclusive"); |
| |
| // FIXME: backward compatibility hack |
| - if (file) evalSettings.pureEval = false; |
| + evalSettings.pureEval = false; |
| |
| auto state = getEvalState(); |
| auto vFile = state->allocValue(); |
| |
| From 9e9d28496a7216a0e2893ac0eb05a8c45d898c95 Mon Sep 17 00:00:00 2001 |
| From: Skyler Grey <skyler3665@gmail.com> |
| Date: Wed, 20 Jul 2022 23:51:16 +0100 |
| Subject: [PATCH 3/4] Make nix shell take installables as context |
| |
| --- |
| src/libcmd/installables.cc | 46 +++++++++++++++++++++++++++++++++++++- |
| 1 file changed, 45 insertions(+), 1 deletion(-) |
| |
| diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
| index 43e759b3e93..1abad72e333 100644 |
| --- a/src/libcmd/installables.cc |
| +++ b/src/libcmd/installables.cc |
| @@ -779,10 +779,54 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
| state->evalFile(lookupFileArg(*state, *file), *vFile); |
| else { |
| Strings e = {}; |
| - e.push_back("with (builtins.getFlake \"nixpkgs\")"); |
| + |
| + for (auto & s : ss) { |
| + std::exception_ptr ex; |
| + |
| + if (s.find('/') != std::string::npos) { |
| + try { |
| + result.push_back(std::make_shared<InstallableStorePath>(store, store->followLinksToStorePath(s))); |
| + continue; |
| + } catch (BadStorePath &) { |
| + } catch (...) { |
| + if (!ex) |
| + ex = std::current_exception(); |
| + } |
| + } |
| + |
| + try { |
| + auto [flakeRef, fragment, outputsSpec] = parseFlakeRefWithFragmentAndOutputsSpec(s, absPath(".")); |
| +/* result.push_back(std::make_shared<InstallableFlake>( |
| + this, |
| + getEvalState(), |
| + std::move(flakeRef), |
| + fragment, |
| + outputsSpec, |
| + getDefaultFlakeAttrPaths(), |
| + getDefaultFlakeAttrPathPrefixes(), |
| + lockFlags));*/ |
| + e.push_back("with (builtins.getFlake \"" + flakeRef.to_string() + "\")" + (fragment != "" ? "." + fragment : "")); |
| + e.push_back("with (builtins.getFlake \"" + flakeRef.to_string() + "\").packages.\"${builtins.currentSystem}\"" + (fragment != "" ? "." + fragment : "")); |
| + e.push_back("with (builtins.getFlake \"" + flakeRef.to_string() + "\").legacyPackages.\"${builtins.currentSystem}\"" + (fragment != "" ? "." + fragment : "")); |
| + continue; |
| + } catch (...) { |
| + ex = std::current_exception(); |
| + } |
| + |
| + std::rethrow_exception(ex); |
| + } |
| + |
| e.push_back(*expr); |
| auto parsed = state->parseExprFromString(concatStringsSep(";", e), absPath(".")); |
| state->eval(parsed, *vFile); |
| + |
| + auto [prefix, outputsSpec] = parseOutputsSpec("."); |
| + result.push_back( |
| + std::make_shared<InstallableAttrPath>( |
| + state, *this, vFile, |
| + prefix == "." ? "" : prefix, |
| + outputsSpec)); |
| + return result; |
| } |
| |
| for (auto & s : ss) { |
| |
| From e3045be11cbac91a5e65ef42e42e320e6689e713 Mon Sep 17 00:00:00 2001 |
| From: Skyler Grey <skyler3665@gmail.com> |
| Date: Wed, 20 Jul 2022 23:56:09 +0100 |
| Subject: [PATCH 4/4] Update documentation to match nix shell change |
| |
| --- |
| src/nix/nix.md | 9 +++++++-- |
| 1 file changed, 7 insertions(+), 2 deletions(-) |
| |
| diff --git a/src/nix/nix.md b/src/nix/nix.md |
| index d48682a9432..b5bee708451 100644 |
| --- a/src/nix/nix.md |
| +++ b/src/nix/nix.md |
| @@ -139,8 +139,13 @@ the Nix store. Here are the recognised types of installables: |
| * **Nix expressions**: `--expr '(import <nixpkgs> {}).hello.overrideDerivation (prev: { name = "my-hello"; })'`. |
| |
| When the `--expr` option is given, all installables are interpreted |
| - as Nix expressions. You may need to specify `--impure` if the |
| - expression references impure inputs (such as `<nixpkgs>`). |
| + as context for the expression. For example, the following is valid: |
| + |
| + ```console |
| + # nix shell nixpkgs#python3 --expr 'withPackages(pyPkgs: with pyPkgs; [ numpy ])' |
| + ``` |
| + |
| + Using `--expr` implies `--impure`. |
| |
| For most commands, if no installable is specified, the default is `.`, |
| i.e. Nix will operate on the default flake output attribute of the |