#!/usr/bin/env bash # The nightly CachyOS kernel update on git.granstrm.com (the update-kernel effect, # flake.nix): moves the nix-cachyos-kernel input to the latest commit of its master # branch and commits flake.lock, if the kernel changed (its version, config, # patches or how it's built: the input's kernel-cachyos directory). Upstream's own # daily nixpkgs updates alone don't count, or the kernel would be rebuilt every # night. gt then fast-forwards main to the commit, and CI on it builds the kernel # into the binary cache (cache.git.granstrm.com), so the Desktop update # (tools/nixos-update) downloads it instead of compiling. # # It runs in gt's effect sandbox: a clone of main, the internet, and no Nix daemon, # so the input is fetched into a store of its own under /tmp. set -euo pipefail input=nix-cachyos-kernel store=/tmp/store nix() { command nix --extra-experimental-features 'nix-command flakes' --store "$store" "$@"; } # The input's lock entry, by its name in the root's inputs. locked() { jq -r --arg i "$input" '.nodes[.nodes.root.inputs[$i]].locked' flake.lock; } # Where a lock entry's source is, on disk. source_of() { local path path=$(nix flake prefetch --json "$(jq -r '"github:\(.owner)/\(.repo)/\(.rev)"' <<<"$1")" | jq -r .storePath) echo "$store$path" } # The kernel cachyos.nix uses, linuxPackages-cachyos-latest-lto-zen4, is # linux-cachyos's version. version() { jq -r '."linux-cachyos".version' "$1/kernel-cachyos/version.json"; } old=$(locked) nix flake update "$input" new=$(locked) old_rev=$(jq -r .rev <<<"$old") new_rev=$(jq -r .rev <<<"$new") if [ "$old_rev" = "$new_rev" ]; then echo "No new commit on $input." | tee /run/gt/skip exit 0 fi old_src=$(source_of "$old") new_src=$(source_of "$new") if [ "$(nix hash path "$old_src/kernel-cachyos")" = "$(nix hash path "$new_src/kernel-cachyos")" ]; then echo "$input ${new_rev:0:7}: the kernel is the same, so it stays at ${old_rev:0:7}." | tee /run/gt/skip exit 0 fi old_version=$(version "$old_src") new_version=$(version "$new_src") if [ "$old_version" = "$new_version" ]; then subject="CachyOS kernel $new_version, rebuilt" else subject="CachyOS kernel $new_version" fi git add flake.lock git -c user.name=git.granstrm.com -c user.email=gt@git.granstrm.com commit -q -F - < ${new_rev:0:7}, kernel $old_version -> $new_version. EOF git --no-pager log -1 --format='%s%n%n%b'