img

Installation

curl -L https://nixos.org/nix/install | sh -s -- --daemon

On Arch Linux, you can alternatively install Nix through pacman.

Verify installation

Check the installation by opening a new terminal and typing:

nix --version
nix (Nix) 2.11.0

Nix Package Manager Commands

DescriptionCommandExample
Searching for pkgsnix search nixpkgs packagenamenix --extra-experimental-features "nix-command flakes" search nixpkgs firefox
List all Installed Pkgsnix-env -q-
Query Installed pkgsnix-env -q search_termnix-env -q librewolf
Query Available pkgsnix-env -qa search_termnix-env -qa calibre
Installing pkgsnix-env -iA nixpkgs.pkg_namenix-env -iA nixpkgs.sakura
Installing pkg from urlnix-env -i pkg_name --file example.comnix-env --file https://github.com/NixOS/nixpkgs/archive/nixos-14.12.tar.gz --install --attr firefox<br>
Upgrade single pkgnix-env -u pkg_namenix-env -u librewolf
Upgrade All pkgnix-env -u-
Uninstall a pkgnix-env -e pkg_namenix-env -e sakura

Installed binaries are stored in ~/.nix-profile/bin

Generations Commands

DescriptionCommand
list generationsnix-env --list-generations
switch generationsnix-env --switch-generation 50
delete generationnix-env --delete-generations old
delete specific generationsnix-env --delete-generations 10 11 14
delete generation older than specific number of daysnix-env --delete-generations 14d

Garbage Collection (cleanup)

After removing appropriate old generations you can run the garbage collector as follows:
nix-store --gc

If you are feeling uncertain, you can also first view what files would be deleted:

nix-store --gc --print-dead

Likewise, the option --print-live will show the paths that won’t be deleted.

There is also a convenient little utility nix-collect-garbage, which when invoked with the -d (--delete-old) switch deletes all old generations of all profiles in /nix/var/nix/profiles. So

 nix-collect-garbage -d

is a quick and easy way to clean up your system.