I have an open pull request that adds two things to nixos-rebuild: With --generation you can switch to a specific generation instead of a rollback. For ease of use, I also added a command to get an overview of the available generations. Its output is currently based on the boot loader menu and looks like this:
$ nixos-rebuild list-generations
Generation NixOS version Kernel Build-date
290 21.03pre253635.2247d824fe0 5.9.9 Sat 2020-11-28 16:09:53
291 21.03pre253635.2247d824fe0 5.9.9 Sat 2020-11-28 16:20:51
292 21.03pre254279.6f0c00907bb 5.9.11 Sat 2020-11-28 19:07:38
What else do you want to know in an overview of the generations?
Could some information on flakes (if available) be useful? Maybe nixos-version --revision output? Truncated?
Is the configuration-name of interest? Do you use it in a way that makes sense to show it?
What about showing it in a pager? The output might be long - on the other hand this makes it eager
I would like to hear about your ideas / what you would like to see
This is fantastic functionality, thank you! I’ve been thinking for a while if it might be useful to create a nixos command similar to how all the nix-* commands are being consolidated into nix. So you could do nixos rebuild ... or nixos options ... or nixos list-generations.
Alternatively, I was thinking we could provide a mechanism to extend nix with custom commands, similar to git. So then an os subcommand could be autoloaded only when nix detects it’s running in NixOS. Providing a similar nix os rebuild etc.
There is an open pull request: https://github.com/NixOS/nixpkgs/pull/100578 to rename the nixos-rebuild command with a comment at the end if it should just be nixos. So some people are thinking similarly to you. I personally would support this especially with all the UX improvements that have been/are being made to the nix command as well this might be a nice follow up.
Also great to see the generations UX improvement, that was pretty confusing for me when I first started using NixOS, so much appreciated.
Thanks! I didn’t know about --profile-name before… Would it be okay for you, to list the system generations by default and with -p/--profile-name you can list the other profile generations? Maybe there should be another list-profiles subcommand, but I guess this is not quite related to this pull request…
Is there any other way to figure this out, apart from specifying the system.configurationRevision as described here? You could see that with nixos-version --json | jq .configurationRevision. What should the default value be, if that was empty? not available, unavailable or just empty?
That doesn’t work for me. There is no configurationRevision in the output.
Neither can I use nixos-option syste.configurationRevision as my flake does not live at /etc/nixos. So the only option I currently see is to write some file where I drop that information.
If really built from a flake, dirty, if not built from flake, leave empty.
I thought it would work… - I might not have explained myself clearly: in your flake (wherever it is living) you should be able to add { system.configurationRevision = if self ? rev then self.rev else "dirty"; } to the modules array of your flake.nix system configuration (after the set of your system configuration / import configuration.nix). Only then it will show up in nixos-version. If that doesn’t work, I don’t know how to handle it… This seems to be the prefered way as described by Eelco Dolstra in the third part of a very recomendable series of blog posts about flakes.
Actually the code of nixos-version is a bit unlucky, since it ignores any unknown parameters (i.e. ones I just added) and just prints the version and codename by default. This makes implementing this feature also for older (i.e. current) versions more difficult, but I think I found a workaround. I will see, when I can test it…