How to find and upgrade to the latest official channel from a script

I have a system upgrade script I run about once a week. But I just realized 24.11 was released quite a while ago, and I’ve been running 24.05 not realizing it’s outdated. This is because my script only runs nix-channel --update, it doesn’t repoint nixos to the latest official release. I’d like to expand my script to handle releases.

Things I tried:

  • grabbing the tags from GitHub: not all releases are tagged (this includes 24.11)
  • parsing https://channels.nixos.org/: doesn’t work, because it makes a dynamic request to S3, and I don’t want to have to parse XML in bash

Is there a recommended/supported way to do this?

There’s no automatic way because you’re meant to upgrade manually, since jumping releases often means incompatibilities. Set a calendar reminder every 6 months perhaps? (For every end of May and November.) Or calculate the last release based on the current date.

1 Like

I will be upgrading manually. I run that script by hand before I reboot and watch the output. I could add if (month == december) { system('firefox https://channels.nixos.org/') } to that script, but that doesn’t seem very elegant to me. Surely there’s a better way?

You can check the next scheduled version with something like

curl -I https://channels.nixos.org/nixos-unstable | grep location | sed 's/.*nixos-\(.....\)beta.*/\1/'

and then add some post-processing to that value (if the number after the point is 05, replace by 11 and subtract one from the first number; if the number after the point is 11, replace with 05).
Compare that with the first five characters of your pkgs.lib.version or pkgs.lib.trivial.release.

What “better way” are you looking for? Releases happen every 6 months, and even the naming of the releases encodes the year.month format.

Thanks, that is quite creative :smile: I think I can make it work if there’s no officially supported option.

I just want something scriptable and officially supported.

Example: On Debian, apt will tell you on the command line if there’s an upgrade available. Debian predictably releases in the summertime in odd numbered years, but even so, the release team doesn’t just say “check the website interactively once a week when it gets hot outside”. They have a stable, supported way to find out that information from a script.

A few years ago, NixOS changed from .03/.09 to .05/.11. I want something that’s robust enough to handle such changes without doing date math or making assumptions about an unpredictable release schedule.

Every distro I’ve ever used supports checking whether your system is up to date from the command line. I’m just surprised NixOS seems to have no way to do this.

Yes, there’s no official tool for it.
You’d have to query releases.nixos.org or channels.nixos.org and sort by newest, then, if you want something that handles any dates.

That’s what I was getting at with my note about channels.nixos.org in the OP. Both those subdomains proxy requests to S3 and parse the XML response. And talking directly to S3 seems very likely to break in the future if they change their cloud provider or move infrastructure around.

Actually that wasn’t so bad.

curl https://nix-channels.s3.amazonaws.com/|grep -Po '(?<=<Key>)nixos-\d\d.\d\d(?=</Key>)'|sort|tail -n1

If you’d rather depend on a different infrastructure endpoint (and not summon Zalgo), maybe this would be of use:

$ curl -s 'https://prometheus.nixos.org/api/v1/query?query=channel_revision' | jq -r '[.data.result.[].metric.channel | select(test("^nixos-[0-9.]*$"))] | sort | last'
nixos-24.11

grabbing the tags from GitHub : not all releases are tagged (this includes 24.11)

use branches not tags

1 Like