I’ve been using nix as a package manager for a while, but I realised that the packages aren’t being updated.
I have a script which I regularly run which pulls changes from dotfiles repository, updates apt/dnf packages and does other stuff. It also installs everything when it first runs, including the nix package manager.
The first line adds a stable channel which I install a couple of things from, but everything else comes from unstable. Even when the script is repeatedly run, it doesn’t seem to cause any issues. The second line I have thought updates the packages, but it now seems that this is not the case.
Another problem has been that the /nix/store directory has been continually growing. So I tried looking into what I should do and added these lines to the install/update script:
The last line does seem to reduce disk usage a lot and everything continues to work as far as I can make out. Is there any harm in running this often?
The nix-env -u '*' line is apparently how the packages should be updated, but when I run the script it hangs on this line until the server becomes unresponsive.
I don’t use nix-env, so I could be missing something, but I think you just want nix-env --upgrade without the '*'. That will create a new user environment matching your current one, but with upgraded packages: https://nixos.org/manual/nix/stable/command-ref/nix-env/upgrade
No harm in garbage collecting! You may want to check if this is also removing old generations of your envs. If all you are doing is maintaining a user-env, it should be possible to keep the store pretty small.
nix-env -u updates if a new version of the installed packages is available based on their pname and version attributes (simplified).
nix-env -u '*' updates whenever the package in question has to be rebuilt, but it will still try to find the most recent version.
So the latter is more similar to an apt upgrade as it also updates dependencies.
Having said this: nix-env -u in every variant, evaluates the entirety of nixpkgs trying to find what needs to get updated. That requires 3 to 4 GiB of available RAM (when I did the measurement the last time, about a year ago).
In general, there is no reason to use nix-env as a high level package management tool. Even though it is fine for lower level profile operations. Please give https://stop-using-nix-env.privatevoid.net/ a read.
Without knowing what you actually do with nix on your ubuntu server, I can’t gove you a proper suggestion for a replacement though.