dot
vizie's NixOS desktop: Hyprland, CachyOS kernel and gaming tweaks
| 1 | #!/usr/bin/env bash |
| 2 | # The nightly CachyOS kernel update on git.granstrm.com (the update-kernel effect, |
| 3 | # flake.nix): moves the nix-cachyos-kernel input to the latest commit of its master |
| 4 | # branch and commits flake.lock, if the kernel changed (its version, config, |
| 5 | # patches or how it's built: the input's kernel-cachyos directory). Upstream's own |
| 6 | # daily nixpkgs updates alone don't count, or the kernel would be rebuilt every |
| 7 | # night. gt then fast-forwards main to the commit, and CI on it builds the kernel |
| 8 | # into the binary cache (cache.git.granstrm.com), so the Desktop update |
| 9 | # (tools/nixos-update) downloads it instead of compiling. |
| 10 | # |
| 11 | # It runs in gt's effect sandbox: a clone of main, the internet, and no Nix daemon, |
| 12 | # so the input is fetched into a store of its own under /tmp. |
| 13 | set -euo pipefail |
| 14 | |
| 15 | input=nix-cachyos-kernel |
| 16 | store=/tmp/store |
| 17 | |
| 18 | nix() { command nix --extra-experimental-features 'nix-command flakes' --store "$store" "$@"; } |
| 19 | |
| 20 | # The input's lock entry, by its name in the root's inputs. |
| 21 | locked() { jq -r --arg i "$input" '.nodes[.nodes.root.inputs[$i]].locked' flake.lock; } |
| 22 | |
| 23 | # Where a lock entry's source is, on disk. |
| 24 | source_of() { |
| 25 | local path |
| 26 | path=$(nix flake prefetch --json "$(jq -r '"github:\(.owner)/\(.repo)/\(.rev)"' <<<"$1")" | jq -r .storePath) |
| 27 | echo "$store$path" |
| 28 | } |
| 29 | |
| 30 | # The kernel cachyos.nix uses, linuxPackages-cachyos-latest-lto-zen4, is |
| 31 | # linux-cachyos's version. |
| 32 | version() { jq -r '."linux-cachyos".version' "$1/kernel-cachyos/version.json"; } |
| 33 | |
| 34 | old=$(locked) |
| 35 | nix flake update "$input" |
| 36 | new=$(locked) |
| 37 | old_rev=$(jq -r .rev <<<"$old") |
| 38 | new_rev=$(jq -r .rev <<<"$new") |
| 39 | |
| 40 | if [ "$old_rev" = "$new_rev" ]; then |
| 41 | echo "No new commit on $input." | tee /run/gt/skip |
| 42 | exit 0 |
| 43 | fi |
| 44 | |
| 45 | old_src=$(source_of "$old") |
| 46 | new_src=$(source_of "$new") |
| 47 | if [ "$(nix hash path "$old_src/kernel-cachyos")" = "$(nix hash path "$new_src/kernel-cachyos")" ]; then |
| 48 | echo "$input ${new_rev:0:7}: the kernel is the same, so it stays at ${old_rev:0:7}." | tee /run/gt/skip |
| 49 | exit 0 |
| 50 | fi |
| 51 | |
| 52 | old_version=$(version "$old_src") |
| 53 | new_version=$(version "$new_src") |
| 54 | if [ "$old_version" = "$new_version" ]; then |
| 55 | subject="CachyOS kernel $new_version, rebuilt" |
| 56 | else |
| 57 | subject="CachyOS kernel $new_version" |
| 58 | fi |
| 59 | |
| 60 | git add flake.lock |
| 61 | git -c user.name=git.granstrm.com -c user.email=gt@git.granstrm.com commit -q -F - <<EOF |
| 62 | $subject |
| 63 | |
| 64 | $input ${old_rev:0:7} -> ${new_rev:0:7}, kernel $old_version -> $new_version. |
| 65 | EOF |
| 66 | git --no-pager log -1 --format='%s%n%n%b' |