Nix (package manager)

The Nix logo

Nix is “purely functional package manager”. It manages sets of packages as immutable data structures so each particular environment has no dependencies from the outside world. This property makes it possible to have many versions of any piece of software simultaneously. You can even try to modify any particular environment and then roll it back. Any set of packages one can describe using “the Nix language” by writing a declarative program. Execution of this program with the Nix package manager will reproduce the described environment, and that is very convenient for development as for the deployment.

There is a /Linux distribution NixOS which uses Nix as a system package manager. And one can configure the whole system with a single declarative program.

Resources

And of course, one should take a look into the official documentation. There are described many aspects of using Nix with different toolchains, (/Python for example is mentioned here). The “Developing Python with Poetry & Poetry2nix” is also a good entry point to Nix for the Python users.

Additional tools

  • nix-tree, “Interactively browse the dependency graph of your Nix derivations.”
  • nix-script, that “lets you write quick scripts in compiled languages, tranparently compile and cache them, and pull in whatever dependencies you need from the Nix ecosystem.” (see an article)

Nix Flakes

Nix Flakes are an upcoming feature of the Nix package manager.

Series of posts in the Tweag.io blog: - “Nix Flakes, Part 1: An introduction and tutorial” - “Nix Flakes, Part 2: Evaluation caching” - “Nix Flakes, Part 3: Managing NixOS systems”

Tips

Subprocesses

If you are using some app that run other apps as subprocesses (like /Rofi) then beware: all the subprocesses will run inside the same nix env.

For example, rofi depends on the Gtk and runs any apps inside the env with this particular version of Gtk. For me it breaks any Gtk-based apps those I run from the rofi!

How much

This command shows how many space will “eat” a particular package:

nix-env --dry-run -iA nixpkgs.gimp

Profile update

nix-env -iA nixpkgs.myPackages && nix-collect-garbage

With -r it will remove all the packages that aren’t mentioned in your myPackages.

Locales

By default there are no locales will be installed with glibc and some software won’t work after installation. Here is a workaround:

  1. Install glibcLocales:

    $ nix-env -iA nixpkgs.glibcLocales
  2. Configure the environment:

    if [ -f "$HOME/.nix-profile/lib/locale/locale-archive" ]; then
        export LOCALE_ARCHIVE="$HOME/.nix-profile/lib/locale/locale-archive"
    fi

“Why”

nix-tree can tell why this or that package was installed.