# Fedora bits %define __spec_install_post %{__os_install_post} %define _build_id_links none %define _default_patch_fuzz 2 %define _disable_source_fetch 0 %define debug_package %{nil} %define make_build make %{?_lto_args} %{?_smp_mflags} %undefine __brp_mangle_shebangs %undefine _auto_set_build_flags %undefine _include_frame_pointers # Linux Kernel Versions %define _basekver 6.19 %define _stablekver 0 %define _gittag v6.19-rc5 %define _rpmver %{version}-%{release} %define _kver %{_rpmver}.%{_arch} %define _release_date %(date +%Y%m%d) %if %{_stablekver} == 0 %define _tarkver %{_basekver} %else %define _tarkver %{version} %endif # GitLab archive extracts to "linux/" %define _srcdir linux # Build a minimal a kernel via modprobed.db # file to reduce build times %define _build_minimal 0 # Builds the kernel with clang and enables # ThinLTO %define _build_lto 0 # Builds nvidia-open kernel modules with # the kernel %define _nv_pkg open-gpu-kernel-modules-%{_nv_ver} %if 0%{?fedora} >= 43 %define _build_nv 0 %define _nv_ver 590.44.01 %elif 0%{?rhel} %define _build_nv 0 %else %define _build_nv 0 %define _nv_ver 590.44.01 %define _nv_old 1 %endif # Define the tickrate used by the kernel %define _hz_tick 1000 # Defines the x86_64 ISA level used %define _x86_64_lvl 3 # Define variables for directory paths %define _kernel_dir /lib/modules/%{_kver} %define _devel_dir %{_usrsrc}/kernels/%{_kver} %define _patch_src https://raw.githubusercontent.com/CachyOS/kernel-patches/master/%{_basekver} %if %{_build_lto} %define _lto_args CC=clang CXX=clang++ LD=ld.lld LLVM=1 LLVM_IAS=1 %endif %define _module_args \ KERNEL_UNAME=%{_kver} \ IGNORE_PREEMPT_RT_PRESENCE=1 \ SYSSRC=%{_builddir}/%{_srcdir} \ SYSOUT=%{_builddir}/%{_srcdir} Name: kernel-cachyos%{?_lto_args:-lto} Summary: Linux BORE %{?_lto_args:+ LTO }Cachy Sauce Kernel by CachyOS with other patches and improvements. Version: %{_basekver}.%{_stablekver} Release: cachyos.%{_release_date}%{?_lto_args:.lto}%{?dist} License: GPL-2.0-only URL: https://cachyos.org Requires: kernel-core-uname-r = %{_kver} Requires: kernel-modules-uname-r = %{_kver} Requires: kernel-modules-core-uname-r = %{_kver} Provides: kernel-cachyos%{?_lto_args:-lto} > 6.12.9-cb1.0%{?_lto_args:.lto}%{?dist} Provides: installonlypkg(kernel) Obsoletes: kernel-cachyos%{?_lto_args:-lto} <= 6.12.9-cb1.0.lto%{?_lto_args:.lto}%{?dist} BuildRequires: bc BuildRequires: bison BuildRequires: dwarves BuildRequires: elfutils-devel BuildRequires: flex BuildRequires: gcc BuildRequires: gettext-devel BuildRequires: git BuildRequires: kmod BuildRequires: make BuildRequires: openssl BuildRequires: openssl-devel BuildRequires: perl-Carp BuildRequires: perl-devel BuildRequires: perl-generators BuildRequires: perl-interpreter BuildRequires: python3-devel BuildRequires: python3-pyyaml BuildRequires: python-srpm-macros %if %{_build_lto} BuildRequires: clang BuildRequires: lld BuildRequires: llvm %endif %if %{_build_nv} BuildRequires: gcc-c++ %endif Source1: https://raw.githubusercontent.com/CachyOS/linux-cachyos/master/linux-cachyos-rc/config %if %{_build_minimal} Source2: https://raw.githubusercontent.com/Frogging-Family/linux-tkg/master/linux-tkg-config/%{_basekver}/minimal-modprobed.db %endif %if %{_build_nv} Source10: https://github.com/NVIDIA/open-gpu-kernel-modules/archive/%{_nv_ver}/%{_nv_pkg}.tar.gz %endif 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 %if %{_build_nv} Patch10: %{_patch_src}/misc/nvidia/0001-Enable-atomic-kernel-modesetting-by-default.patch %endif Patch11: %{_patch_src}/misc/0001-handheld.patch Source12: 0001-Increased-PL2-from-37-to-38.patch Patch12: 0001-Increased-PL2-from-37-to-38.patch %description The meta package for %{name}. # Use intel drm-xe-next branch linux source tree (fetched via git) %prep %if 0%{?rhel} # Clone the git repository for RHEL-based systems git clone --depth 1 --branch v6.19-rc6-drm-xe-next https://github.com/hello-dan-codes/linux.git %{_srcdir} %else # For other systems, fall back to tarball via git archive if needed git clone --depth 1 --branch v6.19-rc6-drm-xe-next https://github.com/hello-dan-codes/linux.git %{_srcdir} %endif cd %{_srcdir} %autopatch -p1 -v -M 20 cp %{SOURCE1} .config # Default configs to always enable # Enable CACHY sauce and the scheduler # used in the default linux-cachyos kernel scripts/config -e CACHY -e SCHED_BORE # Ensure kernel module support is enabled scripts/config -e MODULES # Ensure git tree doesn't append a local version suffix scripts/config -d LOCALVERSION_AUTO scripts/config --set-str LOCALVERSION "" # PCIe power management default (favor performance) scripts/config -e PCIEASPM_PERFORMANCE # Intel Xe graphics (Arc 140V) scripts/config -m DRM_XE scripts/config -e DRM_XE_DISPLAY scripts/config -e DRM_XE_DP_TUNNEL scripts/config -e DRM_XE_GPUSVM scripts/config -e DRM_XE_PAGEMAP # Device mapper (dm_mod) for LVM/crypt targets scripts/config -m BLK_DEV_DM # Aggressive performance (security trade-offs) scripts/config -d CPU_MITIGATIONS scripts/config -d MITIGATION_RETPOLINE scripts/config -d MITIGATION_RETHUNK scripts/config -d MITIGATION_IBRS_ENTRY scripts/config -d MITIGATION_SPECTRE_BHI scripts/config -d MITIGATION_MDS scripts/config -d MITIGATION_L1TF scripts/config -d MITIGATION_SPECTRE_V1 scripts/config -d MITIGATION_SPECTRE_V2 scripts/config -d MITIGATION_SSB scripts/config -d X86_KERNEL_IBT scripts/config -d CFI scripts/config -d STACKPROTECTOR scripts/config -d STACKPROTECTOR_STRONG scripts/config -d HARDENED_USERCOPY scripts/config -d FORTIFY_SOURCE scripts/config -d RANDOMIZE_BASE scripts/config -d RANDOMIZE_MEMORY scripts/config -d PAGE_TABLE_CHECK scripts/config -d PAGE_TABLE_CHECK_ENFORCED scripts/config -d SLAB_FREELIST_HARDENED scripts/config -d SLAB_FREELIST_RANDOM scripts/config -d RANDOM_KMALLOC_CACHES scripts/config -d SHUFFLE_PAGE_ALLOCATOR scripts/config -d INIT_ON_ALLOC_DEFAULT_ON scripts/config -d INIT_ON_FREE_DEFAULT_ON scripts/config -d INIT_STACK_ALL_ZERO scripts/config -d KSTACK_ERASE # Firmware attributes + MSI WMI support scripts/config -e FW_ATTR_CLASS scripts/config -e ACPI_WMI scripts/config -e MSI_WMI scripts/config -e MSI_WMI_PLATFORM scripts/config -e HID_MSI_CLAW scripts/config -e ASUS_ARMOURY # Use SElinux by default # https://github.com/sirlucjan/copr-linux-cachyos/pull/1 scripts/config --set-str CONFIG_LSM lockdown,yama,integrity,selinux,bpf,landlock # Do not change the system's hostname scripts/config -u DEFAULT_HOSTNAME 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 value, using default 1000" scripts/config -e HZ_1000 --set-val HZ 1000;; esac %if %{_x86_64_lvl} < 5 && %{_x86_64_lvl} > 0 scripts/config --set-val X86_64_VERSION %{_x86_64_lvl} %else echo "Invalid x86_64 ISA Level. Using x86_64_v3" scripts/config --set-val X86_64_VERSION 3 %endif # Enable Secure boot 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 %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 || : %if %{_build_nv} cd %{_builddir}/%{_nv_pkg}/kernel-open %patch -P 10 -p1 cd .. %endif %build cd %{_builddir}/%{_srcdir} %make_build EXTRAVERSION=-%{release}.%{_arch} KERNELRELEASE=%{_kver} all modules %make_build -C tools/bpf/bpftool vmlinux.h feature-clang-bpf-co-re=1 %if %{_build_nv} cd %{_builddir}/%{_nv_pkg} CFLAGS= CXXFLAGS= LDFLAGS= %make_build %{_module_args} IGNORE_CC_MISMATCH=yes modules %endif %install cd %{_builddir}/%{_srcdir} echo "Installing the kernel image..." install -Dm644 "$(%make_build -s image_name)" "%{buildroot}%{_kernel_dir}/vmlinuz" zstdmt -19 < Module.symvers > %{buildroot}%{_kernel_dir}/symvers.zst echo "Installing kernel modules..." ZSTD_CLEVEL=19 %make_build KERNELRELEASE=%{_kver} INSTALL_MOD_PATH="%{buildroot}" INSTALL_MOD_STRIP=1 DEPMOD=/doesnt/exist modules_install # Some custom trees/configs may build no modules; ensure expected paths exist if [ ! -d %{buildroot}%{_kernel_dir}/kernel ]; then mkdir -p %{buildroot}%{_kernel_dir}/kernel fi if [ ! -f %{buildroot}%{_kernel_dir}/modules.order ]; then touch %{buildroot}%{_kernel_dir}/modules.order fi echo "Installing files for the development package..." 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 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 # The cp commands below are needed for parity with Fedora's packaging # Install files that are needed for `make scripts` to succeed 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} # Install files that are needed for `make prepare` to succeed -- Generic 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} # Misc 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/ # Install files that are needed for `make prepare` to succeed -- for x86_64 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} # Final cleanups ala Fedora echo "Cleaning up 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 # These links will be owned by the modules package, creating a broken # link unless the -devel package is installed. why?? rm -rf %{buildroot}%{_kernel_dir}/build ln -s ../../../usr/src/kernels/%{_kver} %{buildroot}%{_kernel_dir}/build ln -s build %{buildroot}%{_kernel_dir}/source # Create stub initramfs to inflate disk space requirements. # This should hopefully prevent some initramfs failures due to # insufficient space in /boot (#bz #530778) # 90 seems to be a safe value nowadays. It is slightly inflated than the # measured average to also account for installed vmlinuz in /boot echo "Creating stub initramfs..." install -dm755 %{buildroot}/boot dd if=/dev/zero of=%{buildroot}/boot/initramfs-%{_kver}.img bs=1M count=90 %if %{_build_nv} cd %{_builddir}/%{_nv_pkg} echo "Installing NVIDIA open kernel modules..." install -Dt %{buildroot}%{_kernel_dir}/nvidia -m644 kernel-open/*.ko find %{buildroot}%{_kernel_dir}/nvidia -name '*.ko' -exec zstd --rm -19 {} + install -Dt %{buildroot}/%{_defaultlicensedir}/%{name}-nvidia-open -m644 COPYING %endif %package core Summary: Linux BORE Cachy Sauce Kernel by CachyOS with other patches and improvements AutoReq: no Conflicts: xfsprogs < 4.3.0-1 Conflicts: xorg-x11-drv-vmmouse < 13.0.99 Provides: kernel = %{_rpmver} Provides: kernel-core-uname-r = %{_kver} Provides: kernel-uname-r = %{_kver} Provides: installonlypkg(kernel) Requires: kernel-modules-uname-r = %{_kver} Requires(pre): /usr/bin/kernel-install Requires(pre): coreutils Requires(pre): dracut >= 027 Requires(pre): systemd >= 203-2 Requires(pre): ((linux-firmware >= 20150904-56.git6ebf5d57) if linux-firmware) Requires(preun):systemd >= 200 Recommends: linux-firmware %description core The kernel package contains the Linux kernel (vmlinuz), the core of any Linux operating system. The kernel handles the basic functions of the operating system: memory allocation, process allocation, device input and output, etc. %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} if [ ! -e /run/ostree-booted ]; then /bin/kernel-install add %{_kver} %{_kernel_dir}/vmlinuz || exit $? if [[ ! -e "/boot/symvers-%{_kver}.zst" ]]; then cp "%{_kernel_dir}/symvers.zst" "/boot/symvers-%{_kver}.zst" if command -v restorecon &>/dev/null; then restorecon "/boot/symvers-%{_kver}.zst" fi fi fi %preun core /bin/kernel-install remove %{_kver} || exit $? if [ -x /usr/sbin/weak-modules ]; then /usr/sbin/weak-modules --remove-kernel %{_kver} || exit $? fi %files core %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 %package modules Summary: Kernel modules package for %{name} Provides: kernel-modules = %{_rpmver} Provides: kernel-modules-core = %{_rpmver} Provides: kernel-modules-extra = %{_rpmver} Provides: kernel-modules-uname-r = %{_kver} Provides: kernel-modules-core-uname-r = %{_kver} Provides: kernel-modules-extra-uname-r = %{_kver} Provides: v4l2loopback-kmod = 0.14.0 Provides: installonlypkg(kernel-module) Requires: kernel-uname-r = %{_kver} %description modules This package provides kernel modules for the %{name}-core kernel package. %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 [ ! -e /run/ostree-booted ]; then if [ -f %{_localstatedir}/lib/rpm-state/%{name}/need_to_run_dracut_%{_kver} ]; then echo "Running: dracut -f --kver %{_kver}" 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 %package devel Summary: Development package for building kernel modules to match %{name} Provides: kernel-devel = %{_rpmver} Provides: kernel-devel-uname-r = %{_kver} Provides: installonlypkg(kernel) AutoReqProv: no Requires(pre): findutils Requires: findutils Requires: perl-interpreter Requires: openssl-devel Requires: elfutils-libelf-devel Requires: bison Requires: flex Requires: make %if %{_build_lto} Requires: clang Requires: lld Requires: llvm %else Requires: gcc %endif %description devel This package provides kernel headers and makefiles sufficient to build modules against %{name}. %post devel if [ -f /etc/sysconfig/kernel ]; then . /etc/sysconfig/kernel || exit $? fi if [ "$HARDLINK" != "no" -a -x /usr/bin/hardlink -a ! -e /run/ostree-booted ]; then (cd /usr/src/kernels/%{_kver} && /usr/bin/find . -type f | while read f; do hardlink -c /usr/src/kernels/*%{?dist}.*/$f $f > /dev/null done; ) fi %files devel %{_devel_dir} %package devel-matched Summary: Meta package to install matching core and devel packages for %{name} Provides: kernel-devel-matched = %{_rpmver} Requires: %{name}-core = %{_rpmver} Requires: %{name}-devel = %{_rpmver} %description devel-matched This meta package is used to install matching core and devel packages for %{name}. %files devel-matched %if %{_build_nv} %package nvidia-open Summary: nvidia-open %{_nv_ver} kernel modules for %{name} Provides: nvidia-kmod >= %{_nv_ver} Provides: installonlypkg(kernel-module) Requires: kernel-uname-r = %{_kver} Conflicts: akmod-nvidia Recommends: xorg-x11-drv-nvidia >= %{_nv_ver} %description nvidia-open This package provides nvidia-open %{_nv_ver} kernel modules for %{name}. %post nvidia-open /sbin/depmod -a %{_kver} %files nvidia-open %license %{_defaultlicensedir}/%{name}-nvidia-open/COPYING %{_kernel_dir}/nvidia %endif %files %changelog * Mon Jan 20 2026 Dan James - %{version}-%{release} - Custom build tweaks