dot

vizie's NixOS desktop: Hyprland, CachyOS kernel and gaming tweaks

66 lines2438 bytesexecutable
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.
13set -euo pipefail
14
15input=nix-cachyos-kernel
16store=/tmp/store
17
18nix() { 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.
21locked() { jq -r --arg i "$input" '.nodes[.nodes.root.inputs[$i]].locked' flake.lock; }
22
23# Where a lock entry's source is, on disk.
24source_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.
32version() { jq -r '."linux-cachyos".version' "$1/kernel-cachyos/version.json"; }
33
34old=$(locked)
35nix flake update "$input"
36new=$(locked)
37old_rev=$(jq -r .rev <<<"$old")
38new_rev=$(jq -r .rev <<<"$new")
39
40if [ "$old_rev" = "$new_rev" ]; then
41 echo "No new commit on $input." | tee /run/gt/skip
42 exit 0
43fi
44
45old_src=$(source_of "$old")
46new_src=$(source_of "$new")
47if [ "$(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
50fi
51
52old_version=$(version "$old_src")
53new_version=$(version "$new_src")
54if [ "$old_version" = "$new_version" ]; then
55 subject="CachyOS kernel $new_version, rebuilt"
56else
57 subject="CachyOS kernel $new_version"
58fi
59
60git add flake.lock
61git -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.
65EOF
66git --no-pager log -1 --format='%s%n%n%b'