Skip to content

Commit

Permalink
Use nix-shell --pure to avoid running externally installed tools
Browse files Browse the repository at this point in the history
  • Loading branch information
noamraph committed Apr 12, 2024
1 parent 11f9dce commit 7e1acc8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pills/10-developing-with-nix-shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ Recall that in a nix environment, we don't have access to libraries or programs
We can call `nix-shell` on any Nix expression which returns a derivation, but the resulting `bash` shell's `PATH` does not have the utilities we want:

```console
$ nix-shell hello.nix
$ nix-shell --pure hello.nix
[nix-shell]$ make
bash: make: command not found
[nix-shell]$ echo $baseInputs
/nix/store/jff4a6zqi0yrladx3kwy4v6844s3swpc-gnutar-1.27.1 [...]
```

(`--pure` asks `nix-shell` to remove most environment variables before running the shell. Without adding it, `make` might work, but it will be taken from your environment, so it might have a different behavior during build.)

This shell is rather useless. It would be reasonable to expect that the GNU `hello` build inputs are available in `PATH`, including GNU `make`, but this is not the case.

However, we do have the environment variables that we set in the derivation, like `$baseInputs`, `$buildInputs`, `$src`, and so on.
Expand Down Expand Up @@ -154,7 +156,7 @@ mkDerivation {
Now back to nix-shell:

```console
$ nix-shell hello.nix
$ nix-shell --pure hello.nix
[nix-shell]$ source $setup
[nix-shell]$
```
Expand Down

0 comments on commit 7e1acc8

Please sign in to comment.