blob: d41d6647e57efe30a76d1c21e192c33a068e07e3 [file] [log] [blame]
Skyler Grey2aa52512022-07-21 00:00:04 +01001From 519d541fdc71508793ece6e087d2c1a231378558 Mon Sep 17 00:00:00 2001
2From: Skyler Grey <skyler3665@gmail.com>
3Date: Wed, 20 Jul 2022 14:45:45 +0100
4Subject: [PATCH 1/4] Make --expr always include nixpkgs
5
6---
7 src/libcmd/installables.cc | 7 +++++--
8 1 file changed, 5 insertions(+), 2 deletions(-)
9
10diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
11index 59162c4df03..7dc3f7435ee 100644
12--- a/src/libcmd/installables.cc
13+++ b/src/libcmd/installables.cc
14@@ -778,8 +778,11 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
15 } else if (file)
16 state->evalFile(lookupFileArg(*state, *file), *vFile);
17 else {
18- auto e = state->parseExprFromString(*expr, absPath("."));
19- state->eval(e, *vFile);
20+ Strings e = {};
21+ e.push_back("with (builtins.getFlake \"nixpkgs\")");
22+ e.push_back(*expr);
23+ auto parsed = state->parseExprFromString(concatStringsSep(";", e), absPath("."));
24+ state->eval(parsed, *vFile);
25 }
26
27 for (auto & s : ss) {
28
29From 29b83de5671901e5e8755c17b840139a6f8650db Mon Sep 17 00:00:00 2001
30From: Skyler Grey <skyler3665@gmail.com>
31Date: Wed, 20 Jul 2022 14:46:17 +0100
32Subject: [PATCH 2/4] Stop --expr requiring --impure flag
33
34---
35 src/libcmd/installables.cc | 2 +-
36 1 file changed, 1 insertion(+), 1 deletion(-)
37
38diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
39index 7dc3f7435ee..43e759b3e93 100644
40--- a/src/libcmd/installables.cc
41+++ b/src/libcmd/installables.cc
42@@ -767,7 +767,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
43 throw UsageError("'--file' and '--expr' are exclusive");
44
45 // FIXME: backward compatibility hack
46- if (file) evalSettings.pureEval = false;
47+ evalSettings.pureEval = false;
48
49 auto state = getEvalState();
50 auto vFile = state->allocValue();
51
52From 9e9d28496a7216a0e2893ac0eb05a8c45d898c95 Mon Sep 17 00:00:00 2001
53From: Skyler Grey <skyler3665@gmail.com>
54Date: Wed, 20 Jul 2022 23:51:16 +0100
55Subject: [PATCH 3/4] Make nix shell take installables as context
56
57---
58 src/libcmd/installables.cc | 46 +++++++++++++++++++++++++++++++++++++-
59 1 file changed, 45 insertions(+), 1 deletion(-)
60
61diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
62index 43e759b3e93..1abad72e333 100644
63--- a/src/libcmd/installables.cc
64+++ b/src/libcmd/installables.cc
65@@ -779,10 +779,54 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
66 state->evalFile(lookupFileArg(*state, *file), *vFile);
67 else {
68 Strings e = {};
69- e.push_back("with (builtins.getFlake \"nixpkgs\")");
70+
71+ for (auto & s : ss) {
72+ std::exception_ptr ex;
73+
74+ if (s.find('/') != std::string::npos) {
75+ try {
76+ result.push_back(std::make_shared<InstallableStorePath>(store, store->followLinksToStorePath(s)));
77+ continue;
78+ } catch (BadStorePath &) {
79+ } catch (...) {
80+ if (!ex)
81+ ex = std::current_exception();
82+ }
83+ }
84+
85+ try {
86+ auto [flakeRef, fragment, outputsSpec] = parseFlakeRefWithFragmentAndOutputsSpec(s, absPath("."));
87+/* result.push_back(std::make_shared<InstallableFlake>(
88+ this,
89+ getEvalState(),
90+ std::move(flakeRef),
91+ fragment,
92+ outputsSpec,
93+ getDefaultFlakeAttrPaths(),
94+ getDefaultFlakeAttrPathPrefixes(),
95+ lockFlags));*/
96+ e.push_back("with (builtins.getFlake \"" + flakeRef.to_string() + "\")" + (fragment != "" ? "." + fragment : ""));
97+ e.push_back("with (builtins.getFlake \"" + flakeRef.to_string() + "\").packages.\"${builtins.currentSystem}\"" + (fragment != "" ? "." + fragment : ""));
98+ e.push_back("with (builtins.getFlake \"" + flakeRef.to_string() + "\").legacyPackages.\"${builtins.currentSystem}\"" + (fragment != "" ? "." + fragment : ""));
99+ continue;
100+ } catch (...) {
101+ ex = std::current_exception();
102+ }
103+
104+ std::rethrow_exception(ex);
105+ }
106+
107 e.push_back(*expr);
108 auto parsed = state->parseExprFromString(concatStringsSep(";", e), absPath("."));
109 state->eval(parsed, *vFile);
110+
111+ auto [prefix, outputsSpec] = parseOutputsSpec(".");
112+ result.push_back(
113+ std::make_shared<InstallableAttrPath>(
114+ state, *this, vFile,
115+ prefix == "." ? "" : prefix,
116+ outputsSpec));
117+ return result;
118 }
119
120 for (auto & s : ss) {
121
122From e3045be11cbac91a5e65ef42e42e320e6689e713 Mon Sep 17 00:00:00 2001
123From: Skyler Grey <skyler3665@gmail.com>
124Date: Wed, 20 Jul 2022 23:56:09 +0100
125Subject: [PATCH 4/4] Update documentation to match nix shell change
126
127---
128 src/nix/nix.md | 9 +++++++--
129 1 file changed, 7 insertions(+), 2 deletions(-)
130
131diff --git a/src/nix/nix.md b/src/nix/nix.md
132index d48682a9432..b5bee708451 100644
133--- a/src/nix/nix.md
134+++ b/src/nix/nix.md
135@@ -139,8 +139,13 @@ the Nix store. Here are the recognised types of installables:
136 * **Nix expressions**: `--expr '(import <nixpkgs> {}).hello.overrideDerivation (prev: { name = "my-hello"; })'`.
137
138 When the `--expr` option is given, all installables are interpreted
139- as Nix expressions. You may need to specify `--impure` if the
140- expression references impure inputs (such as `<nixpkgs>`).
141+ as context for the expression. For example, the following is valid:
142+
143+ ```console
144+ # nix shell nixpkgs#python3 --expr 'withPackages(pyPkgs: with pyPkgs; [ numpy ])'
145+ ```
146+
147+ Using `--expr` implies `--impure`.
148
149 For most commands, if no installable is specified, the default is `.`,
150 i.e. Nix will operate on the default flake output attribute of the