Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 1 | From a54baf53d934a3c95bcc42bdbeaefca3cc12aab7 Mon Sep 17 00:00:00 2001 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 2 | From: Skyler Grey <skyler3665@gmail.com> |
| 3 | Date: Wed, 20 Jul 2022 14:45:45 +0100 |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 4 | Subject: [PATCH 01/11] Make --expr always include nixpkgs |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 5 | |
| 6 | --- |
| 7 | src/libcmd/installables.cc | 7 +++++-- |
| 8 | 1 file changed, 5 insertions(+), 2 deletions(-) |
| 9 | |
| 10 | diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 11 | index 60d6e9dc08c..e065f655452 100644 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 12 | --- a/src/libcmd/installables.cc |
| 13 | +++ b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 14 | @@ -788,8 +788,11 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
| 15 | else if (file) |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 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 | |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 29 | From 8e2457a62ab209e1f111ab71aeaa694ad35fd0fd Mon Sep 17 00:00:00 2001 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 30 | From: Skyler Grey <skyler3665@gmail.com> |
| 31 | Date: Wed, 20 Jul 2022 14:46:17 +0100 |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 32 | Subject: [PATCH 02/11] Stop --expr requiring --impure flag |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 33 | |
| 34 | --- |
| 35 | src/libcmd/installables.cc | 2 +- |
| 36 | 1 file changed, 1 insertion(+), 1 deletion(-) |
| 37 | |
| 38 | diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 39 | index e065f655452..fc83d6e35b8 100644 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 40 | --- a/src/libcmd/installables.cc |
| 41 | +++ b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 42 | @@ -776,7 +776,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 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 | |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 52 | From c2f7a39313ab34dc208fddc0a2467e7739bc3754 Mon Sep 17 00:00:00 2001 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 53 | From: Skyler Grey <skyler3665@gmail.com> |
| 54 | Date: Wed, 20 Jul 2022 23:51:16 +0100 |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 55 | Subject: [PATCH 03/11] Make nix shell take installables as context |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 56 | |
| 57 | --- |
| 58 | src/libcmd/installables.cc | 46 +++++++++++++++++++++++++++++++++++++- |
| 59 | 1 file changed, 45 insertions(+), 1 deletion(-) |
| 60 | |
| 61 | diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 62 | index fc83d6e35b8..477aa8cc760 100644 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 63 | --- a/src/libcmd/installables.cc |
| 64 | +++ b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 65 | @@ -789,10 +789,54 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 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 | |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 122 | From 2aaef9cd16698dd4c574c0c0fe6bc03394ef2296 Mon Sep 17 00:00:00 2001 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 123 | From: Skyler Grey <skyler3665@gmail.com> |
| 124 | Date: Wed, 20 Jul 2022 23:56:09 +0100 |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 125 | Subject: [PATCH 04/11] Update documentation to match nix shell change |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 126 | |
| 127 | --- |
| 128 | src/nix/nix.md | 9 +++++++-- |
| 129 | 1 file changed, 7 insertions(+), 2 deletions(-) |
| 130 | |
| 131 | diff --git a/src/nix/nix.md b/src/nix/nix.md |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 132 | index db60c59ffaf..3491b38af23 100644 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 133 | --- a/src/nix/nix.md |
| 134 | +++ b/src/nix/nix.md |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 135 | @@ -138,8 +138,13 @@ the Nix store. Here are the recognised types of installables: |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 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 |
| 151 | |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 152 | From 340051b4f71957bc93ec7ac6511657c4de6dc0ce Mon Sep 17 00:00:00 2001 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 153 | From: Skyler Grey <skyler3665@gmail.com> |
| 154 | Date: Thu, 21 Jul 2022 21:49:44 +0100 |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 155 | Subject: [PATCH 05/11] Only build . with expr if it'd be a default installable |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 156 | |
| 157 | --- |
| 158 | src/libcmd/installables.cc | 16 +++++++++------- |
| 159 | 1 file changed, 9 insertions(+), 7 deletions(-) |
| 160 | |
| 161 | diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 162 | index 477aa8cc760..e82103422bf 100644 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 163 | --- a/src/libcmd/installables.cc |
| 164 | +++ b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 165 | @@ -830,13 +830,15 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 166 | 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 Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 189 | From 01426c7c8d76b57fd342d7e2ce4390c9dba92c27 Mon Sep 17 00:00:00 2001 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 190 | From: Skyler Grey <skyler3665@gmail.com> |
| 191 | Date: Fri, 22 Jul 2022 14:28:31 +0100 |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 192 | Subject: [PATCH 06/11] Do not include implicit installables with expr |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 193 | |
| 194 | --- |
| 195 | src/libcmd/command.hh | 2 +- |
| 196 | src/libcmd/installables.cc | 9 +++++---- |
| 197 | 2 files changed, 6 insertions(+), 5 deletions(-) |
| 198 | |
| 199 | diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh |
| 200 | index 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); |
| 212 | diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 213 | index e82103422bf..5c11c976299 100644 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 214 | --- a/src/libcmd/installables.cc |
| 215 | +++ b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 216 | @@ -763,7 +763,7 @@ FlakeRef InstallableFlake::nixpkgsFlakeRef() const |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 217 | } |
| 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 Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 225 | @@ -790,7 +790,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 226 | 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 Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 234 | @@ -837,8 +837,8 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 235 | state, *this, vFile, |
| 236 | prefix == "." ? "" : prefix, |
| 237 | outputsSpec)); |
| 238 | - return result; |
| 239 | } |
| 240 | + return result; |
| 241 | } |
| 242 | |
| 243 | for (auto & s : ss) { |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 244 | @@ -1132,11 +1132,12 @@ void InstallablesCommand::prepare() |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 245 | |
| 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 Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 259 | From 82904ee72f245f4b901f8f9b94c4e9caff2b53be Mon Sep 17 00:00:00 2001 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 260 | From: Skyler Grey <skyler3665@gmail.com> |
| 261 | Date: Fri, 22 Jul 2022 20:13:48 +0100 |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 262 | Subject: [PATCH 07/11] Allow running --expr purely again |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 263 | |
| 264 | --- |
| 265 | src/libcmd/installables.cc | 15 ++++++++------- |
| 266 | src/nix/nix.md | 2 -- |
| 267 | 2 files changed, 8 insertions(+), 9 deletions(-) |
| 268 | |
| 269 | diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 270 | index 5c11c976299..e54d4107353 100644 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 271 | --- a/src/libcmd/installables.cc |
| 272 | +++ b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 273 | @@ -776,7 +776,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 274 | 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 Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 282 | @@ -790,7 +790,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 283 | 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 Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 291 | @@ -806,7 +806,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 292 | |
| 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 Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 300 | @@ -814,10 +814,11 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 301 | 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(); |
| 316 | diff --git a/src/nix/nix.md b/src/nix/nix.md |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 317 | index 3491b38af23..2fdaf258643 100644 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 318 | --- a/src/nix/nix.md |
| 319 | +++ b/src/nix/nix.md |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 320 | @@ -144,8 +144,6 @@ the Nix store. Here are the recognised types of installables: |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 321 | # 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 Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 330 | From 60aeb420787c6276e26df6c73bd33d2a870590ef Mon Sep 17 00:00:00 2001 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 331 | From: Skyler Grey <skyler3665@gmail.com> |
| 332 | Date: Sat, 23 Jul 2022 11:46:07 +0100 |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 333 | Subject: [PATCH 08/11] Fix builtins.currentSystem in pure evaluation |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 334 | |
| 335 | --- |
| 336 | src/libcmd/installables.cc | 15 ++++++++++++--- |
| 337 | 1 file changed, 12 insertions(+), 3 deletions(-) |
| 338 | |
| 339 | diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 340 | index e54d4107353..95a31dba289 100644 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 341 | --- a/src/libcmd/installables.cc |
| 342 | +++ b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 343 | @@ -816,9 +816,18 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 344 | 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 Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 366 | From ed9400560c79657b9d7a2e2952fb4effc6453928 Mon Sep 17 00:00:00 2001 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 367 | From: Skyler Grey <skyler3665@gmail.com> |
| 368 | Date: Sun, 24 Jul 2022 01:30:00 +0100 |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 369 | Subject: [PATCH 09/11] Gracefully handle missing attributes |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 370 | |
| 371 | --- |
| 372 | src/libcmd/installables.cc | 2 +- |
| 373 | 1 file changed, 1 insertion(+), 1 deletion(-) |
| 374 | |
| 375 | diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 376 | index 95a31dba289..419fc90c96a 100644 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 377 | --- a/src/libcmd/installables.cc |
| 378 | +++ b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 379 | @@ -826,7 +826,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 380 | 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 Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 389 | From 3fba464fe76656d54136ab757fc7ede579254a4e Mon Sep 17 00:00:00 2001 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 390 | From: Skyler Grey <skyler3665@gmail.com> |
| 391 | Date: Sun, 24 Jul 2022 07:11:37 +0100 |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 392 | Subject: [PATCH 10/11] Fix including a flake without any attrpath |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 393 | |
| 394 | --- |
| 395 | src/libcmd/installables.cc | 2 +- |
| 396 | 1 file changed, 1 insertion(+), 1 deletion(-) |
| 397 | |
| 398 | diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 399 | index 419fc90c96a..bad324b424c 100644 |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 400 | --- a/src/libcmd/installables.cc |
| 401 | +++ b/src/libcmd/installables.cc |
Skyler Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 402 | @@ -826,7 +826,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( |
Skyler Grey | 5b75372 | 2022-08-26 07:53:33 +0100 | [diff] [blame] | 403 | 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 Grey | c767aa8 | 2023-02-24 09:04:17 +0000 | [diff] [blame] | 411 | |
| 412 | From 8ad1e705394a304db09935c207a964de33c02c08 Mon Sep 17 00:00:00 2001 |
| 413 | From: Skyler Grey <skyler3665@gmail.com> |
| 414 | Date: Fri, 24 Feb 2023 01:09:56 +0000 |
| 415 | Subject: [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 | |
| 421 | diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc |
| 422 | index 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; |