I want Understanding Nix Packages and Flake Basics

Hey everyone,

I am kind of new to the Nix ecosystem & I have been trying to wrap my head around how packages & flakes work together. I have been going through some of the docs but it is still a bit confusing when it comes to creating reproducible dev environments. I have used Docker before but Nix seems way more flexible.

I am just experimenting with some simple projects & trying to understand the flake.nix structure & how it connects with nix develop. Also, is there a clean way to manage Python packages using Nix without relying too heavily on virtual environments?

Any pointers, beginner-friendly resources or practical examples you have got would be super appreciated. Side note – I am doing some CCSP Training, so security-focused workflows in Nix would also be interesting to explore if anyone has experience with that. Also i have check this Understanding nix-channels, nix-env and nix-shell witch is good.

Thank you.:slight_smile:

Ignore flakes for now. Focus on understanding nix as a language the concept of a derivation, and how the language works in general. Realistically, First steps — nix.dev documentation is probably the best starting point

Python Usability

Until recently, this was a bit like asking for being able to program Spring Boot without having to follow Java patterns. Luckily, the Python ecosystem now has uv.

To cut the long story short, it’s likely that the notion of “virtual environment” will disappear in the near future. The PyCon US talk on the future of virtualenvs explains why: You’ll be using uv to run or install Python CLI tools or applications in one of the following ways:

  • uv tool install <package> (then run the tool via its name, e.g. ruff)
  • uvx <package> (e.g. uvx pyclean --help)
  • uv run <package> (after uv sync to install dependencies from a pyproject.toml file)

Python on NixOS

For a pythonic experience on NixOS, I recommend using nix-ld to tame library dependencies that Python packages may have and install both all Python versions (e.g. uv python install 3.13) and their Python packages using uv, exclusively.

  # Don't install Python system packages, only uv!
  environment.systemPackages = [ pkgs.uv ];
  # Allow dynamically linked executables to run (Python code using libraries)
  programs.nix-ld = {
    enable = true;
    libraries = options.programs.nix-ld.libraries.default ++ (
      with pkgs; [
        cairo
        dbus
        dbus-glib
        e2fsprogs
        flac
        fontconfig
        freetype
        fuse
        glib
        gtk2
        gtk3
        libelf
        libGL
        libjpeg
        libogg
        libpng
        libpq
        libtiff
        libva
        libvorbis
        libxkbcommon
        pipewire
        wayland
      ]
    );
  };

Read: You can’t mix and match NixOS system packages and Python packages installed from PyPI. Choose either the NixOS or the Python way. nix-ld allows you to stick with the latter.

Learning Nix(OS)

I fully agree and can confirm from personal experience. After embracing the Nix language NixOS configurations started to make sense all of a sudden!

I’ve written a blog post to explain Nix for people with a background from imperative languages, which you may find helpful. It includes links back to the official Nix documentation. Enjoy!

1 Like

I just want to say that article is AMAZING! I have been using NixOS for around 8 months but this article has cleared up so many things for me, thank you.

1 Like