mirror of
https://github.com/NixOS/nix-pills
synced 2024-09-19 04:00:13 -04:00
Use nix-shell --pure
to avoid running externally installed tools
This commit is contained in:
parent
11f9dce51f
commit
7e1acc8877
|
@ -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:
|
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
|
```console
|
||||||
$ nix-shell hello.nix
|
$ nix-shell --pure hello.nix
|
||||||
[nix-shell]$ make
|
[nix-shell]$ make
|
||||||
bash: make: command not found
|
bash: make: command not found
|
||||||
[nix-shell]$ echo $baseInputs
|
[nix-shell]$ echo $baseInputs
|
||||||
/nix/store/jff4a6zqi0yrladx3kwy4v6844s3swpc-gnutar-1.27.1 [...]
|
/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.
|
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.
|
However, we do have the environment variables that we set in the derivation, like `$baseInputs`, `$buildInputs`, `$src`, and so on.
|
||||||
|
@ -154,7 +156,7 @@ mkDerivation {
|
||||||
Now back to nix-shell:
|
Now back to nix-shell:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ nix-shell hello.nix
|
$ nix-shell --pure hello.nix
|
||||||
[nix-shell]$ source $setup
|
[nix-shell]$ source $setup
|
||||||
[nix-shell]$
|
[nix-shell]$
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in a new issue