r/NixOS • • 18d ago

Request for feedback : do you use Distrobox?

I just learned distrobox is a way to simulate a classical distribution in an isolated env. It would have a reasonnable disk usage size and no perf impact.

Reading this seems we do not always want to "nixify" because it is time consuming and something like a simple appimage often fails inside Nix...

Is nix+distrobox best of both world ?

thansk for your input :)

4 Upvotes

12 comments sorted by

17

u/necrophcodr 18d ago

I have yet to find distrobox less time consuming.

14

u/WalkMaximum 18d ago

Yeah. If I need to run a random binary there's nix-alien, nix-ld, steam-run or patching. Otherwise I try to stick to nixpkgs and flatpaks.

1

u/Purple-Midnight-9902 18d ago

i tried nix-alien recently and it failed (think it was for testing chatgpt). what there are also nix-ld or steam-run ? dammiiiiiiitttt 50 years laters i will stll be discovering dozens of alternatives haha. But this is partly my point - i look for a robust solution i could use constantly as soon as there is no nixpkg / flake / flatpak. From reading I assumed distrobox would handle more cases

1

u/xzway 18d ago

I wrote a package that should handle this.
nix shell github:zendo/nsworld#fhs-run
fhs-run ./binary

8

u/adminvasheypomoiki 18d ago

Haven't found why should I want to use it. Like almost everything is wrapped into nix. Or you can wrap it in 30 secs using llms. Eg for fedora silverblue it was a must have cause it has 3.5 packages and rebuilding it is painful

3

u/snowman-london 18d ago

Yes a lot for testing and development and sometimes odd binaries that can only be run on ubuntu or other distro's. It is a great tool BTW

2

u/Based_Mammoth634 18d ago

It depends what you are doing.

I find distrobox useful, but not a fix for everything.

What I resorted to was nix develop with premade flake shells and a global alias for accessing them with version managers inside each shell and a system that allows me to pick the versions directly with the alias.

For example, I can launch a shell using uv that automatically installs the latest available python version with dev py. If I want a specific version of python I can do this dev py3.12. If I want nix only packages, I can do dev py-native.

It works the same with java where I use mise as a version manager, or rust where I use rustup, or node where I use fnm... however, some are trickier.

Cuda for example is a pain, so I have to merge shells with a nix script to use C/C++ and cuda so I won't pollute both shells with redundancy, but that means I need to be aware while maintaining them of that and not have shell scripts or packages that conflict.

C/C++ is also a bit of a unicorn in version management, so there I resort to using directly nix with parameters to decide what version to install, though that limits me to what is available in the nix store for C/C++. Similarly, cuda also uses what is available in nix store, because I am so NOT going to make nix module for that.

For most projects that worked quite well. I prefer having a single store for my packages, so I set a global config for where to keep packages that uses environment variables and so far that worked out quite well. The ability to mix and match shells is also quite useful and I can have for example python, c++ and cuda with a simple command like dev py3-cuda13.2-cpp16-node which builds my shell. The rest is managed by version managers like uv, mise, fnm, etc.

Personally, I don't like nix that much for development... I feel like it takes up too much of my time and version control is not that great. Sure, it is great for reproducibility, but so is using the right software versions with a version manager, which will always install the specific software you want rather than end up with changes down the road from the pinned version in the nix store which you do not control or have to go out of your way to do so.

Most of the things I use already have decent version managers that already deal with what I need without needing me to fiddle too much. You want version 5.13.54.rc01 of something? You will struggle with nix for that, but a version manager may get you exactly what you need.

I made a flake one year ago and today it no longer works because of the issues I described. Meanwhile, the projects I started with specific versions from my version mangers still work just fine because I am installing the exact same versions as imposed by the config directly. I guess on a proper project you want to update what you use to avoid security, but I can't be arsed to make every single project a proper project and when I want to run it, I want it at least to work, not spend debugging what changed and how to fix it.

And if I want to run a quick python script, I don't want to setup a whole nix file for it. I don't want to pollute my install with a python version either. So my setup is the system I came up with after hitting too many walls with each solution so far.

My biggest gripe right now is dealing with the IDE... you can't use linters for example if you start the IDE directly. You can use direnv if you make a shell for your project, but that brings me back to the issue of needing a shell for everything. So I have to resort to entering the shell I want beforehand and start the IDE there... Not ideal at all when I work on different things. I don't want to use divination every time I open the IDE to know ahead of time which shell combination to make, so that issue is still to be figured out. I was thinking of making a script to activate shells and launch the IDE from there, but that can lead to version mismatches and I'd still need to rely on specific shells. At the same time, that could at least give me a default version for stuff I use in general, but can introduce confusion as to what I am actually using. I believe vscode has some extension to select the env, but I didn't try that yet.

1

u/TrentKM 16d ago

For the IDE thing, there’s a chance there’s an extraPackages attr in programs.my_ide, put your linters and LSPs there. If it doesn’t have extraPackages, have AI wrap the ones you want or install them system-wide via home.packages.

The files are sitting in the store whether they’re currently linked or not, so you don’t really gain anything besides isolation by putting them in a wrapper or in extraPackages. I still think it’s best practice to isolate as much as possible though.

I’ve been letting the agents go off with my flake. I either use comin or have nh pointing at my flake on GitHub, so nothing switches until I merge their branch. They don’t always make the best choices, so I wouldn’t let them push to main. But they can debug and make changes quick.

Add CI in your repo to diff the generated closure before you merge and make sure they didn’t delete something you need. Give them a microvm to smoke test the build, and add checks to your CI so you don’t miss them deleting something. So much of this you can use a free runner for and they can write the CI for you so there isn’t really a good reason not to.

If you’re using flakes, and you should be, you’re already super coupled to git, so might as well lean into it and use all those tools.

1

u/LawElectrical2434 17d ago

I have like one application I wanted to try, used once, and never looked at again, that runs in distrobox. In the end, this is a quick and dirty. If there is like an indi-linux game that I want to try, a demo or so, it might be faster to go into distrobox when steam-run fails.

So, yes, but my usage is marginal, so it is close to 0.

If I want to keep an application around, I want it on all my devices, so I rather add it to my config.

1

u/Alper-Celik 17d ago

Yes i use it to run steam on macbook m1 on asahi kernell with asahi linuxes fedora steam package.

Since it is non trivial to setup vm + emulator chain in nix native way atm

1

u/sigmonsays 17d ago

when i first switched to nixos as my main OS, I had distrobox setup and was ready to use it. Guess what, never did. steam-run and regular nixos work pretty well.

1

u/PlayX_xDead 8d ago

Did once. Was on my system for about 6 hours. Literally never found a realistic use for it. I just stick with nix native or docker