You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/posts/guides/nix-shells.md
+14-14Lines changed: 14 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -49,16 +49,16 @@ To make this process even easier, `nix develop` now comes with special arguments
49
49
50
50
This allows to _run phases_ individually in the shell using `$ unpackPhase`, `$ configurePhase` `$ buildPhase`, etc.
51
51
52
-
...or directly using `nix develop --<PHASE>` or `nix develop --phase PHASE` (for non-standard phases).
52
+
...or directly using `nix develop \--<PHASE>` or `nix develop \--phase PHASE` (for non-standard phases).
53
53
54
-
...or run an arbitrary command in the shell using `nix develop --command COMMAND [ARGS...]`
54
+
...or run an arbitrary command in the shell using `nix develop \--command COMMAND [ARGS...]`
55
55
56
56
**Why should you use this?**
57
57
58
58
It is most useful for locally developed packages.
59
59
60
60
Use it to set up the environment using e.g. the `configurePhase` and perform the subsequent development using `build` and `check` phases.
61
-
If your workflow includes things that are not part of a phase use `nix develop --command`
61
+
If your workflow includes things that are not part of a phase use `nix develop \--command`
62
62
:::
63
63
64
64
In essence, this is exactly what `nix-shell` was intended for!
@@ -70,7 +70,7 @@ As the default implementation in nix's `stdenv` is done as functions, an interna
70
70
71
71
**Solution**
72
72
73
-
Enter a shell using `nix develop` and run the overridden phases using `eval \$buildPhase` or `--command eval '\$buildPhase'`.
73
+
Enter a shell using `nix develop` and run the overridden phases using `eval \$buildPhase` or `\--command eval '\$buildPhase'`.
74
74
75
75
:::
76
76
@@ -216,7 +216,7 @@ This is useful to install temporary software
216
216
217
217
...from a [flake specifier](../../internals/2021-01-01-flake-ification/#flake-reference-conventions).
218
218
219
-
...from a `*.nix` file/arbitrary expression using `--impure --expr EXPR` flags
219
+
...from a `*.nix` file/arbitrary expression using `\--impure \--expr EXPR` flags
220
220
221
221
**Why should you use this?**
222
222
@@ -235,11 +235,11 @@ Notably, not mentioned here is the use of `nix shell` to load `FANCYLANGUAGE` wi
235
235
236
236
Apart from dropping into development shells, `nix-shell` can also be used to run commands and programs from derivation not currently installed to the user's profile. This is it can build a shell as before and run a command inside transparently.
237
237
238
-
We discussed the use of `nix-shell --command COMMAND ARGS` above, where we would run a command from within the build environment of a derivation. Similarly, we may want to just run a program provided by a derivation. For this `nix-shell` provided the `--run` argument
238
+
We discussed the use of `nix-shell \--command COMMAND ARGS` above, where we would run a command from within the build environment of a derivation. Similarly, we may want to just run a program provided by a derivation. For this `nix-shell` provided the `\--run` argument
239
239
240
-
:::{.info header="\"`--command`\" vs \"`run`\""}
240
+
:::{.info header="\"`\--command`\" vs \"`run`\""}
241
241
242
-
As a development aid, `--command` is interactive, meaning among other things, that *if a command fails or is interrupted by the user, the user is dropped into the shell with the build environment loaded*.
242
+
As a development aid, `\--command` is interactive, meaning among other things, that *if a command fails or is interrupted by the user, the user is dropped into the shell with the build environment loaded*.
243
243
244
244
This behavior translates into an invocation using the `-p PROGRAM` argument as well as seen in the following box.
245
245
@@ -257,7 +257,7 @@ Man page: asciidoc --help manpage
257
257
Syntax: asciidoc --help syntax
258
258
```
259
259
260
-
`--run`runs non-interactive and closes the shell after the command returns
260
+
`\--run`runs non-interactive and closes the shell after the command returns
261
261
```bash
262
262
$ asciidoc
263
263
zsh: command not found: asciidoc
@@ -277,19 +277,19 @@ zsh: command not found: asciidoc
277
277
278
278
As the functions of `nix-shell DERIVATION` and `nix-shell -p DERIVATION` were separated, the new tools come with new clearer semantics.
279
279
280
-
The generic `nix-shell --run` function is now `nix shell -c`. Given an installable, nix allows to run any command in an environment where the installable is present. Note that this command is run in a non-interactive shell. The shell is dropped as the command ends.
280
+
The generic `nix-shell \--run` function is now `nix shell -c`. Given an installable, nix allows to run any command in an environment where the installable is present. Note that this command is run in a non-interactive shell. The shell is dropped as the command ends.
281
281
282
282
:::{.info}
283
283
The above example using the new command would look like this:
284
284
285
285
```
286
-
$ nix shell -c nixpkgs#asciidoc -c asciidoc
286
+
$ nix shell nixpkgs#asciidoc -c asciidoc
287
287
```
288
288
:::
289
289
290
290
### `nix run`
291
291
292
-
Yet, `nix shell -c` will still require to type the name of the executed program. As for most programs this command is the same as the derivation name e.g. `nix shell -c nixpkgs#asciidoc -c asciidoc` another command was introduced named `nix run`. With `nix run` the previous command can be run as `nix run nixpkgs#asciidoc`.
292
+
Yet, `nix shell -c` will still require to type the name of the executed program. As for most programs this command is the same as the derivation name e.g. `nix shell nixpkgs#asciidoc -c asciidoc` another command was introduced named `nix run`. With `nix run` the previous command can be run as `nix run nixpkgs#asciidoc`.
293
293
294
294
Naturally, the functionality of `nix run` goes further and as is the case for many other new commands mainly concerns flakes. Next to `packages`, `nixosModules` and others, flakes can now also define `apps`. Written as records with two fields -`type` (currently, necessarily `app`) and `program` (an executable path) - these apps can be run directly using `nix run`.
295
295
@@ -371,7 +371,7 @@ As it stands this function does not [yet](https://github.com/NixOS/nix/pull/5189
371
371
372
372
## To flake or not to flake
373
373
374
-
Most of the new nix commands are designed in a flake first way. Most notably `nix {shell,develop,run}` expect [flake URLs](../internals/2021-01-01-flake-ification/#flake-reference-conventions) as argument. Traditional `*.nix` files can be used with the `--expr` argument all commands support. As flake mode imposes greater purity strictness, imports have to happen with the `--impure` flag given:
374
+
Most of the new nix commands are designed in a flake first way. Most notably `nix {shell,develop,run}` expect [flake URLs](../internals/2021-01-01-flake-ification/#flake-reference-conventions) as argument. Traditional `*.nix` files can be used with the `\--expr` argument all commands support. As flake mode imposes greater purity strictness, imports have to happen with the `\--impure` flag given:
375
375
376
376
```sh
377
377
$ nix shell --impure --expr "import my.nix {}"
@@ -431,5 +431,5 @@ Being so closely named to its _semantically different_ predecessor, it is imposs
431
431
| **runs `shellHook`s** | yes | yes | no | no |
432
432
| **use as interpreter** | yes | no | no | no |
433
433
| **supports flakes** | no | yes | yes | only |
434
-
| **evaluate nix file** | yes | with `--impure`, `-f` or `--expr` | with `--impure`, `-f` or `--expr` | with `--impure`, `-f` or `--expr` |
434
+
| **evaluate nix file** | yes | with `\--impure`, `-f` or `\--expr` | with `\--impure`, `-f` or `\--expr` | with `\--impure`, `-f` or `\--expr` |
435
435
| **modifies environment** | `PATH`, attributes mk`mkDerivation` and changes by `shellHooks` | `PATH`, attributes mk`mkDerivation` and changes by `shellHooks` | `PATH` | *nothing* |
Copy file name to clipboardExpand all lines: src/posts/internals/2020-04-10-built-with-nix.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -315,7 +315,7 @@ Snapshots like these also allow rollbacks as they define which versions of depen
315
315
316
316
Nix has some integration with GitHub Actions through [install-nix](https://github.com/marketplace/actions/install-nix), an action that **installs nix** •_•
317
317
318
-
With nix installed, I run `$(nix-build -A ci.compile --no-out-link)` to make Nix build the blog generator and rebuild the blog's content into `build/site`. This works because `nix-build --no-out-link` will just print the path of the resulting package to `stdout`, which in this case is only an executable script produced by the `script` function above. The next step is to take that content and push it to the deployment branch.
318
+
With nix installed, I run `$(nix-build -A ci.compile \--no-out-link)` to make Nix build the blog generator and rebuild the blog's content into `build/site`. This works because `nix-build \--no-out-link` will just print the path of the resulting package to `stdout`, which in this case is only an executable script produced by the `script` function above. The next step is to take that content and push it to the deployment branch.
Copy file name to clipboardExpand all lines: src/posts/internals/2021-01-01-flake-ification.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -295,7 +295,7 @@ To take this apart again, we face three different sections here.
295
295
1. `flake-utils.lib.eachDefaultSystem`, like its name suggests will provide the attribute set in its scope for all default systems (basically linux and darwin on x86_64 hardware). Hence, we don't need to worry about these tags.
296
296
2. The actual output still needs to conform to flakes' expected attributes. In this case we set `packages`, `defaultPackage`, `apps`, `defaultApp` and `devShell`. There are even more most importantly `overlay` which are referenced [below](#output-attributes)
297
297
3. third one is the middle part and shows an important aspect of nix flakes.
298
-
Because there is no access to impure variables (`--arg`, environment variables, the current system, etc.), `nixpkgs` must be imported explicitly for each system. Additionally, this gives the opportunity to apply any possible overlay.
298
+
Because there is no access to impure variables (`\--arg`, environment variables, the current system, etc.), `nixpkgs` must be imported explicitly for each system. Additionally, this gives the opportunity to apply any possible overlay.
299
299
In the case of this blog everything is defined in an external `blog.nix` file and imported from there.
300
300
301
301
### Output attributes
@@ -334,7 +334,7 @@ is possible to use.
334
334
*Notice* that some inputs might need to be quoted due to substitution rules in your shell.
335
335
:::
336
336
337
-
`apps`is used together with `nix run`, similarly to `npm run`. You can define binaries that can then be run directly without explicitly building them first. This allowed me to change the somewhat cryptic `$(nix-build -A packages.x86_64-linux.ci.compile --no-out-link)` to `nix run ./#compile` in the CI script. Actually given that `defaultApp` point to the same `compile` attribute, the argument `./#compile` could be elided paying with decreased clarity.
337
+
`apps`is used together with `nix run`, similarly to `npm run`. You can define binaries that can then be run directly without explicitly building them first. This allowed me to change the somewhat cryptic `$(nix-build -A packages.x86_64-linux.ci.compile \--no-out-link)` to `nix run ./#compile` in the CI script. Actually given that `defaultApp` point to the same `compile` attribute, the argument `./#compile` could be elided paying with decreased clarity.
338
338
339
339
`devShell`is another special one used in combination with `nix develop` which opens a *`bash`* shell with the given derivation prepared.
0 commit comments