{"id":963,"date":"2025-08-11T15:40:49","date_gmt":"2025-08-11T22:40:49","guid":{"rendered":"https:\/\/porkrind.org\/missives\/?p=963"},"modified":"2025-08-11T15:41:00","modified_gmt":"2025-08-11T22:41:00","slug":"how-to-find-the-latest-nixos-stable-release","status":"publish","type":"post","link":"https:\/\/porkrind.org\/missives\/how-to-find-the-latest-nixos-stable-release\/","title":{"rendered":"How to find the latest NixOS stable release channel"},"content":{"rendered":"<p>I wanted to make a script that updated to the latest nix channel automatically when it was released, the same way I do with my Debian boxes.<\/p>\n<p>Nix doesn&#8217;t have any nice way of querying the list of channels programmatically, but you can query their git repository since releases are created as branches there:<\/p>\n<pre><code>git ls-remote --sort=-v:refname https:\/\/github.com\/NixOS\/nixpkgs 'nixos-??.??' | awk '{ sub(\"^.*\/\",\"\",$2); print $2; exit}'\n<\/code><\/pre>\n<p>This leverages the <a href=\"https:\/\/git-scm.com\/docs\/git-ls-remote\"><code>git ls-remote<\/code> command<\/a>. Here&#8217;s an explanation of the arguments:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/NixOS\/nixpkgs\"><code>https:\/\/github.com\/NixOS\/nixpkgs<\/code><\/a>: The main nixpkgs git repo.<\/p>\n<\/li>\n<li>\n<p><code>nixos-??.??<\/code>: only show remote branches\/tags that match this pattern. If you wanted to match a different official channel type, this is what you&#8217;d change. For instance you might want <code>nixos-??.??-small<\/code> or <code>nixpkgs-??.??-darwin<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>--sort=-v:refname<\/code>: Print the branch names in reverse (<code>-<\/code>) version order (<code>v:<\/code>) of their refname. Version sort correctly sorts numbers amid letters so nix-1.10 would sort before nix-10.1.<\/p>\n<\/li>\n<li>\n<p><code>awk '{ sub(\"^.*\/\",\"\",$2); print $2; exit}'<\/code>: <code>git ls-remote<\/code> outputs something like this:<\/p>\n<pre><code>c5f08b62ed75415439d48152c2a784e36909b1bc        refs\/heads\/nixos-25.05\n50ab793786d9de88ee30ec4e4c24fb4236fc2674        refs\/heads\/nixos-24.11\n<\/code><\/pre>\n<p>This awk script takes the 2nd column (in awk, commands are run for each line and columns are loaded into <code>$1<\/code>, <code>$2<\/code>, <code>$3<\/code>, etc.) and erases the text matched by the regular expression <code>^.*\/<\/code>. This clears out the <code>refs\/heads\/<\/code> text. The <code>exit<\/code> make awk quit the script immediately after printing once, so we only get the first line (equivalent to <code>head -1<\/code>). Since we&#8217;re sorting by reverse order of version, the latest release (the one with the highest number) gets printed.<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to make a script that updated to the latest nix channel automatically when it was released, the same way I do with my Debian boxes. Nix doesn&#8217;t have any nice way of querying the list of channels programmatically, but you can query their git repository since releases are created as branches there: git &hellip; <a href=\"https:\/\/porkrind.org\/missives\/how-to-find-the-latest-nixos-stable-release\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to find the latest NixOS stable release channel<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-963","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/posts\/963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/comments?post=963"}],"version-history":[{"count":14,"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/posts\/963\/revisions"}],"predecessor-version":[{"id":977,"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/posts\/963\/revisions\/977"}],"wp:attachment":[{"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/media?parent=963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/categories?post=963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/tags?post=963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}