Skip to content

Commit 3eb7a24

Browse files
authored
Merge pull request #178 from cachix/docs/149
Document how to pass env vars to modern nix commands
2 parents e304541 + 840ed7c commit 3eb7a24

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ To install Nix from any commit, go to [the corresponding installer_test action](
8484
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
8585
```
8686

87-
### How can I run NixOS tests?
87+
### How do I run NixOS tests?
8888

8989
With the following inputs:
9090

@@ -96,7 +96,7 @@ With the following inputs:
9696

9797
[Note that there's no hardware acceleration on GitHub Actions.](https://github.com/actions/virtual-environments/issues/183#issuecomment-610723516).
9898

99-
### How can I install packages via nix-env from the specified `nix_path`?
99+
### How do I install packages via nix-env from the specified `nix_path`?
100100

101101
```
102102
nix-env -i mypackage -f '<nixpkgs>'
@@ -126,3 +126,23 @@ install-nix-action's own `extra_nix_config` input:
126126
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
127127
substituters = https://hydra.iohk.io https://cache.nixos.org/
128128
```
129+
130+
### How do I pass environment variables to commands run with `nix develop` or `nix shell`?
131+
132+
Nix runs commands in a restricted environment by default, called `pure mode`.
133+
In pure mode, environment variables are not passed through to improve the reproducibility of the shell.
134+
135+
You can use the `--keep / -k` flag to keep certain environment variables:
136+
137+
```yaml
138+
- name: Run a command with nix develop
139+
run: nix develop --ignore-environment --keep MY_ENV_VAR --command echo $MY_ENV_VAR
140+
env:
141+
MY_ENV_VAR: "hello world"
142+
```
143+
144+
Or you can disable pure mode entirely with the `--impure` flag:
145+
146+
```
147+
nix develop --impure
148+
```

0 commit comments

Comments
 (0)