Learn to use Nix (not NixOS) in 10 minutes (it’s easy)

After this guide, you will be able to:

  • replace apt or pacman with the nixpkgs package repository, even if you don’t care about declarativity
  • use home-manager to set up all your configs and apps declaratively with just one config file and use it on any machine
  • use any nixpkgs package one time only and without bloat, fix dependency hell and weird dependencies

Why use nix

Nix is the biggest package repository, containing the freshest and the most packages as of today, and it also lets you declare all your settings in one config, saving you time. Also, Nix is not NixOS, and you don’t have to install NixOS to benefit from the nixpkgs repo. You can install Nix on any UNIX machine really. I personally use it on debian-12-minimal. The difference NixOS makes is that it allows you to configure not only your apps and their settings but all system settings too, but that’s outside the scope of my current guide. nix graph

Installation

Install Nix via the recommended multi-user installation:

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

Check the installation by opening a new terminal and typing:

$ nix --version
nix (Nix) 2.11.0

If you need more options, find them here

Install packages temporarily (nix-shell)

“Nix can be used to provide some kind of virtual environment through the nix-shell command.” This basically means you can install any package, and when you’re done with it, you can just exit the nix-shell, and it will be gone!

$ cowsay Hello       
sh: 4: cowsay: not found
$ nix-shell -p cowsay
<SNIP>
[nix-shell:~]$ cowsay hello!
 ________
< hello! >
 --------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

[nix-shell:~]$ exit
$ cowsay hello!
sh: 6: cowsay: not found

If you ask for the same package twice, it will pull it out of your cache instead of downloading it again. This is because when you exit nix-shell, the packages are not deleted and are stored on your machine. If you want to delete them from the cache, use:

$ nix-collect-garbage

To find out what packages you can download, use Nix Package Search

Install packages permanently using nix-env

It’s completely fine to use Nix as any other imperative package manager (apt, pacman) if you don’t need the benefits of declaring packages and settings using a single config file. In that case, use

$ nix-env -iA nixpkgs.<package name>

Example:

$ nix-env -iA nixpkgs.cowsay
installing 'cowsay-3.8.4'

This way, you can use nixpkgs the same way you likely used apt or pacman before.

If you don’t have access to the package after it was installed, this might happen because you don’t have the correct PATH. Fix it with:

export PATH="/nix/var/nix/profiles/default/bin:$HOME/.nix-profile/bin:$PATH"

and to make it persistent after reboots, put this line in your interactive shell script.

Example with bash

echo 'export PATH="/nix/var/nix/profiles/default/bin:$HOME/.nix-profile/bin:$PATH"' > ~/.bashrc

Make a config to configure and install packages (home-manager)

This will allow you to make changes in your system using a centralized config that you can carry around to any system. Firstly, get home-manager:

nix-shell -p home-manager

Now, we can enable flakes. This way, when we build our config the second time, flake.lock will make sure we are downloading the same packages we did when we built the config the first time and that their versions don’t shift and possibly break compatibility. To enable them:

mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" > ~/.config/nix/nix.conf

Then finally, make a default config file with the following:

[nix-shell:~]$ home-manager init
Creating /home/user/.config/home-manager/home.nix...
Creating /home/user/.config/home-manager/flake.nix...

Proceed to the home.nix folder, as it contains useful tips on configuring your environment. For now, we will just build it as is:

[nix-shell:~]$ home-manager switch
warning: creating lock file '"/home/user/.config/home-manager/flake.lock"':
• Added input 'home-manager':
    'github:nix-community/home-manager/34a13086148cbb3ae65a79f753eb451ce5cac3d3?narHash=sha256-mKYwYcO9RmA2AcAFIXGDBOw5iv/fbjw6adWvMbnfIuk%3D' (2025-06-03)
• Added input 'home-manager/nixpkgs':
    follows 'nixpkgs'
• Added input 'nixpkgs':
    'github:nixos/nixpkgs/c2a03962b8e24e669fb37b7df10e7c79531ff1a4?narHash=sha256-lcZQ8RhsmhsK8u7LIFsJhsLh/pzR9yZ8yqpTzyGdj%2BQ%3D' (2025-06-03)
Starting Home Manager activation
Activating checkFilesChanged
Activating checkLinkTargets
Activating writeBoundary
Creating new profile generation
Activating installPackages
installing 'home-manager-path'
building '/nix/store/5hmvci606lgn8n0d49phcmn0sair7zpn-user-environment.drv'...
Activating linkGeneration
Creating home file links in /home/user
Activating onFilesChange
Activating reloadSystemd

There are 226 unread and relevant news items.
Read them by running the command "home-manager news".

Teaching to make your own configs goes outside the scope of this introduction guide, but now you already can use other people’s configs and edit them for your own usage. Here’s an example of a ready-made config: https://nixos-and-flakes.thiscute.world/nixos-with-flakes/start-using-home-manager

Also, I believe this video is a good starting point for customizing your home.nix file and configuring home-manager. At 20:14 it includes a guide on installing specific versions of packages.

Conclusion

Submerging further into nix will help you:

  • build portable environments for your development purposes
  • create isolated environments by combining nix with docker
  • configure your entire system declaratively (with NixOS)
  • share identical development environments across your team

Further reading

First steps (this is where you should start)
Declarative shell environments with shell.nix
Nix language basics
Nix home-manager Manual