Skip to content

Commit cd6dce4

Browse files
committed
Re #6688 Document ability to --keep STACK_XDG with 'pure' Nix
1 parent bc89ff0 commit cd6dce4

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

doc/configure/environment_variables.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
The environment variables listed in alphabetal order below can affect how Stack
66
behaves.
77

8+
If using Stack's
9+
[Nix integration](../topics/nix_integration.md#pure-and-impure-nix-shells) and a
10+
*pure* Nix build environment (or *shell*), by default, these environment
11+
variables will not be forwarded from your user session to the Nix shell.
12+
However, the Nix shell can be configured to keep specific environment variables.
13+
814
## `GH_TOKEN` or `GITHUB_TOKEN`
915

1016
[:octicons-tag-24: 2.11.1](https://github.com/commercialhaskell/stack/releases/tag/v2.11.1)

doc/topics/nix_integration.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ configured to integrate with Nix. Integration provides these benefits:
1313
conflict with any existing versions of these libraries on your system. That
1414
they are managed locally to the project means that you don't need to alter
1515
your system in any way to build any odd project pulled from the Internet; and
16+
1617
* implicit sharing of system packages between projects. This means you don't
1718
have more copies on-disk than you need.
1819

@@ -317,12 +318,13 @@ configuration file (`stack.yaml`, by default).
317318
## Pure and impure Nix shells
318319

319320
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
321326

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
326328
`packages:` section of the Stack configuration file, even if these
327329
dependencies are installed elsewhere on your system. This behaviour enforces
328330
a complete description of the build environment to facilitate
@@ -339,6 +341,24 @@ nix:
339341

340342
The equivalent command line flag (which will prevail) is `--[no-]-nix-pure`.
341343

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+
342362
**Note:** On macOS, shells are non-pure by default currently. This is due soon
343363
to be resolved locale issues. So on macOS you'll need to be a bit more careful
344364
to check that you really have listed all dependencies.

0 commit comments

Comments
 (0)