linux nix nixos - ghdrako/doc_snipets GitHub Wiki

Shell

immediately use any program packaged with Nix, without installing it permanently

nix-shell with the -p (--packages) option to specify that we need
use package
exit
nix-shell -p hello
hello
exit

Search for packages

Enter the program name you want to run in search.nixos.org to find packages that provide it.

Running programs once

nix-shell -p cowsay --run "cowsay Nix"
nix-shell -p hello --run hello

Run any combination of programs

nix-shell -p git neovim nodejs

Nested shell

nix-shell -p hello
nix-shell -p socat
hello
socat
exit
exit

Create reproducibile shell env

nix-shell -p git --run "git --version" --pure -I nixpkgs=https://github.com/NixOS/nixpkgs/tarball/2a601aafdc5605a5133a2ca506a34a3a73377247

Reproducible interpreted scripts

$cat nixpkgs-releases.sh

#!/usr/bin/env nix-shell
#! nix-shell -i bash --pure
#! nix-shell -p bash cacert curl jq python3Packages.xmljson
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/2a601aafdc5605a5133a2ca506a34a3a73377247.tar.gz

curl https://github.com/NixOS/nixpkgs/releases.atom | xml2json | jq .
chmod +x nixpkgs-releases.sh
./nixpkgs-releases.sh