Nix Shell
You can use Nix packages without installing them globally on your machine. This is a good way to bring in the tools you need for individual projects.
$ nix-shell -p hello
[nix-shell:nix-workshop]$ hello
Hello, world!
Using Multiple Packages
$ nix-shell -p python3 htop vim
[nix-shell:nix-workshop]$ which python3
/nix/store/qp5zys77biz7imbk6yy85q5pdv7qk84j-python3-3.11.6/bin/python3
[nix-shell:nix-workshop]$ which htop
/nix/store/i4af69js47rqcym6j6y83nxj58ihsi96-htop-3.2.2/bin/htop
[nix-shell:nix-workshop]$ which vim
/nix/store/jiixxdyqlaalxzzs0nzhpprgy6rx2bxg-vim-9.0.2048/bin/vim
Using shell.nix
It is common practice for Nix-using projects to provide a shell.nix
file that specifies the shell environment. The nix-shell
command reads this file, allowing us to create reproducible shell environments without using -p
. These environments can provide access to any tool written in any language, without polluting the global environment. We will cover the use of shell.nix
in a later chapter.