Document how to pass env vars to modern nix commands

Resolves #149.
This commit is contained in:
sandydoo 2023-05-04 08:41:47 +00:00
parent 763a380571
commit 840ed7ce9a
No known key found for this signature in database
GPG Key ID: D1A763BC84F34603

View File

@ -84,7 +84,7 @@ To install Nix from any commit, go to [the corresponding installer_test action](
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version' run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
``` ```
### How can I run NixOS tests? ### How do I run NixOS tests?
With the following inputs: With the following inputs:
@ -96,7 +96,7 @@ With the following inputs:
[Note that there's no hardware acceleration on GitHub Actions.](https://github.com/actions/virtual-environments/issues/183#issuecomment-610723516). [Note that there's no hardware acceleration on GitHub Actions.](https://github.com/actions/virtual-environments/issues/183#issuecomment-610723516).
### How can I install packages via nix-env from the specified `nix_path`? ### How do I install packages via nix-env from the specified `nix_path`?
``` ```
nix-env -i mypackage -f '<nixpkgs>' nix-env -i mypackage -f '<nixpkgs>'
@ -126,3 +126,23 @@ install-nix-action's own `extra_nix_config` input:
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
substituters = https://hydra.iohk.io https://cache.nixos.org/ substituters = https://hydra.iohk.io https://cache.nixos.org/
``` ```
### How do I pass environment variables to commands run with `nix develop` or `nix shell`?
Nix runs commands in a restricted environment by default, called `pure mode`.
In pure mode, environment variables are not passed through to improve the reproducibility of the shell.
You can use the `--keep / -k` flag to keep certain environment variables:
```yaml
- name: Run a command with nix develop
run: nix develop --ignore-environment --keep MY_ENV_VAR --command echo $MY_ENV_VAR
env:
MY_ENV_VAR: "hello world"
```
Or you can disable pure mode entirely with the `--impure` flag:
```
nix develop --impure
```