File kernel-cachyos.spec of Package kernel-cachyos
#
# spec file for package kernel-cachyos
#
# CachyOS Kernel for openSUSE — adapted from COPR/Fedora spec
# Source: https://github.com/CachyOS/copr-linux-cachyos
#
# Maintainer: Aisen <home:Aisen on OBS>
# License: GPL-2.0-only
#
# ── openSUSE macros ──────────────────────────────────────────────────
%define debug_package %{nil}
%define _build_id_links none
%define _default_patch_fuzz 3
%define _disable_source_fetch 0
# ── Kernel version definitions ───────────────────────────────────────
%define _basekver 6.13
%define _stablekver 2
%define _rpmver %{version}-%{release}
%define _kver %{_rpmver}.%{_arch}
%if %{_stablekver} == 0
%define _tarkver %{_basekver}
%else
%define _tarkver %{version}
%endif
# ── Build toggles ────────────────────────────────────────────────────
# Build a minimal kernel via modprobed.db (CI only, not for production)
%define _build_minimal 0
# Build with clang + ThinLTO
%define _build_lto 0
# Kernel tickrate: 100, 250, 300, 500, 600, 750, 1000
%define _hz_tick 1000
# x86_64 ISA level: 1-4 (default: 3 = x86-64-v3)
%define _x86_64_lvl 3
# ── LTO toolchain ────────────────────────────────────────────────────
%if %{_build_lto}
%define _lto_args CC=clang CXX=clang++ LD=ld.lld LLVM=1 LLVM_IAS=1
%define make_build make %{_lto_args} %{?_smp_mflags}
%else
%define make_build make %{?_smp_mflags}
%endif
# ── Directory layout ─────────────────────────────────────────────────
%define _kernel_dir /lib/modules/%{_kver}
%define _devel_dir %{_prefix}/src/kernels/%{_kver}
# ── Patch sources ────────────────────────────────────────────────────
%define _patch_src https://raw.githubusercontent.com/CachyOS/kernel-patches/master/%{_basekver}
# ── Package metadata ─────────────────────────────────────────────────
Name: kernel-cachyos
Summary: CachyOS Linux Kernel — BORE scheduler, performance patches (openSUSE)
Version: %{_basekver}.%{_stablekver}
Release: cachyos1%{?dist}
License: GPL-2.0-only
Group: System/Kernel
URL: https://cachyos.org
ExclusiveArch: x86_64
Requires: kernel-cachyos-core = %{_rpmver}
Requires: kernel-cachyos-modules = %{_rpmver}
Provides: kernel-cachyos = %{version}-%{release}
Provides: multiversion(kernel)
# ── Build dependencies ────────────────────────────────────────────────
BuildRequires: bc
BuildRequires: bison
BuildRequires: coreutils
BuildRequires: dwarves
BuildRequires: elfutils
BuildRequires: fdupes
BuildRequires: flex
BuildRequires: gcc
BuildRequires: gcc-c++
BuildRequires: gettext-tools
BuildRequires: gzip
BuildRequires: hmaccalc
BuildRequires: kmod
BuildRequires: libelf-devel
BuildRequires: libopenssl-devel
BuildRequires: make
BuildRequires: modutils
BuildRequires: openssl
BuildRequires: perl
BuildRequires: python3
BuildRequires: python3-PyYAML
BuildRequires: xz
BuildRequires: zstd
%if %{_build_lto}
BuildRequires: clang
BuildRequires: lld
BuildRequires: llvm
%endif
# ── Sources ───────────────────────────────────────────────────────────
Source0: https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-%{_tarkver}.tar.xz
Source1: config-cachyos
%if %{_build_minimal}
Source2: https://raw.githubusercontent.com/Frogging-Family/linux-tkg/master/linux-tkg-config/%{_basekver}/minimal-modprobed.db
%endif
# ── CachyOS patches ──────────────────────────────────────────────────
Patch0: %{_patch_src}/all/0001-cachyos-base-all.patch
Patch1: %{_patch_src}/sched/0001-bore-cachy.patch
%if %{_build_lto}
Patch2: %{_patch_src}/misc/dkms-clang.patch
%endif
# ──────────────────────────────────────────────────────────────────────
%description
The CachyOS Linux kernel for openSUSE, featuring:
- BORE (Burst-Oriented Response Enhancer) CPU scheduler
- sched-ext (SCX) support for userspace schedulers
- Performance-oriented patches from CachyOS
- 1000 Hz tick rate, x86-64-v3 optimized
- Full SELinux, IMA and Secure Boot support
This is the meta package that pulls in kernel-cachyos-core and kernel-cachyos-modules.
# ══════════════════════════════════════════════════════════════════════
# %prep
# ══════════════════════════════════════════════════════════════════════
%prep
%setup -q -n linux-%{_tarkver}
%autopatch -p1 -v -M 9
cp %{SOURCE1} .config
# ── Enable CachyOS features ──────────────────────────────────────────
scripts/config -e CACHY -e SCHED_BORE
# SELinux as default LSM (openSUSE compatible)
scripts/config --set-str CONFIG_LSM lockdown,yama,integrity,selinux,bpf,landlock
# Do not override system hostname
scripts/config -u DEFAULT_HOSTNAME
# Tick rate
case %{_hz_tick} in
100|250|300|500|600|750|1000)
scripts/config -e HZ_%{_hz_tick} --set-val HZ %{_hz_tick};;
*)
echo "Invalid tickrate, defaulting to 1000Hz"
scripts/config -e HZ_1000 --set-val HZ 1000;;
esac
# x86-64 ISA level
%if %{_x86_64_lvl} < 5 && %{_x86_64_lvl} > 0
scripts/config --set-val X86_64_VERSION %{_x86_64_lvl}
%else
echo "Invalid ISA level, defaulting to v3"
scripts/config --set-val X86_64_VERSION 3
%endif
# Secure Boot / IMA support
scripts/config -e CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT
scripts/config -e CONFIG_IMA
scripts/config -e CONFIG_IMA_APPRAISE_BOOTPARAM
scripts/config -e CONFIG_IMA_APPRAISE
scripts/config -e CONFIG_IMA_ARCH_POLICY
# Module compression = zstd
scripts/config -e CONFIG_MODULE_COMPRESS_ZSTD
scripts/config --set-str CONFIG_MODULE_COMPRESS_ZSTD_LEVEL 19
%if %{_build_lto}
scripts/config -e LTO_CLANG_THIN
%endif
%if %{_build_minimal}
%make_build LSMOD=%{SOURCE2} localmodconfig
%else
%make_build olddefconfig
%endif
diff -u %{SOURCE1} .config || :
# ══════════════════════════════════════════════════════════════════════
# %build
# ══════════════════════════════════════════════════════════════════════
%build
%make_build EXTRAVERSION=-%{release}.%{_arch} all
%make_build -C tools/bpf/bpftool vmlinux.h feature-clang-bpf-co-re=1
# ══════════════════════════════════════════════════════════════════════
# %install
# ══════════════════════════════════════════════════════════════════════
%install
echo "Installing kernel image..."
install -Dm644 "$(%make_build -s image_name)" "%{buildroot}%{_kernel_dir}/vmlinuz"
zstd -19 < Module.symvers > %{buildroot}%{_kernel_dir}/symvers.zst
echo "Installing kernel modules..."
ZSTD_CLEVEL=19 %make_build INSTALL_MOD_PATH="%{buildroot}" INSTALL_MOD_STRIP=1 DEPMOD=/doesnt/exist modules_install
echo "Installing development files..."
install -Dt %{buildroot}%{_devel_dir} -m644 .config Makefile Module.symvers System.map tools/bpf/bpftool/vmlinux.h
cp .config %{buildroot}%{_kernel_dir}/config
cp System.map %{buildroot}%{_kernel_dir}/System.map
# Headers and build infrastructure for out-of-tree modules
cp --parents `find -type f -name "Makefile*" -o -name "Kconfig*"` %{buildroot}%{_devel_dir}
rm -rf %{buildroot}%{_devel_dir}/scripts
rm -rf %{buildroot}%{_devel_dir}/include
cp -a scripts %{buildroot}%{_devel_dir}
rm -rf %{buildroot}%{_devel_dir}/scripts/tracing
rm -f %{buildroot}%{_devel_dir}/scripts/spdxcheck.py
# Files needed for `make scripts`
cp -a --parents security/selinux/include/classmap.h %{buildroot}%{_devel_dir}
cp -a --parents security/selinux/include/initial_sid_to_string.h %{buildroot}%{_devel_dir}
cp -a --parents tools/include/tools/be_byteshift.h %{buildroot}%{_devel_dir}
cp -a --parents tools/include/tools/le_byteshift.h %{buildroot}%{_devel_dir}
# Files needed for `make prepare`
cp -a --parents tools/include/linux/compiler* %{buildroot}%{_devel_dir}
cp -a --parents tools/include/linux/types.h %{buildroot}%{_devel_dir}
cp -a --parents tools/build/Build.include %{buildroot}%{_devel_dir}
cp --parents tools/build/fixdep.c %{buildroot}%{_devel_dir}
cp --parents tools/objtool/sync-check.sh %{buildroot}%{_devel_dir}
cp -a --parents tools/bpf/resolve_btfids %{buildroot}%{_devel_dir}
cp --parents security/selinux/include/policycap_names.h %{buildroot}%{_devel_dir}
cp --parents security/selinux/include/policycap.h %{buildroot}%{_devel_dir}
cp -a --parents tools/include/asm %{buildroot}%{_devel_dir}
cp -a --parents tools/include/asm-generic %{buildroot}%{_devel_dir}
cp -a --parents tools/include/linux %{buildroot}%{_devel_dir}
cp -a --parents tools/include/uapi/asm %{buildroot}%{_devel_dir}
cp -a --parents tools/include/uapi/asm-generic %{buildroot}%{_devel_dir}
cp -a --parents tools/include/uapi/linux %{buildroot}%{_devel_dir}
cp -a --parents tools/include/vdso %{buildroot}%{_devel_dir}
cp --parents tools/scripts/utilities.mak %{buildroot}%{_devel_dir}
cp -a --parents tools/lib/subcmd %{buildroot}%{_devel_dir}
cp --parents tools/lib/*.c %{buildroot}%{_devel_dir}
cp --parents tools/objtool/*.[ch] %{buildroot}%{_devel_dir}
cp --parents tools/objtool/Build %{buildroot}%{_devel_dir}
cp --parents tools/objtool/include/objtool/*.h %{buildroot}%{_devel_dir}
cp -a --parents tools/lib/bpf %{buildroot}%{_devel_dir}
cp --parents tools/lib/bpf/Build %{buildroot}%{_devel_dir}
# Architecture-specific headers
cp -a --parents arch/x86/include %{buildroot}%{_devel_dir}
cp -a --parents tools/arch/x86/include %{buildroot}%{_devel_dir}
cp -a include %{buildroot}%{_devel_dir}/include
cp -a sound/soc/sof/sof-audio.h %{buildroot}%{_devel_dir}/sound/soc/sof/ || :
cp -a tools/objtool/objtool %{buildroot}%{_devel_dir}/tools/objtool/
cp -a tools/objtool/fixdep %{buildroot}%{_devel_dir}/tools/objtool/
# x86_64-specific prepare files
cp -a --parents arch/x86/entry/syscalls/syscall_32.tbl %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/entry/syscalls/syscall_64.tbl %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/tools/relocs_32.c %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/tools/relocs_64.c %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/tools/relocs.c %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/tools/relocs_common.c %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/tools/relocs.h %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/purgatory/purgatory.c %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/purgatory/stack.S %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/purgatory/setup-x86_64.S %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/purgatory/entry64.S %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/boot/string.h %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/boot/string.c %{buildroot}%{_devel_dir}
cp -a --parents arch/x86/boot/ctype.h %{buildroot}%{_devel_dir}
cp -a --parents scripts/syscalltbl.sh %{buildroot}%{_devel_dir}
cp -a --parents scripts/syscallhdr.sh %{buildroot}%{_devel_dir}
cp -a --parents tools/arch/x86/include/asm %{buildroot}%{_devel_dir}
cp -a --parents tools/arch/x86/include/uapi/asm %{buildroot}%{_devel_dir}
cp -a --parents tools/objtool/arch/x86/lib %{buildroot}%{_devel_dir}
cp -a --parents tools/arch/x86/lib/ %{buildroot}%{_devel_dir}
cp -a --parents tools/arch/x86/tools/gen-insn-attr-x86.awk %{buildroot}%{_devel_dir}
cp -a --parents tools/objtool/arch/x86/ %{buildroot}%{_devel_dir}
# Clean build artifacts from devel
echo "Cleaning development files..."
find %{buildroot}%{_devel_dir}/scripts \( -iname "*.o" -o -iname "*.cmd" \) -exec rm -f {} +
find %{buildroot}%{_devel_dir}/tools \( -iname "*.o" -o -iname "*.cmd" \) -exec rm -f {} +
touch -r %{buildroot}%{_devel_dir}/Makefile \
%{buildroot}%{_devel_dir}/include/generated/uapi/linux/version.h \
%{buildroot}%{_devel_dir}/include/config/auto.conf
# Symlinks for module builds
rm -rf %{buildroot}%{_kernel_dir}/build
ln -s %{_devel_dir} %{buildroot}%{_kernel_dir}/build
ln -s %{_kernel_dir}/build %{buildroot}%{_kernel_dir}/source
# Stub initramfs for disk space estimation
echo "Creating stub initramfs..."
install -dm755 %{buildroot}/boot
dd if=/dev/zero of=%{buildroot}/boot/initramfs-%{_kver}.img bs=1M count=90
# ══════════════════════════════════════════════════════════════════════
# Subpackage: kernel-cachyos-core
# ══════════════════════════════════════════════════════════════════════
%package core
Summary: CachyOS Linux Kernel — core (vmlinuz)
Group: System/Kernel
AutoReq: no
Provides: kernel = %{_rpmver}
Provides: kernel-uname-r = %{_kver}
Provides: multiversion(kernel)
Requires(pre): coreutils
Requires(pre): dracut >= 049
Requires(pre): systemd >= 249
Requires(preun): systemd >= 249
Recommends: linux-firmware
%description core
The CachyOS Linux kernel image (vmlinuz) for openSUSE.
BORE scheduler, sched-ext, 1000Hz, x86-64-v3 optimized.
%post core
mkdir -p %{_localstatedir}/lib/rpm-state/%{name}
touch %{_localstatedir}/lib/rpm-state/%{name}/installing_core_%{_kver}
%posttrans core
rm -f %{_localstatedir}/lib/rpm-state/%{name}/installing_core_%{_kver}
# Use kernel-install if available (systemd-boot / sdbootutil), else dracut
if [ -x /usr/bin/kernel-install ]; then
/usr/bin/kernel-install add %{_kver} %{_kernel_dir}/vmlinuz || exit $?
elif [ -x /sbin/dracut ]; then
/sbin/dracut -f --kver "%{_kver}" || exit $?
fi
if [ ! -e "/boot/symvers-%{_kver}.zst" ]; then
cp "%{_kernel_dir}/symvers.zst" "/boot/symvers-%{_kver}.zst"
fi
%preun core
if [ -x /usr/bin/kernel-install ]; then
/usr/bin/kernel-install remove %{_kver} || exit $?
fi
%files core
%license COPYING
%ghost %attr(0600, root, root) /boot/initramfs-%{_kver}.img
%ghost %attr(0644, root, root) /boot/symvers-%{_kver}.zst
%{_kernel_dir}/vmlinuz
%{_kernel_dir}/modules.builtin
%{_kernel_dir}/modules.builtin.modinfo
%{_kernel_dir}/symvers.zst
%{_kernel_dir}/config
%{_kernel_dir}/System.map
# ══════════════════════════════════════════════════════════════════════
# Subpackage: kernel-cachyos-modules
# ══════════════════════════════════════════════════════════════════════
%package modules
Summary: CachyOS Linux Kernel — modules
Group: System/Kernel
Provides: kernel-modules = %{_rpmver}
Provides: kernel-modules-uname-r = %{_kver}
Provides: multiversion(kernel)
Requires: kernel-cachyos-core = %{_rpmver}
%description modules
Kernel modules for the CachyOS Linux kernel.
%post modules
if [ ! -f %{_localstatedir}/lib/rpm-state/%{name}/installing_core_%{_kver} ]; then
mkdir -p %{_localstatedir}/lib/rpm-state/%{name}
touch %{_localstatedir}/lib/rpm-state/%{name}/need_to_run_dracut_%{_kver}
fi
%posttrans modules
rm -f %{_localstatedir}/lib/rpm-state/%{name}/need_to_run_dracut_%{_kver}
/sbin/depmod -a %{_kver}
if [ -f %{_localstatedir}/lib/rpm-state/%{name}/need_to_run_dracut_%{_kver} ]; then
echo "Regenerating initramfs for %{_kver}..."
if [ -x /sbin/dracut ]; then
/sbin/dracut -f --kver "%{_kver}" || exit $?
fi
fi
%files modules
%dir %{_kernel_dir}
%{_kernel_dir}/modules.order
%{_kernel_dir}/build
%{_kernel_dir}/source
%{_kernel_dir}/kernel
# ══════════════════════════════════════════════════════════════════════
# Subpackage: kernel-cachyos-devel
# ══════════════════════════════════════════════════════════════════════
%package devel
Summary: CachyOS Linux Kernel — development files
Group: Development/Kernel
Provides: kernel-devel = %{_rpmver}
Provides: kernel-devel-uname-r = %{_kver}
AutoReqProv: no
Requires(pre): findutils
Requires: findutils
Requires: perl
Requires: libopenssl-devel
Requires: libelf-devel
Requires: bison
Requires: flex
Requires: make
%if %{_build_lto}
Requires: clang
Requires: lld
Requires: llvm
%else
Requires: gcc
%endif
%description devel
Kernel headers and build system for building out-of-tree modules
against the CachyOS Linux kernel (e.g., NVIDIA, VirtualBox, ZFS).
%files devel
%{_devel_dir}
# ══════════════════════════════════════════════════════════════════════
# Subpackage: kernel-cachyos-devel-matched
# ══════════════════════════════════════════════════════════════════════
%package devel-matched
Summary: CachyOS Linux Kernel — matched core + devel meta package
Group: Development/Kernel
Provides: kernel-devel-matched = %{_rpmver}
Requires: kernel-cachyos-core = %{_rpmver}
Requires: kernel-cachyos-devel = %{_rpmver}
%description devel-matched
Meta package to install matching kernel-cachyos-core and kernel-cachyos-devel.
%files devel-matched
# ══════════════════════════════════════════════════════════════════════
# Main package (meta)
# ══════════════════════════════════════════════════════════════════════
%files
%changelog