What are the values on the left inside Nix expressions? Let's find out!
Create a file named shell.nix
.
Paste the following into it:
# shell.nix
{ nixpkgs ? import <nixpkgs> { } }:
let pkgs = [];
in nixpkgs.stdenv.mkDerivation {
name = "env";
buildInputs = pkgs;
LOCALE_ARCHIVE = "/usr/lib/locale/locale-archive";
libgpiod_dir = builtins.fetchGit {
url = "git://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git";
ref = "master";
};
}
Next, run nix-shell
and observe, what happens to env variable named libgpiod_dir
:
â ~ nix-shell
[nix-shell:~]$ echo $libgpiod_dir
/nix/store/macpk6l9c44j84791i27n0d1xc327wlh-source
[nix-shell:~]$ ls $libgpiod_dir
autogen.sh COPYING lib man tests
bindings Doxyfile.in LICENSES NEWS TODO
configure.ac include Makefile.am README tools
Exit the shell inside the Nix environment with [Ctrl] + [D], or by typing exit
.
Check if variable libgpiod_dir
is still set:
â ~ echo $libgpiod_dir
It is not!
In this experiment, the value of libgpiod_dir
was propagated from Nix to the shell as an environment variable. It contained the path to the resource we requested creation of on the right - a repo downloaded [1] using builtins.fetchGit
.
Note: It was not cloned. If you do
git status
inside it, you'll find it doesn't contain Git metadata. âŠī¸