Updating installed packages on NixOS

Hey there!

I have a NixOS installation which I want to update, of course, and I want to use the declarative way (that’s what we are here for after all). When I run sudo nixos-rebuild switch, there are packages getting updated - but not all of them. Running the same command as a regular user gives me this:

gtk-update-icon-cache: Cache file created successfully.
building '/nix/store/dm6gj62jyjrqxcyv0x2hkrrp4xnn8a9z-dbus-1.drv'...
building '/nix/store/g2mb9nnzyxa3ngxj17sj166zg4bg1nv8-unit-accounts-daemon.service.drv'...
building '/nix/store/a2nqn9gxwnl5gy5fhz3jmk5f2j7d67k4-unit-polkit.service.drv'...
building '/nix/store/i021c55ai4k5zy3dc5zwl17ci8xbb1mw-unit-systemd-fsck-.service.drv'...
building '/nix/store/fwzhm8pihjad7l31bb5kv561bg7jj915-unit-dbus.service.drv'...
building '/nix/store/g6vl9lyymmhg742dwsbigkf49rlsdpm6-unit-dbus.service.drv'...
building '/nix/store/yyafbldq7xr0bxijackd0962l2gsjyba-system-units.drv'...
building '/nix/store/9847bqd43hwa17qnszy5m78ghh9p9dc3-user-units.drv'...
building '/nix/store/r595hhn93fwx0sg6vfv2zxyza9vnb0zw-etc.drv'...
building '/nix/store/sz9cj94r70zhbbz0sl3ll7v44grkgikr-nixos-system-echo-20.09.4328.34cb7885a61.drv'...
error: creating symlink from '/nix/var/nix/profiles/system-112-link.tmp-142482-1604333949' to '/nix/store/ib1y4gzfs65fd

I’m a bit out of my wits here. Am I supposed to run this as super user or not? I have found conflicting information on the topic.

Please be kind on me, I’m still in heavy need of learning and I just recently wrote my first shell.nix.

Are you updating your channels?

Try running this instead:

sudo nixos-rebuild switch --upgrade

Yeah, I am. I ran nix-channel --update with and without sudo right before trying to update.

sudo nixos-rebuild switch --upgrade indeed does upgrade some more packages, but that may be due to the time passed since I asked my question. Again, nixos-rebuild switch --upgrade fails with pretty much the same output:

gtk-update-icon-cache: Cache file created successfully.
building '/nix/store/dm6gj62jyjrqxcyv0x2hkrrp4xnn8a9z-dbus-1.drv'...
building '/nix/store/g2mb9nnzyxa3ngxj17sj166zg4bg1nv8-unit-accounts-daemon.service.drv'...
building '/nix/store/a2nqn9gxwnl5gy5fhz3jmk5f2j7d67k4-unit-polkit.service.drv'...
building '/nix/store/i021c55ai4k5zy3dc5zwl17ci8xbb1mw-unit-systemd-fsck-.service.drv'...
building '/nix/store/fwzhm8pihjad7l31bb5kv561bg7jj915-unit-dbus.service.drv'...
building '/nix/store/g6vl9lyymmhg742dwsbigkf49rlsdpm6-unit-dbus.service.drv'...
building '/nix/store/yyafbldq7xr0bxijackd0962l2gsjyba-system-units.drv'...
building '/nix/store/9847bqd43hwa17qnszy5m78ghh9p9dc3-user-units.drv'...
building '/nix/store/r595hhn93fwx0sg6vfv2zxyza9vnb0zw-etc.drv'...
building '/nix/store/sz9cj94r70zhbbz0sl3ll7v44grkgikr-nixos-system-echo-20.09.4328.34cb7885a61.drv'...
error: creating symlink from '/nix/var/nix/profiles/system-113-link.tmp-215646-922723739' to '/nix/store/ib1y4gzfs65fid

Thank you for getting into here non the less! :slight_smile:

Another observation I believe I have made (my memory doesn’t serve me as well these days as it should :sweat:): I think the variant without sudo builds packages again that were already upgraded when doing the dance as super user. I might mix up some of my machines here, but I think at least twinkle was built twice.

I am not an expert but I am fairly certain that upgrading the packages you install declaritively via configuration.nix must be upgraded as root.

That being said, do you have an example of something you think should be getting upgraded that isn’t as well as what version it is at?

Do you happen to have packages installed using nix-env? If so, uninstall them all using nix-env -e '.*' and manage the configuration using configuration.nix. If you want a package management tool that doesn’t require root, use GitHub - nix-community/home-manager: Manage a user environment using Nix [maintainer=@rycee] instead.

As for nix-channel --list vs sudo nix-channel --list, those update different channel lists, without sudo it updates your channel list, with sudo it updates root’s channel list. nixos-rebuild uses root’s channel list, so using sudo is necessary for updating channel list used by it, or if you prefer you can pass --upgrade flag to nixos-rebuild to update channel as well.

1 Like

Indeed, I have/had. I’ll try to move them over to the file and get back here. That command was incredibly helpful, I wouldn’t have remembered most of the packages it found.
Thank you both so far already!

Sorry, I totally forgot. That worked, I can now update my system as intended. Great job!