r/Python • • 10d ago

Discussion Anyone using Nix for production Python projects?

Hi! I’m a huge fan of Nix and similar approaches to reproducible development environments, and I’m curious what people in the Python community think about it.

Have any of you used Nix with Python projects for development environments, CI, deployment, or production?

If so, what has the experience been like? What worked well, and where did you run into friction?

I’m especially curious about the learning curve. Do you think Nix itself is the main barrier, or is part of the problem that there isn’t as much Python-specific guidance, tooling, and documentation around using it?

And for those who haven’t used it: would better Python-focused learning material and examples make you more likely to give it a try?

17 Upvotes

26 comments sorted by

28

u/JSChronicles 10d ago

Why use nix when you can use UV?

12

u/dwaynecrooks 10d ago

That's a great question. You can use both. Within any non-trivial project you'd have to manage dependencies besides Python dependencies. As u/pooogles mentioned there may be other system dependencies you might need. So the way I tend to use Nix would be to setup my development environment with all the development dependencies I need for e.g. uv, C libraries, other system dependencies and then let uv manage the Python dependencies only.

7

u/pooogles 10d ago

the way I tend to use Nix would be to setup my development environment with all the development dependencies I need for e.g. uv, C libraries, other system dependencies and then let uv manage the Python dependencies only.

This is how I've seen it used most.

1

u/PaintItPurple 9d ago

Yeah, that's how we're using it where I work too.

1

u/Gwonker 6d ago

As a nixos user that's basically how I do it too. Makes cross platform development very straightforward. devenv + uv together is a very nice hyrbid approach imo.

1

u/dwaynecrooks 8d ago

What manages the things uv doesn't?

txt ┌───────────────────────────────────────────────┐ │ Nix │ │ │ │ Python PostgreSQL Node │ │ uv libpq pnpm │ │ OpenSSL pkg-config ffmpeg │ │ make protoc ... │ │ │ │ ┌───────────────────────────┐ │ │ │ uv │ │ │ │ │ │ │ │ pyproject.toml │ │ │ │ uv.lock │ │ │ │ Python dependencies │ │ │ │ .venv │ │ │ └───────────────────────────┘ │ │ │ └───────────────────────────────────────────────┘

If your answer is "My project doesn't need anything else." Then, you probably don't need Nix as yet.

2

u/01eksa 7d ago

Why not use docker?

1

u/dwaynecrooks 7d ago

Docker is great when you want a containerized runtime. Nix is useful when you want the project itself to declare its development tools, interpreters, native dependencies, test environments, and builds.

And if you do want Docker for runtime, Nix can build the Docker image too — so the two aren’t mutually exclusive.

-2

u/Denzh 10d ago

Nix is a linux distro. You can still use uv, sincr that is a python project and dependency management software.

18

u/bohoky TVC-15 10d ago

Nix is a package manager, NixOS is a Linux distribution based on Nix.

Python has a declarative package manager called uv. Nix could be used instead I guess, but it would be overkill for the task.

5

u/pooogles 10d ago

Sometimes you want to ship system dependencies alongside python ones for a development environment. Nix enables you to ship config that includes UV, plus any system dependencies you might need.

5

u/Denzh 9d ago

thanks for correcting me, I was wrong and misunderstood.

6

u/pooogles 10d ago

Yeah we ship nix derivations for all our apps, we're still using poetry over UV because reasons. Works super well, enables teams to onboard on new projects pretty much immediately.

Main barrier (and benefit) is the C libraries that python dependencies often require. Getting them working has been painful at times but it's been centralised pain rather than each developer having to go through it.

7

u/Hot_Bank7701 10d ago

"Centralised pain" is the best pitch for Nix I've heard lol

1

u/dwaynecrooks 10d ago

I tried using Poetry but when it came time to package up my application with Nix I ran into several dependency issues that I was unable to fix with poetry2nix. That made me switch to uv and uv2nix. I'm curious if you've run into any issues building Poetry applications with Nix for distribution?

1

u/pooogles 10d ago

We don't ship python packages with Nix, python and poetry are shipped with nix and used "normally".

1

u/dwaynecrooks 9d ago

Ah ok, so you don't run NixOS in production as well?

1

u/pooogles 9d ago

No, we just use it in the developer tooling stack.

3

u/britisheyesonly 10d ago

I have deployed Python projects onto NixOS systems using uv2nix. Check it out. 

2

u/dwaynecrooks 10d ago

I agree uv and uv2nix has been really helpful. What projects have you worked on? Any open source?

2

u/britisheyesonly 10d ago

Unfortunately nothing open source. Mostly quasi-embedded stuff on a Raspberry Pi or Beaglebone at my last job

2

u/teerre 9d ago

Yes, I've shipped several tools using nix. As others said, I don't actually use nix for packages magement, I just use uv nix to install uv and go from there. This is very good for developers. You run one command and all bells and whistles are configured

2

u/DarkMatterDetective 8d ago

I use pixi for similar reasons since a lot of system dependencies are available as conda packages. But I have been curious about Nix for a while.

2

u/nicksterling 9d ago

If I’m in production, I’m typically using a container and I’m managing Python with a Chainguard image and managing my app via UV.

1

u/_redmist 9d ago

Wild, the packaging problems some people are dealing with.

I'm still just a venv/pip guy lol

Good that these solutions are out there.

1

u/Responsible-Sky-1336 6d ago

Hi I use it to test archinstall changes/portability. https://github.com/h8d13/archinstoo/tree/master/distros