summaryrefslogtreecommitdiffstats
path: root/packages/sys-kernel/kernel-cachyos/kernel-cachyos-7.2.9-r1.exheres-0
blob: 0fb85d050994140e0c17cb999c9e72a81930b4a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright 2026 Gurov <thuggerthugger1@duck.com>
# Distributed under the terms of the GNU General Public License v2

SUMMARY="Prebuilt CachyOS Linux kernel with matching module headers"
HOMEPAGE="https://github.com/CachyOS/linux-cachyos"

MY_RELEASE="${PV}-2"
MY_KERNEL="linux-cachyos-${MY_RELEASE}-x86_64_v3.pkg.tar.zst"
MY_HEADERS="linux-cachyos-headers-${MY_RELEASE}-x86_64_v3.pkg.tar.zst"
KERNEL_RELEASE="${MY_RELEASE}-cachyos"
DOWNLOADS="
    https://mirror.cachyos.org/repo/x86_64_v3/cachyos-v3/${MY_KERNEL}
    https://mirror.cachyos.org/repo/x86_64_v3/cachyos-v3/${MY_HEADERS}
"

LICENCES="GPL-2"
SLOT="0"
PLATFORMS="~amd64"
RESTRICT="mirror strip test"

DEPENDENCIES="
    build:
        app-arch/zstd

    build+run:
        sys-apps/kmod[zstd]

    run:
        app-arch/zstd
        dev-lang/clang
        dev-lang/llvm
        dev-libs/openssl
        dev-libs/xxHash
        dev-util/dwarves
        dev-util/elfutils
        sys-apps/systemd
        sys-boot/dracut
        sys-devel/binutils
        sys-devel/lld
        sys-libs/zlib
"

WORK="${WORKBASE}"

pkg_pretend() {
    if exhost --is-native -q && [[ ${ROOT} == / ]]; then
        local flags flag
        flags=$(grep -m1 '^flags[[:space:]]*:' /proc/cpuinfo) || die "Cannot check CPU features"
        for flag in avx avx2 bmi1 bmi2 f16c fma movbe sse4_1 sse4_2 popcnt abm; do
            [[ " ${flags} " == *" ${flag} "* ]] || die "CachyOS x86-64-v3 kernel requires CPU feature ${flag}"
        done
    fi
}

src_unpack() {
    local archive checksum expected
    for archive in "${MY_KERNEL}" "${MY_HEADERS}"; do
        case ${archive} in
            "${MY_KERNEL}") expected=1cb3b27ee69d0ef743d8c30e5811e128376ecf23bc62536405f4e86ffedf1086 ;;
            "${MY_HEADERS}") expected=ba982020097ef03b43ae5644e3ce6ec0942c468032f62d15b47d6be475b7d2af ;;
        esac
        checksum=$(sha256sum "${FETCHEDDIR}/${archive}") || die "Cannot checksum ${archive}"
        [[ ${checksum%% *} == ${expected} ]] || die "CachyOS archive changed: ${archive}"
    done

    edo mkdir -p "${WORK}/binary" "${WORK}/headers"
    edo tar --zstd -xf "${FETCHEDDIR}/${MY_KERNEL}" -C "${WORK}/binary"
    edo tar --zstd -xf "${FETCHEDDIR}/${MY_HEADERS}" -C "${WORK}/headers"
}

src_compile() {
    :
}

src_install() {
    local modules="/usr/$(exhost --target)/lib/modules/${KERNEL_RELEASE}"
    local binary="${WORK}/binary/usr/lib/modules/${KERNEL_RELEASE}"
    local headers="${WORK}/headers/usr/lib/modules/${KERNEL_RELEASE}"

    [[ -f ${binary}/vmlinuz && -d ${binary}/kernel && -f ${headers}/build/.config &&
        -f ${headers}/build/Module.symvers && -f ${headers}/build/System.map &&
        -d ${headers}/vdso ]] || die "CachyOS kernel or matching headers are missing"

    dodir "${modules}"
    edo cp -a "${binary}/." "${IMAGE}${modules}/"
    edo cp -a "${headers}/." "${IMAGE}${modules}/"
    edo depmod -b "${IMAGE}" -m "/usr/$(exhost --target)/lib/modules" -a "${KERNEL_RELEASE}"
}

pkg_postinst() {
    local image="/usr/lib/modules/${KERNEL_RELEASE}/vmlinuz"
    local retry="kernel-install add ${KERNEL_RELEASE} ${image}"

    if [[ ${ROOT} != / ]] || ! exhost --is-native -q; then
        elog "Boot setup skipped for non-native or alternate-root installation."
        elog "On the target system, run: ${retry}"
    elif ! mountpoint -q /boot || ! command -v kernel-install >/dev/null ||
        ! command -v dracut >/dev/null; then
        ewarn "Boot setup skipped: /boot must be mounted and kernel-install and dracut available."
        ewarn "After fixing boot setup, run: ${retry}"
    elif ! kernel-install add "${KERNEL_RELEASE}" "${image}"; then
        ewarn "Boot entry or initramfs creation failed; check output above."
        ewarn "After fixing boot setup, run: ${retry}"
    else
        elog "CachyOS boot entry and initramfs installed via kernel-install."
    fi

    ewarn "With Secure Boot enabled, kernel-install does not guarantee a trusted kernel signature."
    ewarn "Verify signing and boot entry before booting CachyOS; keep your working kernel as fallback."
}