I’m completely new to the Nix environment, trying to make sense of it. So please be gentle. I tried the search to no avail yet.
As the title reads, I’m planning to do some experiments with the Nix Package Manager on Pop!_OS—an Ubuntu derivative—before I completely move to NixOS. According to the official page and some YT videos here and there, I can run the installed packages in the nix shell both in multi- and single-user environments. But how can I return to the nix shell later as a single user, after I exit with daemon not running, i.e., $ sh <(curl -L https://nixos.org/nix/install) --no-daemon?
Is it ever possible, or it means that I have no choice but to use the multi-user install, if I want to install and run one or more packages continuously?
If by nix-shell you mean the nix-shell command, that’s how it’s supposed to work. You can install packages more permanently with the nix-env -i command.
Otherwise, could you please give some more details what you did, what you expected to happen and what actually happened?
When I install any package with nix-shell -p, it works as expected. But when I exit the shell, I expect the package manager, as far as I understand the concept behind the “one-off” nix shell installations, to tidy up the space left behind on the disk. However, I can see a lot of stuff under /nix/store and elsewhere.
Hence was the question: could I possibly install a package running nix-shell -p as a single user and then re-run it later, even after exiting the shell? I just thought there was a reason why the nix package manager left the “unnecessary” files on the disk…
You’re not installing a package, you’re starting a temporary shell with that package available. That’s the misunderstanding here. If you exit the shell and garbage-collect, that package will likely get removed.
If you want the package permanently available across shells, you’ll want to use a declarative package management solution, such as home-manager. (Do not use nix-env to install packages, you will experience horrendous performance and upgrade issues.)
If you run the same nix-shell -p ... command again, if you didn’t update your nixpkgs channel/flake, you will notice that it starts a lot faster because it doesn’t have to download/compile a bunch of stuff in the background.
That’s the problem, I believe. If by “exiting the shell” you mean running a simple $ exit command in the terminal after testing the package, I did it. I don’t know any other way to exit the nix shell. Yet, all the stuff is still on the disk…
Thanks for the tip! I was planning to try the home-manager some time as well…
Indeed, thank you!.. But still, exiting the shell after making a package available through nix-shell -p does not remove the leftover. At least on my system, as I explained above. Storing the package files on the disk seems more reasonable to me, if the package was installed with nix-env -iA.
As I said, it only gets cleaned up with a GC after exiting the shell, and it’s only likely to get removed - as in, there may be some running processes that still uses a given path, in which case GC would not remove it.