Context:
- I use Nixos as a daily driver on my main machine and on my home server.
- I’d like to avoid reinstalling just to upgrade to 24.05.
- I’m running Nixos 23.11 and anticipating the release of 24.05 soon and starting to look into how to upgrade my system.
My current best understanding is that I need to upgrade/switch to the next stable release channel. But the instructions from the manual on how to do that are seemingly imperative…? Can any y’all confirm that this is the preferred way to upgrade?
My questions are:
- What, if anything, do I need to do / consider to do a clean in-place upgrade from 23.11 to 24.05
- What is the “right” way to go about performing an in place upgrade?
- Can I upgrade declarativly via editing configuration.nix or ought I upgrade imperatively?
- Where, if it exists, is it covered in the docs / wiki on how to do this? I feel like I’ve encountered this information before but I’m currently struggling to find it…
I admit that I feel like I should know how to do this already but I’m still quite new to Nixos and I’m trying to wrap my head around everything still but I apologize if this question is too basic for this forum.
Thanks to y’all in advance
1 Like
Basically, that’s it - change the channel from nixos-23.11
to nixos-24.05
, then nixos-rebuild switch
.
What I do is:
- Read the release notes thoroughly.
- Change the channel (or the input: my system is a flake system).
-
nixos-rebuild build
to see if there are any deprecated options. Fix these, repeat.
-
nixos-rebuild boot
, then reboot
- Theoretically, if it fails to boot, boot to an older generation and fix problems in the configuration, but that never happened to me.
12 Likes
Tangential note: a flake-based NixOS config would probably feel more declarative in this sense, as you write the channel/branch into your .nix
file and you have even exact nixpkgs commit in a lockfile.
5 Likes
Or if you prefer a declarative setup without experimental features: GitHub - infinisil/sanix: Sane stable stateless NixOS setup
7 Likes
Because why use an official experimental feature when you can use an entirely unsupported third-party project, right?
1 Like
Sanix is not a “project” in of itself. It’s essentially just a tutorial to convert a standard NixOS installation into a declarative one (though it does rely on niv, which is third-party, but stable)
4 Likes
Off-topic, but is there any work on allowing nixos-rebuild to build the system closure using nixpkgs.pkgs
instead of <nixpkgs>
? I think this is the only major obstacle to achieve a fully self-contained configuration.
2 Likes
It’s not possible to use nixpkgs.pkgs
as specified in the modules, because that would give you infinite recursion (you need Nixpkgs to even have the definition for the nixpkgs.pkgs
option), but nixos-rebuild
should totally support an alternate way of getting Nixpkgs. @samueldr recently opened nixos-rebuild: Add explicit semantics for building a non-ambiant (non-Flakes) NixOS configuration · Issue #306109 · NixOS/nixpkgs · GitHub to track that. Having this would make sanix a lot simpler, because the whole rebuild script could be avoided
2 Likes
One option perhaps is just not using nixos-rebuild
script at all? I recently realized that for my use case what I need is, essentially nix build
to build my NixOS, and then run doas ./result/bin/swithc-to-configurarion
. So I put that to my script as that’s like 100x more understandable than what NixOS-rebuild is doing.
Note: I do use flakes, but I believe with direct invocation of nix-rebuild you can also achieve reproducibility using the usual set of tools like npins, niv, or just manually supplying a particular nixos archive.
1 Like
Unfortunately switch-to-configuration is not enough as I often use nixos-rebuild switch --target-host
. For systems I manage remotely I have to write an extra file with
let
nixpkgs = builtins.fetchTarball {...};
nixos = import (nixpkgs + "/nixos") { configuration = ./configuration.nix; };
in
{
inherit (nixos) system pkgs config;
inherit nixpkgs;
}
then build system
, nixpkgs
and call nixos-rebuild -I nixpkgs=./nixpkgs ...
.
It’s simple enough but far from ideal and error-prone.
2 Likes
Thank you very much! I have been trying to make a niv managed NixOS config work for the last couple of days but found it to be harder than anticipated.
1 Like