blob: 112d7a2b804d042f9a7eef560c4c9b6842a566d8 [file] [log] [blame]
Skyler Greyc767aa82023-02-24 09:04:17 +00001From a54baf53d934a3c95bcc42bdbeaefca3cc12aab7 Mon Sep 17 00:00:00 2001
Skyler Grey5b753722022-08-26 07:53:33 +01002From: Skyler Grey <skyler3665@gmail.com>
3Date: Wed, 20 Jul 2022 14:45:45 +0100
Skyler Greyc767aa82023-02-24 09:04:17 +00004Subject: [PATCH 01/11] Make --expr always include nixpkgs
Skyler Grey5b753722022-08-26 07:53:33 +01005
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
Skyler Greyc767aa82023-02-24 09:04:17 +000011index 60d6e9dc08c..e065f655452 100644
Skyler Grey5b753722022-08-26 07:53:33 +010012--- a/src/libcmd/installables.cc
13+++ b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +000014@@ -788,8 +788,11 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
15 else if (file)
Skyler Grey5b753722022-08-26 07:53:33 +010016 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
Skyler Greyc767aa82023-02-24 09:04:17 +000029From 8e2457a62ab209e1f111ab71aeaa694ad35fd0fd Mon Sep 17 00:00:00 2001
Skyler Grey5b753722022-08-26 07:53:33 +010030From: Skyler Grey <skyler3665@gmail.com>
31Date: Wed, 20 Jul 2022 14:46:17 +0100
Skyler Greyc767aa82023-02-24 09:04:17 +000032Subject: [PATCH 02/11] Stop --expr requiring --impure flag
Skyler Grey5b753722022-08-26 07:53:33 +010033
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
Skyler Greyc767aa82023-02-24 09:04:17 +000039index e065f655452..fc83d6e35b8 100644
Skyler Grey5b753722022-08-26 07:53:33 +010040--- a/src/libcmd/installables.cc
41+++ b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +000042@@ -776,7 +776,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Skyler Grey5b753722022-08-26 07:53:33 +010043 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
Skyler Greyc767aa82023-02-24 09:04:17 +000052From c2f7a39313ab34dc208fddc0a2467e7739bc3754 Mon Sep 17 00:00:00 2001
Skyler Grey5b753722022-08-26 07:53:33 +010053From: Skyler Grey <skyler3665@gmail.com>
54Date: Wed, 20 Jul 2022 23:51:16 +0100
Skyler Greyc767aa82023-02-24 09:04:17 +000055Subject: [PATCH 03/11] Make nix shell take installables as context
Skyler Grey5b753722022-08-26 07:53:33 +010056
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
Skyler Greyc767aa82023-02-24 09:04:17 +000062index fc83d6e35b8..477aa8cc760 100644
Skyler Grey5b753722022-08-26 07:53:33 +010063--- a/src/libcmd/installables.cc
64+++ b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +000065@@ -789,10 +789,54 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Skyler Grey5b753722022-08-26 07:53:33 +010066 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
Skyler Greyc767aa82023-02-24 09:04:17 +0000122From 2aaef9cd16698dd4c574c0c0fe6bc03394ef2296 Mon Sep 17 00:00:00 2001
Skyler Grey5b753722022-08-26 07:53:33 +0100123From: Skyler Grey <skyler3665@gmail.com>
124Date: Wed, 20 Jul 2022 23:56:09 +0100
Skyler Greyc767aa82023-02-24 09:04:17 +0000125Subject: [PATCH 04/11] Update documentation to match nix shell change
Skyler Grey5b753722022-08-26 07:53:33 +0100126
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
Skyler Greyc767aa82023-02-24 09:04:17 +0000132index db60c59ffaf..3491b38af23 100644
Skyler Grey5b753722022-08-26 07:53:33 +0100133--- a/src/nix/nix.md
134+++ b/src/nix/nix.md
Skyler Greyc767aa82023-02-24 09:04:17 +0000135@@ -138,8 +138,13 @@ the Nix store. Here are the recognised types of installables:
Skyler Grey5b753722022-08-26 07:53:33 +0100136 * **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
151
Skyler Greyc767aa82023-02-24 09:04:17 +0000152From 340051b4f71957bc93ec7ac6511657c4de6dc0ce Mon Sep 17 00:00:00 2001
Skyler Grey5b753722022-08-26 07:53:33 +0100153From: Skyler Grey <skyler3665@gmail.com>
154Date: Thu, 21 Jul 2022 21:49:44 +0100
Skyler Greyc767aa82023-02-24 09:04:17 +0000155Subject: [PATCH 05/11] Only build . with expr if it'd be a default installable
Skyler Grey5b753722022-08-26 07:53:33 +0100156
157---
158 src/libcmd/installables.cc | 16 +++++++++-------
159 1 file changed, 9 insertions(+), 7 deletions(-)
160
161diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +0000162index 477aa8cc760..e82103422bf 100644
Skyler Grey5b753722022-08-26 07:53:33 +0100163--- a/src/libcmd/installables.cc
164+++ b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +0000165@@ -830,13 +830,15 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Skyler Grey5b753722022-08-26 07:53:33 +0100166 auto parsed = state->parseExprFromString(concatStringsSep(";", e), absPath("."));
167 state->eval(parsed, *vFile);
168
169- auto [prefix, outputsSpec] = parseOutputsSpec(".");
170- result.push_back(
171- std::make_shared<InstallableAttrPath>(
172- state, *this, vFile,
173- prefix == "." ? "" : prefix,
174- outputsSpec));
175- return result;
176+ if (!ss.empty()) {
177+ auto [prefix, outputsSpec] = parseOutputsSpec(".");
178+ result.push_back(
179+ std::make_shared<InstallableAttrPath>(
180+ state, *this, vFile,
181+ prefix == "." ? "" : prefix,
182+ outputsSpec));
183+ return result;
184+ }
185 }
186
187 for (auto & s : ss) {
188
Skyler Greyc767aa82023-02-24 09:04:17 +0000189From 01426c7c8d76b57fd342d7e2ce4390c9dba92c27 Mon Sep 17 00:00:00 2001
Skyler Grey5b753722022-08-26 07:53:33 +0100190From: Skyler Grey <skyler3665@gmail.com>
191Date: Fri, 22 Jul 2022 14:28:31 +0100
Skyler Greyc767aa82023-02-24 09:04:17 +0000192Subject: [PATCH 06/11] Do not include implicit installables with expr
Skyler Grey5b753722022-08-26 07:53:33 +0100193
194---
195 src/libcmd/command.hh | 2 +-
196 src/libcmd/installables.cc | 9 +++++----
197 2 files changed, 6 insertions(+), 5 deletions(-)
198
199diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh
200index 3b4b40981de..ba6ab4197ad 100644
201--- a/src/libcmd/command.hh
202+++ b/src/libcmd/command.hh
203@@ -102,7 +102,7 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions
204 SourceExprCommand(bool supportReadOnlyMode = false);
205
206 std::vector<std::shared_ptr<Installable>> parseInstallables(
207- ref<Store> store, std::vector<std::string> ss);
208+ ref<Store> store, std::vector<std::string> ss, std::optional<std::vector<std::string>> explicitInstallables);
209
210 std::shared_ptr<Installable> parseInstallable(
211 ref<Store> store, const std::string & installable);
212diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +0000213index e82103422bf..5c11c976299 100644
Skyler Grey5b753722022-08-26 07:53:33 +0100214--- a/src/libcmd/installables.cc
215+++ b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +0000216@@ -763,7 +763,7 @@ FlakeRef InstallableFlake::nixpkgsFlakeRef() const
Skyler Grey5b753722022-08-26 07:53:33 +0100217 }
218
219 std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
220- ref<Store> store, std::vector<std::string> ss)
221+ ref<Store> store, std::vector<std::string> ss, std::optional<std::vector<std::string>> explicitInstallables = std::nullopt)
222 {
223 std::vector<std::shared_ptr<Installable>> result;
224
Skyler Greyc767aa82023-02-24 09:04:17 +0000225@@ -790,7 +790,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Skyler Grey5b753722022-08-26 07:53:33 +0100226 else {
227 Strings e = {};
228
229- for (auto & s : ss) {
230+ for (auto & s : explicitInstallables.value_or(ss)) {
231 std::exception_ptr ex;
232
233 if (s.find('/') != std::string::npos) {
Skyler Greyc767aa82023-02-24 09:04:17 +0000234@@ -837,8 +837,8 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Skyler Grey5b753722022-08-26 07:53:33 +0100235 state, *this, vFile,
236 prefix == "." ? "" : prefix,
237 outputsSpec));
238- return result;
239 }
240+ return result;
241 }
242
243 for (auto & s : ss) {
Skyler Greyc767aa82023-02-24 09:04:17 +0000244@@ -1132,11 +1132,12 @@ void InstallablesCommand::prepare()
Skyler Grey5b753722022-08-26 07:53:33 +0100245
246 Installables InstallablesCommand::load() {
247 Installables installables;
248+ auto explicitInstallables = _installables;
249 if (_installables.empty() && useDefaultInstallables())
250 // FIXME: commands like "nix profile install" should not have a
251 // default, probably.
252 _installables.push_back(".");
253- return parseInstallables(getStore(), _installables);
254+ return parseInstallables(getStore(), _installables, explicitInstallables);
255 }
256
257 std::vector<std::string> InstallablesCommand::getFlakesForCompletion()
258
Skyler Greyc767aa82023-02-24 09:04:17 +0000259From 82904ee72f245f4b901f8f9b94c4e9caff2b53be Mon Sep 17 00:00:00 2001
Skyler Grey5b753722022-08-26 07:53:33 +0100260From: Skyler Grey <skyler3665@gmail.com>
261Date: Fri, 22 Jul 2022 20:13:48 +0100
Skyler Greyc767aa82023-02-24 09:04:17 +0000262Subject: [PATCH 07/11] Allow running --expr purely again
Skyler Grey5b753722022-08-26 07:53:33 +0100263
264---
265 src/libcmd/installables.cc | 15 ++++++++-------
266 src/nix/nix.md | 2 --
267 2 files changed, 8 insertions(+), 9 deletions(-)
268
269diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +0000270index 5c11c976299..e54d4107353 100644
Skyler Grey5b753722022-08-26 07:53:33 +0100271--- a/src/libcmd/installables.cc
272+++ b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +0000273@@ -776,7 +776,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Skyler Grey5b753722022-08-26 07:53:33 +0100274 throw UsageError("'--file' and '--expr' are exclusive");
275
276 // FIXME: backward compatibility hack
277- evalSettings.pureEval = false;
278+ if (file) evalSettings.pureEval = false;
279
280 auto state = getEvalState();
281 auto vFile = state->allocValue();
Skyler Greyc767aa82023-02-24 09:04:17 +0000282@@ -790,7 +790,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Skyler Grey5b753722022-08-26 07:53:33 +0100283 else {
284 Strings e = {};
285
286- for (auto & s : explicitInstallables.value_or(ss)) {
287+ for (auto & s : explicitInstallables.value_or(std::vector<std::string>())) {
288 std::exception_ptr ex;
289
290 if (s.find('/') != std::string::npos) {
Skyler Greyc767aa82023-02-24 09:04:17 +0000291@@ -806,7 +806,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Skyler Grey5b753722022-08-26 07:53:33 +0100292
293 try {
294 auto [flakeRef, fragment, outputsSpec] = parseFlakeRefWithFragmentAndOutputsSpec(s, absPath("."));
295-/* result.push_back(std::make_shared<InstallableFlake>(
296+ auto installableFlake = InstallableFlake(
297 this,
298 getEvalState(),
299 std::move(flakeRef),
Skyler Greyc767aa82023-02-24 09:04:17 +0000300@@ -814,10 +814,11 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Skyler Grey5b753722022-08-26 07:53:33 +0100301 outputsSpec,
302 getDefaultFlakeAttrPaths(),
303 getDefaultFlakeAttrPathPrefixes(),
304- lockFlags));*/
305- e.push_back("with (builtins.getFlake \"" + flakeRef.to_string() + "\")" + (fragment != "" ? "." + fragment : ""));
306- e.push_back("with (builtins.getFlake \"" + flakeRef.to_string() + "\").packages.\"${builtins.currentSystem}\"" + (fragment != "" ? "." + fragment : ""));
307- e.push_back("with (builtins.getFlake \"" + flakeRef.to_string() + "\").legacyPackages.\"${builtins.currentSystem}\"" + (fragment != "" ? "." + fragment : ""));
308+ lockFlags);
309+ auto lockedFlake = installableFlake.getLockedFlake()->flake.lockedRef;
310+ e.push_back("with (builtins.getFlake \"" + lockedFlake.to_string() + "\")" + (fragment != "" ? "." + fragment : ""));
311+ e.push_back("with (builtins.getFlake \"" + lockedFlake.to_string() + "\").packages.\"${builtins.currentSystem}\"" + (fragment != "" ? "." + fragment : ""));
312+ e.push_back("with (builtins.getFlake \"" + lockedFlake.to_string() + "\").legacyPackages.\"${builtins.currentSystem}\"" + (fragment != "" ? "." + fragment : ""));
313 continue;
314 } catch (...) {
315 ex = std::current_exception();
316diff --git a/src/nix/nix.md b/src/nix/nix.md
Skyler Greyc767aa82023-02-24 09:04:17 +0000317index 3491b38af23..2fdaf258643 100644
Skyler Grey5b753722022-08-26 07:53:33 +0100318--- a/src/nix/nix.md
319+++ b/src/nix/nix.md
Skyler Greyc767aa82023-02-24 09:04:17 +0000320@@ -144,8 +144,6 @@ the Nix store. Here are the recognised types of installables:
Skyler Grey5b753722022-08-26 07:53:33 +0100321 # nix shell nixpkgs#python3 --expr 'withPackages(pyPkgs: with pyPkgs; [ numpy ])'
322 ```
323
324- Using `--expr` implies `--impure`.
325-
326 For most commands, if no installable is specified, the default is `.`,
327 i.e. Nix will operate on the default flake output attribute of the
328 flake in the current directory.
329
Skyler Greyc767aa82023-02-24 09:04:17 +0000330From 60aeb420787c6276e26df6c73bd33d2a870590ef Mon Sep 17 00:00:00 2001
Skyler Grey5b753722022-08-26 07:53:33 +0100331From: Skyler Grey <skyler3665@gmail.com>
332Date: Sat, 23 Jul 2022 11:46:07 +0100
Skyler Greyc767aa82023-02-24 09:04:17 +0000333Subject: [PATCH 08/11] Fix builtins.currentSystem in pure evaluation
Skyler Grey5b753722022-08-26 07:53:33 +0100334
335---
336 src/libcmd/installables.cc | 15 ++++++++++++---
337 1 file changed, 12 insertions(+), 3 deletions(-)
338
339diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +0000340index e54d4107353..95a31dba289 100644
Skyler Grey5b753722022-08-26 07:53:33 +0100341--- a/src/libcmd/installables.cc
342+++ b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +0000343@@ -816,9 +816,18 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Skyler Grey5b753722022-08-26 07:53:33 +0100344 getDefaultFlakeAttrPathPrefixes(),
345 lockFlags);
346 auto lockedFlake = installableFlake.getLockedFlake()->flake.lockedRef;
347- e.push_back("with (builtins.getFlake \"" + lockedFlake.to_string() + "\")" + (fragment != "" ? "." + fragment : ""));
348- e.push_back("with (builtins.getFlake \"" + lockedFlake.to_string() + "\").packages.\"${builtins.currentSystem}\"" + (fragment != "" ? "." + fragment : ""));
349- e.push_back("with (builtins.getFlake \"" + lockedFlake.to_string() + "\").legacyPackages.\"${builtins.currentSystem}\"" + (fragment != "" ? "." + fragment : ""));
350+
351+ auto defaultPathPrefixes = getDefaultFlakeAttrPathPrefixes();
352+ defaultPathPrefixes.push_back("");
353+
354+ for (auto & path : defaultPathPrefixes) {
355+ if (path.length()) {
356+ path.pop_back();
357+ path = "." + path;
358+ }
359+
360+ e.push_back(str(boost::format("with (builtins.getFlake \"%1%\")%2%%3%") % lockedFlake.to_string() % path % (fragment != "" ? "." + fragment : "")));
361+ }
362 continue;
363 } catch (...) {
364 ex = std::current_exception();
365
Skyler Greyc767aa82023-02-24 09:04:17 +0000366From ed9400560c79657b9d7a2e2952fb4effc6453928 Mon Sep 17 00:00:00 2001
Skyler Grey5b753722022-08-26 07:53:33 +0100367From: Skyler Grey <skyler3665@gmail.com>
368Date: Sun, 24 Jul 2022 01:30:00 +0100
Skyler Greyc767aa82023-02-24 09:04:17 +0000369Subject: [PATCH 09/11] Gracefully handle missing attributes
Skyler Grey5b753722022-08-26 07:53:33 +0100370
371---
372 src/libcmd/installables.cc | 2 +-
373 1 file changed, 1 insertion(+), 1 deletion(-)
374
375diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +0000376index 95a31dba289..419fc90c96a 100644
Skyler Grey5b753722022-08-26 07:53:33 +0100377--- a/src/libcmd/installables.cc
378+++ b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +0000379@@ -826,7 +826,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Skyler Grey5b753722022-08-26 07:53:33 +0100380 path = "." + path;
381 }
382
383- e.push_back(str(boost::format("with (builtins.getFlake \"%1%\")%2%%3%") % lockedFlake.to_string() % path % (fragment != "" ? "." + fragment : "")));
384+ e.push_back(str(boost::format("with (builtins.getFlake \"%1%\")%2%%3% or {}") % lockedFlake.to_string() % path % (fragment != "" ? "." + fragment : "")));
385 }
386 continue;
387 } catch (...) {
388
Skyler Greyc767aa82023-02-24 09:04:17 +0000389From 3fba464fe76656d54136ab757fc7ede579254a4e Mon Sep 17 00:00:00 2001
Skyler Grey5b753722022-08-26 07:53:33 +0100390From: Skyler Grey <skyler3665@gmail.com>
391Date: Sun, 24 Jul 2022 07:11:37 +0100
Skyler Greyc767aa82023-02-24 09:04:17 +0000392Subject: [PATCH 10/11] Fix including a flake without any attrpath
Skyler Grey5b753722022-08-26 07:53:33 +0100393
394---
395 src/libcmd/installables.cc | 2 +-
396 1 file changed, 1 insertion(+), 1 deletion(-)
397
398diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +0000399index 419fc90c96a..bad324b424c 100644
Skyler Grey5b753722022-08-26 07:53:33 +0100400--- a/src/libcmd/installables.cc
401+++ b/src/libcmd/installables.cc
Skyler Greyc767aa82023-02-24 09:04:17 +0000402@@ -826,7 +826,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Skyler Grey5b753722022-08-26 07:53:33 +0100403 path = "." + path;
404 }
405
406- e.push_back(str(boost::format("with (builtins.getFlake \"%1%\")%2%%3% or {}") % lockedFlake.to_string() % path % (fragment != "" ? "." + fragment : "")));
407+ e.push_back(str(boost::format("with (builtins.getFlake \"%1%\").outputs%2%%3% or {}") % lockedFlake.to_string() % path % (fragment != "" ? "." + fragment : "")));
408 }
409 continue;
410 } catch (...) {
Skyler Greyc767aa82023-02-24 09:04:17 +0000411
412From 8ad1e705394a304db09935c207a964de33c02c08 Mon Sep 17 00:00:00 2001
413From: Skyler Grey <skyler3665@gmail.com>
414Date: Fri, 24 Feb 2023 01:09:56 +0000
415Subject: [PATCH 11/11] Fix regressions in the patch due to nix changes
416
417---
418 src/libcmd/installables.cc | 48 +++++++++++++++++++++++++++++++++-----
419 1 file changed, 42 insertions(+), 6 deletions(-)
420
421diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
422index bad324b424c..57c2492c106 100644
423--- a/src/libcmd/installables.cc
424+++ b/src/libcmd/installables.cc
425@@ -791,11 +791,47 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
426 Strings e = {};
427
428 for (auto & s : explicitInstallables.value_or(std::vector<std::string>())) {
429+
430+ auto [prefix_, extendedOutputsSpec_] = ExtendedOutputsSpec::parse(s);
431+ // To avoid clang's pedantry
432+ auto prefix = std::move(prefix_);
433+ auto extendedOutputsSpec = std::move(extendedOutputsSpec_);
434 std::exception_ptr ex;
435
436- if (s.find('/') != std::string::npos) {
437+ if (prefix.find('/') != std::string::npos) {
438 try {
439- result.push_back(std::make_shared<InstallableStorePath>(store, store->followLinksToStorePath(s)));
440+ auto derivedPath = std::visit(overloaded {
441+ // If the user did not use ^, we treat the output more liberally.
442+ [&](const ExtendedOutputsSpec::Default &) -> DerivedPath {
443+ // First, we accept a symlink chain or an actual store path.
444+ auto storePath = store->followLinksToStorePath(prefix);
445+ // Second, we see if the store path ends in `.drv` to decide what sort
446+ // of derived path they want.
447+ //
448+ // This handling predates the `^` syntax. The `^*` in
449+ // `/nix/store/hash-foo.drv^*` unambiguously means "do the
450+ // `DerivedPath::Built` case", so plain `/nix/store/hash-foo.drv` could
451+ // also unambiguously mean "do the DerivedPath::Opaque` case".
452+ //
453+ // Issue #7261 tracks reconsidering this `.drv` dispatching.
454+ return storePath.isDerivation()
455+ ? (DerivedPath) DerivedPath::Built {
456+ .drvPath = std::move(storePath),
457+ .outputs = OutputsSpec::All {},
458+ }
459+ : (DerivedPath) DerivedPath::Opaque {
460+ .path = std::move(storePath),
461+ };
462+ },
463+ // If the user did use ^, we just do exactly what is written.
464+ [&](const ExtendedOutputsSpec::Explicit & outputSpec) -> DerivedPath {
465+ return DerivedPath::Built {
466+ .drvPath = store->parseStorePath(prefix),
467+ .outputs = outputSpec,
468+ };
469+ },
470+ }, extendedOutputsSpec.raw());
471+ result.push_back(std::make_shared<InstallableStorePath>(store, std::move(derivedPath)));
472 continue;
473 } catch (BadStorePath &) {
474 } catch (...) {
475@@ -805,7 +841,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
476 }
477
478 try {
479- auto [flakeRef, fragment, outputsSpec] = parseFlakeRefWithFragmentAndOutputsSpec(s, absPath("."));
480+ auto [flakeRef, fragment, outputsSpec] = parseFlakeRefWithFragmentAndExtendedOutputsSpec(s, absPath("."));
481 auto installableFlake = InstallableFlake(
482 this,
483 getEvalState(),
484@@ -826,7 +862,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
485 path = "." + path;
486 }
487
488- e.push_back(str(boost::format("with (builtins.getFlake \"%1%\").outputs%2%%3% or {}") % lockedFlake.to_string() % path % (fragment != "" ? "." + fragment : "")));
489+ e.push_back(boost::str(boost::format("with (builtins.getFlake \"%1%\").outputs%2%%3% or {}") % lockedFlake.to_string() % path % (fragment != "" ? "." + fragment : "")));
490 }
491 continue;
492 } catch (...) {
493@@ -841,11 +877,11 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
494 state->eval(parsed, *vFile);
495
496 if (!ss.empty()) {
497- auto [prefix, outputsSpec] = parseOutputsSpec(".");
498+ auto [prefix, outputsSpec] = ExtendedOutputsSpec::parse(".");
499 result.push_back(
500 std::make_shared<InstallableAttrPath>(
501 state, *this, vFile,
502- prefix == "." ? "" : prefix,
503+ prefix == "." ? "" : std::string { prefix },
504 outputsSpec));
505 }
506 return result;