@@ -13,6 +13,7 @@ configured to integrate with Nix. Integration provides these benefits:
13
13
conflict with any existing versions of these libraries on your system. That
14
14
they are managed locally to the project means that you don't need to alter
15
15
your system in any way to build any odd project pulled from the Internet; and
16
+
16
17
* implicit sharing of system packages between projects. This means you don't
17
18
have more copies on-disk than you need.
18
19
@@ -317,12 +318,13 @@ configuration file (`stack.yaml`, by default).
317
318
## Pure and impure Nix shells
318
319
319
320
By default, Stack will run the build in a * pure* Nix build environment (or
320
- * shell* ), which means two important things:
321
+ * shell* ). Building in a pure Nix shell means:
322
+
323
+ 1 . with limited exceptions, ** no environment variable will be forwarded** from
324
+ your user session to the Nix shell (variables like ` HTTP_PROXY ` , ` PATH ` ,
325
+ ` STACK_XDG ` and ` STACK_ROOT ` notably will not be available); and
321
326
322
- 1 . basically ** no environment variable will be forwarded** from your user
323
- session to the nix-shell (variables like ` HTTP_PROXY ` or ` PATH ` notably will
324
- not be available); and
325
- 2 . the build should fail if you haven't specified all the dependencies in the
327
+ 2 . the build should fail if you have not specified all the dependencies in the
326
328
` packages: ` section of the Stack configuration file, even if these
327
329
dependencies are installed elsewhere on your system. This behaviour enforces
328
330
a complete description of the build environment to facilitate
@@ -339,6 +341,24 @@ nix:
339
341
340
342
The equivalent command line flag (which will prevail) is `--[no-]-nix-pure`.
341
343
344
+ To run the build in a *pure* Nix shell but preserve specific environment
345
+ variables use Nix's `nix-shell` command's `--keep` option. For example, to
346
+ preserve the [`STACK_XDG`](../configure/environment_variables.md#stack_xdg)
347
+ environment variable, add the following to your Stack YAML configuration file :
348
+
349
+ ~~~yaml
350
+ nix :
351
+ nix-shell-options :
352
+ - --keep
353
+ - STACK_XDG
354
+ ~~~
355
+
356
+ The equivalent command line option is :
357
+
358
+ ~~~text
359
+ --nix-shell-options "--keep STACK_XDG"
360
+ ~~~
361
+
342
362
** Note:** On macOS, shells are non-pure by default currently. This is due soon
343
363
to be resolved locale issues. So on macOS you'll need to be a bit more careful
344
364
to check that you really have listed all dependencies.
0 commit comments