I’m trying out NixOS, and I see a lot of people saying not to use nix-env to install packages (example: Stop using nix-env). Is there another cli alternative I should use? I’d much rather have a cli interface than manually edit the configuration file myself.
The text says it already:
nix standalone command.
What precisely do you want/need?
Why are you afraid of editing files, after all?
Nix is not very suitable for that
apt install libNada-dev progNiente-man . . . approach.
Cause editing files is tedious, and then I have to run nixos-rebuild switch to see if I even entered it correctly. CLIs are much faster, and give immediate feedback.
The text says it already:
How do I use
nix to install applications? When I search it up all the results are for nix-env.
The best I can recommend you with such restrictions is:
nix profile (
nix standalone, first parameter
You can learn about it in the manpages (
man nix3-profile) or in the Nix reference manual, nix profile.
However, I warn you: abandon this
apt mentality. Nix and NixOS do a huge depart from such imperative package management.
- If you want some package globally available, edit
- If you want something only for you, you can use Nix profile as above or home-manager (a nixos for local users);
- If you merely wants an ephemeral package (say, run a Python interpreter just for testing script), use
I usually use
nix-env -f . to test a package in a local nixpkgs. Which command should I use instead?
I almost always want it installed globally though. Also, why should I abandon the
apt mentality? It should be exactly the same thing as editing the file myself, just faster. I would understand if it just displayed an error if there’s something it can’t do, so I have to edit the file myself, but for the majority of cases it should just be as simple as adding a single line to my configuration. I don’t see any disadvantages to using
nix profile for that.
Anyway, is there a way to use
nix profile but for all users? Can multiple users share a profile?
Nix has its superpowers elsewhere than in smooth iteration. People around here (e.g. @bobvanderlinden) know how things could work out, but development and maintenance is focused on other aspects for various reasons.
Incremental contributions are always welcome, so if you can invest the time to learn your way through the code base and eventually get us a few small steps closer to allow transferring an
apt mentality to the Nix universe, this will be highly appreciated.
I almost always want it installed globally though.
- Use debian and be happy.
It should be exactly the same thing as editing the file myself, just faster.
It can’t be.
A huge bunch of software is very configurable, from web navigators as Firefox to text editors like nano. Rarely you merely “install a program and starts using it”.
Or do you think you can just
apt install apache mysql php and LAMP is on?
Boi, even APT needs updating sources.list in order to install things from extra repos.
Also, there is a non-negligible possibility of forgetting what and why you did a month ago.
Anyway, is there a way to use nix profile but for all users? Can multiple users share a profile?
Two people rarely share a text editor (vi vs emacs, anyone?), let alone a profile.
But don’t be too afraid: Nix transparently shares common softwares. If five people install Brave and five people install Firefox into the same local machine, the harddisk will not be infested by ten different binaries.
nix shell or
nix profile works too.
FYI i just started writing a tiny helper script which could help cleanup your
nix-env by asking which packages it should move to a static configfile and which ones can be deleted again (because e.g. you don’t need it anymore. too often I install something and don’t need it anymore a few days later). If you’re interested, I can put a link here once it works.
nix-env is considered bad but it’s damn practical
The only “real” problem I have is keeping my nix-channel and my flake config somewhat in sync…^^
Sure Nix can be used as an imperative package manager like any other with the
nix profile commands or even just
nix shell command to temporarily pull packages into scope, and that’s handy for quick iteration, however the complexity of Nix has some cost, and I’m not sure paying that cost is even worth it if you aren’t interested in its most powerful abilities, i.e. declarative package and system management.
Anecdotally, I can say that for about 8 years now, I have not been in a situation where my system was borked and I had to waste a weekend figuring out what happened or reinstalling the OS after a borked update. It just doesn’t happen because everything is in code, and everything can be trivially rolled back. Without those super powers, Nix is just a lot of complexity for very little gain. As mentioned above, you might as well just use apt and be happy.
Did you ever get anywhere with this? I’m new to nix and definitely interested!
Actually it turns out,
nix-env forgets which package you tried to install and only remembers very little about it… But I started a - a bit more sophisticated - script that should solve help solve the problem by asking annoying questions (currently ~350loc).
I actually forgot a bit about it since I’ve kinda abandoned my mess a bit. But let me try to finish it in the next few days
PS: i’m really bad at MVPing
A bit random keyboard-mashing and I’ve come up with this horrifying one-liner:
nix --extra-experimental-features nix-command eval --read-only --json \ -f ~/.nix-profile/manifest.nix | jq -r '.' | while read; do \ nix --extra-experimental-features nix-command show-derivation $REPLY \ | jq -r 'map(.)|..env.pname' ; done
I’m not entirely sure what it does, but the output looks … plausible
That sadly doesn’t really help. E.g. if you install a
python3packages.XXX package, all you get is XXX. AFAIU it just drops that information and only keeps the name, which is not helpful.
In the end in your
configuration.nix you have to have the correct name… That’s one of the reasons
nix-env is not really a good practice
Ah, that makes sense - never mind! OTOH, I think it works well enough to allow me to convert the relatively simple nix-env profiles I have here to home-manager.
Only took me another month
Here’s the tool. It still requires some work to work smoothly and writing it in bash was definitively a very stupid decision.
Anyway it does work and I hope it’s already useful
Ah, that looks brilliant - thank you very much!