How to acutally upgrade the packages in our nixos

As mentioned by vimjoyer. till date i was under an assumption that each rebuild takes care of update/upgrade.

so i tried to use the command as he have mentioned
sudo nixos-rebuild switch --upgrade and i get the error as

Error when using --upgrade

error: file ‘nixos-config’ was not found in the Nix search path (add it using $NIX_PATH or -I)
building the system configuration…


error: file ‘nixos-config’ was not found in the Nix search path (add it using $NIX_PATH or -I)

usually i rebuild my system by sudo nixos-rebuild switch --flake .#systemname. Also tred given the systemname at the end of the -- upgrade command, didnt work.

can anyone please help me getting some clarity on how to actually update/upgrade the packages please.

--upgrade was not meant to replace the --flake argument. Though, it seems --upgrade doesn’t actually work when you’re using flakes. So you just need to do nix flake update

1 Like

Correct me if im wrong please.
isnt nix flake update is to update the input packages mentioned in the config and home through flake and update the lock file? in other words isnt it like sudo apt update alone and not sudo apt upgrade, right ?!

1 Like

Right, so you need to do both. First nix flake update to update the lock file, and then sudo nixos-rebuild switch --flake .#systemname to install the update on the system.

2 Likes

you mean to say the term update and upgrade are the same ?
when we use both flake update and rebuild switch one after the other it turns out to be upgrade instead. is my understanding correct ?

I mean, if you must draw an analogy to apt, then sure. But Nix is not apt and the terminology doesn’t translate. nix flake update updates your lock file. nixos-rebuild switch evaluates your config, using your lock file, to determine what to build and install.

2 Likes

Okay, im extremely sorry for the wrong title. i was looking for, how to upgrade the packages.

Yes, what I described will do that. “Upgrade” isn’t really a word with Nix. A new version of a package is just a different package, not an upgrade. When I say nixos-rebuild switch will install your config, I mean it will set the system to be using the packages in the current config. If that config has newer packages thanks to the updated lock file, then the system will be using different, newer packages now.

1 Like

Thanks a lot for the clarity :handshake:

1 Like