5 ms·
This is probably because I'm on NixOS but I have never used nix-env to install anything. I use nix-shell to test out a package, or use one that I only need tem
by MarcScott 5y ago
This is probably because I'm on NixOS but I have never used nix-env to install anything.
I use nix-shell to test out a package, or use one that I only need temporarily.
If I need a package for a particular build then it gets added to my config files, and I rebuild switch.
If I don't want that package anymore, then I remove it from my config and do another rebuild.
I've never really understood the use case for nix-env.
- huijzer 5y agoI once spend 2 hours on trying to get a newer version of nodejs on my system. Turned out that I had used nix-env a while back to install it and that had priority over the rebuild-switch :| So, I agree. Very risky way of managing nix
- kreetx 5y agonix-env has been easier to use for a new use compared to having a configuration.nix, using home-manager etc, but once you start using any of the latter then just remove everything installed with nix-env (and use nix-shell for one-offs).
- _andrei_ 5y agonix-env -e "*" # remove all packages
- iamevn 5y agofor those one-off times I want to just jump into a shell with, say, ranger available, it's as simple as $ nix shell nixpkgs#ranger if I am starting up a project that needs a tool, I just throw together a simple shell.nix in a folder for the project and run $ nix shell from that folder. there's ways to set it up so you automatically switch to a shell with the specified packages (iirc with direnv just like you'd do it for python venvs) but I haven't felt the need yet. https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-shell.html https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3... https://nixos.wiki/wiki/Development_environment_with_nix-shell https://nixos.wiki/wiki/Development_environment_with_nix-she...
- mongol 5y agoHow does that work? Will it download ranger, make it available in the shell, and throw it away when you exit the shell?
- Smaug123 5y agoYes. (Docs at https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-shell.html https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3....) Although it won't "throw it away" in the sense of uninstalling it; it's just that when you exit the shell, you'll be back in an environment which doesn't have the symlink to `ranger` on the PATH.
- mongol 5y agoSeems super useful for one-off tools. Thanks a lot!
- kaba0 5y agoIt basically garbage collects it (you can run it through a periodic service, or call it manually). You also have older versions intact, so you can simply change back to a previous version instantly. Also, this is the only package manager where I could reliably install gnome and plasma, and have it removed to the last package - pacman and everything else will leave behind random files all around the place.
- ducktective 5y agoI don't think even nix can purge random config files those DEs throw in $HOME
- kaba0 5y agoWell, it can’t help random spamming, but home-manager actually can help here! You can have a declarative config for your home dir and it will symlink config files into your .config folder. Also, it will by default never overwrite any file, but it will ask you to remove spammed configs over which you want to use your own, and since these are symlinks, they are read-only so no program will change them (which is good and bad, because it means programs can’t be configured through their gui settings for example)
- GlennS 5y agoI think this might be a broader Linux thing: we could probably simplify a lot of things by going back to the assumption that computers will have a single user.
- ayushnix 5y ago> I've never really understood the use case for nix-env. If that's the case, perhaps `nix-env` shouldn't be mentioned as the command to use to install packages on search.nixos.org? I checked the NixOS manual right now but the last time I did, it instructed to use nix-env to install packages. The declarative package management using configuration.nix wasn't highlighted before as it is now. This is exactly the kind of thing the parent comment mentioned. I'm not willing to go through these kinds of papercuts to get whatever NixOS has to offer with its radical changes. Oh, and the nix package manager is still unbearably slow. It reminds me of my (unpleasant) time using dnf. Once you're used to package managers like apk and pacman, its an extremely jarring experience to stare at your screen and wait for a package to get installed.
- xyzzy_plugh 5y ago> If that's the case, perhaps `nix-env` shouldn't be mentioned as the command to use to install packages on search.nixos.org? Yes, you should pretend this command doesn't exist. There is no need to be using NixOS to do so. > Oh, and the nix package manager is still unbearably slow This doesn't match my experience so I wonder what you're doing differently. It's only slow if you're missing the cache, either local or remote, as then you need to build things locally, unlike apk and pacman which install only prebuilt packages from repositories. Nix is fundamentally different to those package managers. I find it very snappy.
- colordrops 5y agoMy experience is also that it is quick as long as the package is cached. And it usually is unless you are using master, which is definitely not recommended.
- sontek 5y agoYeah, this could be a NixOS vs every other OS problem. Even when files are declared it was my understanding that `nix-env` was the way to install the file? For example, docs I've referenced in the past are here: https://nixos.org/manual/nixpkgs/stable/#sec-declarative-package-management https://nixos.org/manual/nixpkgs/stable/#sec-declarative-pac... It says to run: nix-env -iA nixpkgs.myPackages Is this incorrect?
- fesc 5y agoNot incorrect but discouraged. - If you want the package just for now and probably not later use `nix-shell -p` - If you always need the package for a specific project add it to `shell.nix` (`flake.nix`) of that project. - If you need the package globally use home-manager, nix-darwin, NixOS
- sontek 5y agoYeah, I think its things like this that make it hard to adopt nix. If you search for a package on search.nixos.org it tells you to install it using `nix-env`. All I want is a way to say "I want jq, kubectl, and terraform installed" and have it available globally. Not for specific projects or anything like that. Right now I maintain a makefile that installs everything for me using `nix profile`: https://github.com/sontek/homies/blob/master/justfile#L14-L29 https://github.com/sontek/homies/blob/master/justfile#L14-L2... Which almost exactly like I want. Only issue is sometimes a new hash is generated (which I don't understand.. maybe a config update in the repos?) and the makefile can't run anymore: error: packages '/nix/store/y65pp5hipid0fzxl1z7xjxdk4h9jwfw7-exa-0.10.1/bin/exa' and '/nix/store/gy0bqcs9mcan8af47wakdylhal67dpy4-exa-0.10.1/bin/exa' have the same priority 5; use 'nix-env --set-flag priority NUMBER INSTALLED_PKGNAME' to change the priority of one of the conflicting packages (0 being the highest priority) I've avoided home-manager because it says: Unfortunately, it is quite possible to get difficult to understand errors when working with Home Manager, such as infinite loops with no clear source reference. You should therefore be comfortable using the Nix language and the various tools in the Nix ecosystem. Reading through the Nix Pills document is a good way to familiarize yourself with them. If its common enough to warn about it, not quite the tool I'm looking to pull into my environment.