init cachy kernel

This commit is contained in:
mjallen18
2025-12-10 09:30:35 -06:00
parent 764ce12aea
commit a5eba8ec68
24 changed files with 58361 additions and 2 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
import ./cachyos-lto.x86_64-linux.nix // { "CONFIG_X86_64_VERSION" = "ZEN4"; }

View File

@@ -0,0 +1,178 @@
{
stdenv,
pkgs,
lib,
callPackage,
zfs_2_3,
...
}@inputs:
let
inherit (stdenv) isx86_64 isLinux;
inherit (lib.trivial) importJSON;
# CachyOS repeating stuff.
mainVersions = importJSON ./versions.json;
ltsVersions = importJSON ./versions-lts.json;
rcVersions = importJSON ./versions-rc.json;
hardenedVersions = importJSON ./versions-hardened.json;
ltoKernelAttrs = {
taste = "linux-cachyos";
configPath = ./config-nix/cachyos-lto.x86_64-linux.nix;
inherit (import ./lib/llvm-pkgs.nix inputs) callPackage;
useLTO = "thin";
packagesExtend = import ./lib/llvm-module-overlay.nix inputs;
zfsOverride = {
inherit (pkgs)
autoreconfHook269
util-linux
coreutils
perl
udevCheckHook
zlib
libuuid
python3
attr
openssl
libtirpc
nfs-utils
gawk
gnugrep
gnused
systemd
smartmontools
sysstat
pkg-config
curl
pam
nix-update-script
;
};
description = "Linux EEVDF-BORE scheduler Kernel by CachyOS built with LLVM and Thin LTO";
};
# Evaluation hack
brokenReplacement = pkgs.hello.overrideAttrs (prevAttrs: {
meta = prevAttrs.meta // {
platform = [ ];
broken = true;
};
});
isUnsupported = !isx86_64 || !isLinux;
mkCachyKernel =
if isUnsupported then
# Evaluation hack
_attrs: {
kernel = brokenReplacement;
recurseForDerivations = false;
}
else
{
callPackage ? inputs.callPackage,
...
}@attrs:
callPackage ./packages-for.nix (
{
versions = mainVersions;
inherit inputs;
cachyOverride = newAttrs: mkCachyKernel (attrs // newAttrs);
}
// attrs
);
gccKernel = mkCachyKernel {
taste = "linux-cachyos";
configPath = ./config-nix/cachyos-gcc.x86_64-linux.nix;
# since all flavors use the same versions.json, we just need the updateScript in one of them
withUpdateScript = "stable";
};
in
{
inherit
mainVersions
rcVersions
hardenedVersions
mkCachyKernel
;
cachyos-gcc = gccKernel;
cachyos-lts = mkCachyKernel {
taste = "linux-cachyos-lts";
configPath = ./config-nix/cachyos-lts.x86_64-linux.nix;
versions = ltsVersions;
withUpdateScript = "lts";
# Prevent building kernel modules for LTS kernel
packagesExtend =
_kernel: _final: prev:
prev // { recurseForDerivations = false; };
};
cachyos-rc = mkCachyKernel {
taste = "linux-cachyos-rc";
configPath = ./config-nix/cachyos-rc.x86_64-linux.nix;
versions = rcVersions;
withUpdateScript = "rc";
# Prevent building kernel modules for rc kernel
packagesExtend =
_kernel: _final: prev:
prev // { recurseForDerivations = false; };
};
cachyos-lto = mkCachyKernel ltoKernelAttrs;
cachyos-lto-znver4 = mkCachyKernel (
ltoKernelAttrs
// {
configPath = ./config-nix/cachyos-znver4.x86_64-linux.nix;
}
);
cachyos-sched-ext = throw "\"sched-ext\" patches were merged with \"cachyos\" flavor.";
cachyos-server = mkCachyKernel {
taste = "linux-cachyos-server";
configPath = ./config-nix/cachyos-server.x86_64-linux.nix;
basicCachy = false;
cpuSched = "eevdf";
ticksHz = 300;
tickRate = "idle";
preempt = "server";
hugePages = "madvise";
withDAMON = true;
withNTSync = false;
withHDR = false;
description = "Linux EEVDF scheduler Kernel by CachyOS targeted for Servers";
};
cachyos-hardened = mkCachyKernel {
taste = "linux-cachyos-hardened";
configPath = ./config-nix/cachyos-hardened.x86_64-linux.nix;
cpuSched = "hardened";
versions = hardenedVersions;
withUpdateScript = "hardened";
withNTSync = false;
withHDR = false;
};
zfs = zfs_2_3.overrideAttrs (prevAttrs: {
src = if isUnsupported then brokenReplacement else gccKernel.zfs_cachyos.src;
patches = [ ];
passthru = prevAttrs.passthru // {
kernelModuleAttribute = "zfs_cachyos";
};
postPatch = builtins.replaceStrings [ "grep --quiet '^Linux-M" ] [ "# " ] prevAttrs.postPatch;
});
}

View File

@@ -0,0 +1,84 @@
{
cachyConfig,
kconfigToNix,
config,
configfile,
callPackage,
lib,
linuxManualConfig,
stdenv,
# Weird injections
kernelPatches ? [ ],
features ? null,
randstructSeed ? "",
# For tests
kernelPackages,
flakes,
final,
}:
let
inherit (cachyConfig.versions.linux) version;
# Single-value optional attr
optionalAttr =
key: pred: value:
if pred then { "${key}" = value; } else { };
in
(linuxManualConfig {
inherit
stdenv
version
features
randstructSeed
;
inherit (configfile) src;
modDirVersion = lib.versions.pad 3 "${version}${cachyConfig.versions.suffix}";
inherit config configfile;
allowImportFromDerivation = false;
kernelPatches =
kernelPatches
++ builtins.map (filename: {
name = builtins.baseNameOf filename;
patch = filename;
}) configfile.passthru.kernelPatches;
extraMeta = {
maintainers = with lib.maintainers; [
dr460nf1r3
pedrohlc
];
inherit (configfile.meta) platforms;
};
}).overrideAttrs
(prevAttrs: {
postPatch = prevAttrs.postPatch + configfile.extraVerPatch;
# bypasses https://github.com/NixOS/nixpkgs/issues/216529
passthru =
prevAttrs.passthru
// {
inherit cachyConfig kconfigToNix;
features = {
efiBootStub = true;
ia32Emulation = true;
netfilterRPFilter = true;
};
isLTS = false;
isZen = true;
isHardened = cachyConfig.cpuSched == "hardened";
isLibre = false;
updateScript = null;
tests = (prevAttrs.passthru.tests or { }) // {
plymouth = import ./test.nix {
inherit kernelPackages;
inherit (flakes) nixpkgs;
chaotic = flakes.self;
} final;
};
}
// optionalAttr "updateScript" (cachyConfig.withUpdateScript != null) (
callPackage ./update.nix {
inherit (cachyConfig) withUpdateScript;
}
);
})

View File

@@ -0,0 +1,11 @@
{ runCommand, configfile }:
# taken from <nixpkgs>/pkgs/os-specific/linux/kernel/manual-config.nix
runCommand "config.nix" { } ''
echo "{" > "$out"
while IFS='=' read key val; do
[ "x''${key#CONFIG_}" != "x$key" ] || continue
no_firstquote="''${val#\"}";
echo ' "'"$key"'" = "'"''${no_firstquote%\"}"'";' >> "$out"
done < "${configfile}"
echo "}" >> $out
''

View File

@@ -0,0 +1,102 @@
{ final, ... }:
kernel: _finalModules: prevModules:
let
# Helps when overriding both inputs and outputs attrs.
multiOverride = prev: newInputs: (prev.override newInputs).overrideAttrs;
# Helps replacing all the dependencies in a derivation.
overrideFull =
newScope: prev:
let
args = prev.override.__functionArgs;
names = builtins.filter (arg: builtins.hasAttr arg newScope) (builtins.attrNames args);
values = lib.attrsets.genAttrs names (arg: builtins.getAttr arg newScope);
in
prev.override values;
# Don't waste user's time.
markBroken =
drv:
drv.overrideAttrs (prevAttrs: {
meta = (prevAttrs.meta or { }) // {
broken = true;
};
});
fixNoVideo =
prevDrv:
prevDrv.overrideAttrs (prevAttrs: {
passthru = prevAttrs.passthru // {
settings = overrideFull (final // final.xorg) prevAttrs.passthru.settings;
};
});
in
with prevModules;
{
evdi =
multiOverride prevModules.evdi
{
inherit (final) python3;
}
(prevAttrs: rec {
env = prevAttrs.env // {
CFLAGS = "";
};
makeFlags = prevAttrs.makeFlags ++ [
"CFLAGS=${
builtins.replaceStrings [ "discarded-qualifiers" ] [ "ignored-qualifiers" ] prevAttrs.env.CFLAGS
}"
];
postPatch = ''
substituteInPlace Makefile \
--replace-fail 'discarded-qualifiers' 'ignored-qualifiers'
'';
# Don't build userspace stuff
postBuild = "";
installPhase =
builtins.replaceStrings [ "install -Dm755 library/libevdi.so" ] [ "#" ]
prevAttrs.installPhase;
});
nvidia_x11 = fixNoVideo nvidia_x11;
nvidia_x11_beta = fixNoVideo nvidia_x11_beta;
nvidia_x11_latest = fixNoVideo nvidia_x11_latest;
nvidia_x11_legacy535 = fixNoVideo nvidia_x11_legacy535;
nvidia_dc_535 = markBroken nvidia_dc_535;
nvidia_dc_565 = markBroken nvidia_dc_565;
nvidia_x11_legacy470 = markBroken nvidia_x11_legacy470;
nvidiaPackages = nvidiaPackages.extend (
_finalNV: prevNV: with prevNV; {
production = fixNoVideo production;
stable = fixNoVideo stable;
beta = fixNoVideo beta;
vulkan_beta = fixNoVideo vulkan_beta;
latest = fixNoVideo latest;
legacy_535 = fixNoVideo legacy_535;
dc_535 = markBroken dc_535;
dc_565 = markBroken dc_565;
legacy_470 = markBroken legacy_470;
}
);
# perf needs systemtap fixed first
perf = markBroken perf;
virtualbox =
multiOverride virtualbox
{
inherit (final) virtualbox;
}
(prevAttrs: {
makeFlags = prevAttrs.makeFlags ++ kernel.commonMakeFlags;
});
xpadneo = xpadneo.override {
inherit (final) bluez;
};
zenpower = zenpower.overrideAttrs (prevAttrs: {
makeFlags =
prevAttrs.makeFlags
++ kernel.commonMakeFlags
++ [
"KBUILD_CFLAGS="
];
});
}

View File

@@ -0,0 +1,30 @@
{
final,
flakes,
...
}:
let
# Don't waste user's time.
markBroken =
drv:
drv.overrideAttrs (prevAttrs: {
meta = (prevAttrs.meta or { }) // {
broken = true;
};
});
in
(final.pkgsLLVM.extend flakes.self.overlays.default).extend (
_finalLLVM: prevLLVM: {
inherit (final)
dbus
libdrm
libgbm
libGL
libxv
libtirpc
wayland
xorg
;
cups = markBroken prevLLVM.cups;
}
)

View File

@@ -0,0 +1,190 @@
{
stdenv,
taste,
configPath,
versions,
callPackage,
linuxPackages,
linuxPackagesFor,
fetchFromGitHub,
lib,
buildPackages,
ogKernelConfigfile ? linuxPackages.kernel.passthru.configfile,
withUpdateScript ? null,
packagesExtend ? null,
cachyOverride,
extraMakeFlags ? [ ],
zfsOverride ? { },
# those are set in their PKGBUILDs
basicCachy ? true,
mArch ? null,
cpuSched ? "cachyos",
useLTO ? "none",
ticksHz ? 500,
tickRate ? "full",
preempt ? "full",
hugePages ? "always",
withDAMON ? false,
withNTSync ? true,
withHDR ? true,
withoutDebug ? false,
description ? "Linux EEVDF-BORE scheduler Kernel by CachyOS with other patches and improvements",
# For flakes
inputs,
}:
let
# For revs
shorter = builtins.substring 0 7;
# Helps when overriding.
dropUpdateScript = prevAttrs: { passthru = removeAttrs prevAttrs.passthru [ "updateScript" ]; };
# Helps when batch-overriding.
dropAttrsUpdateScript = builtins.mapAttrs (
_k: v: if (v.passthru.updateScript or null) != null then v.overrideAttrs dropUpdateScript else v
);
# Helps when batch-overriding.
setAttrsPlatforms =
platforms:
builtins.mapAttrs (
_k: v:
if (v ? "overrideAttrs") then
v.overrideAttrs (prevAttrs: {
meta = (prevAttrs.meta or { }) // {
platforms = lib.lists.intersectLists (prevAttrs.meta.platforms or [ ]) platforms;
platformsOrig = prevAttrs.meta.platforms or [ ];
badPlatforms = [ ];
};
})
else
v
);
cachyConfig = {
inherit
taste
versions
basicCachy
mArch
cpuSched
useLTO
ticksHz
tickRate
preempt
hugePages
withDAMON
withNTSync
withHDR
withoutDebug
description
withUpdateScript
;
};
# The three phases of the config
# - First we apply the changes fromt their PKGBUILD using kconfig;
# - Then we NIXify it (in the update-script);
# - Last state is importing the NIXified version for building.
preparedConfigfile = callPackage ./prepare.nix {
inherit
cachyConfig
stdenv
kernel
ogKernelConfigfile
commonMakeFlags
;
};
kconfigToNix = callPackage ./lib/kconfig-to-nix.nix {
configfile = preparedConfigfile;
};
linuxConfigTransfomed = import configPath;
kernel = callPackage ./kernel.nix {
inherit cachyConfig stdenv kconfigToNix;
kernelPatches = [ ];
configfile = preparedConfigfile;
config = linuxConfigTransfomed;
# For tests
inherit (inputs) flakes final;
kernelPackages = packagesWithRightPlatforms;
};
commonMakeFlags = import "${inputs.nixpkgs}/pkgs/os-specific/linux/kernel/common-flags.nix" {
inherit
lib
stdenv
buildPackages
extraMakeFlags
;
};
# CachyOS repeating stuff.
addOurs = finalAttrs: prevAttrs: {
kernel_configfile = prevAttrs.kernel.configfile;
zfs_cachyos =
(finalAttrs.callPackage "${inputs.nixpkgs}/pkgs/os-specific/linux/zfs/generic.nix"
zfsOverride
{
kernelModuleAttribute = "zfs_cachyos";
kernelMinSupportedMajorMinor = "1.0";
kernelMaxSupportedMajorMinor = "99.99";
enableUnsupportedExperimentalKernel = true;
inherit (prevAttrs.zfs_2_3) version;
tests = { };
maintainers = with lib.maintainers; [
pedrohlc
];
hash = "";
extraPatches = [ ];
}
).overrideAttrs
(prevAttrs: {
src = fetchFromGitHub {
owner = "cachyos";
repo = "zfs";
inherit (versions.zfs) rev hash;
};
postPatch = builtins.replaceStrings [ "grep --quiet '^Linux-M" ] [ "# " ] prevAttrs.postPatch;
});
inherit cachyOverride;
};
basePackages = linuxPackagesFor kernel;
packagesWithOurs = basePackages.extend addOurs;
packagesWithExtend =
if packagesExtend == null then
packagesWithOurs
else
packagesWithOurs.extend (packagesExtend kernel);
packagesWithRemovals = removeAttrs packagesWithExtend [
"zfs"
"zfs_2_1"
"zfs_2_2"
"zfs_2_3"
"zfs_unstable"
"lkrg"
"drbd"
# these kernelPackages.* are now pkgs.*
"system76-power"
"system76-scheduler"
"perf"
];
packagesWithoutUpdateScript = dropAttrsUpdateScript packagesWithRemovals;
packagesWithRightPlatforms = setAttrsPlatforms supportedPlatforms packagesWithoutUpdateScript;
supportedPlatforms = [
(with lib.systems.inspect.patterns; isx86_64 // isLinux)
(with lib.systems.inspect.patterns; isx86 // isLinux)
"x86_64-linux"
];
versionSuffix = "+C${shorter versions.config.rev}+P${shorter versions.patches.rev}";
in
packagesWithRightPlatforms
// {
_description = "Kernel and modules for ${description}";
_version = "${versions.linux.version}${versionSuffix}";
inherit (basePackages) kernel; # This one still has the updateScript
}

View File

@@ -0,0 +1,357 @@
{
cachyConfig,
fetchFromGitHub,
fetchurl,
lib,
stdenv,
kernel,
ogKernelConfigfile,
commonMakeFlags,
}:
let
inherit (cachyConfig.versions.linux) version;
majorMinor = lib.versions.majorMinor version;
patches-src = fetchFromGitHub {
owner = "CachyOS";
repo = "kernel-patches";
inherit (cachyConfig.versions.patches) rev hash;
};
config-src = fetchFromGitHub {
owner = "CachyOS";
repo = "linux-cachyos";
inherit (cachyConfig.versions.config) rev hash;
};
src =
if cachyConfig.taste == "linux-cachyos-rc" then
fetchurl {
url = "https://git.kernel.org/torvalds/t/linux-${version}.tar.gz";
inherit (cachyConfig.versions.linux) hash;
}
else
fetchurl {
url = "mirror://kernel/linux/kernel/v${lib.versions.major version}.x/linux-${
if version == "${majorMinor}.0" then majorMinor else version
}.tar.xz";
inherit (cachyConfig.versions.linux) hash;
};
schedPatches =
if cachyConfig.cpuSched == "eevdf" then
[ ]
else if cachyConfig.cpuSched == "hardened" then
[ ] # BORE disabled in CachyOS/linux-cachyos/commit/4ffae8ab9947f35495dfa7b62b7a22f023488dfb
else if (cachyConfig.cpuSched == "cachyos" || cachyConfig.cpuSched == "sched-ext") then
lib.optionals (lib.strings.versionOlder majorMinor "6.12") [
"${patches-src}/${majorMinor}/sched/0001-sched-ext.patch"
]
++ lib.optionals (cachyConfig.cpuSched == "cachyos" && version != "6.17-rc1") [
"${patches-src}/${majorMinor}/sched/0001-bore-cachy.patch"
]
else
throw "Unsupported cachyos _cpu_sched=${toString cachyConfig.cpuSched}";
patches = [
"${patches-src}/${majorMinor}/all/0001-cachyos-base-all.patch"
]
++ schedPatches
++ lib.optional (
cachyConfig.cpuSched == "hardened"
) "${patches-src}/${majorMinor}/misc/0001-hardened.patch";
# There are some configurations set by the PKGBUILD
pkgbuildConfig =
with cachyConfig;
basicCachyConfig
++ mArchConfig
++ cpuSchedConfig
++ [
# _nr_cpus, defaults to empty, which later set this
"--set-val NR_CPUS 320"
# _per_gov, defaults to empty [but PERSONAL CHANGE to "y"]
"-d CPU_FREQ_DEFAULT_GOV_SCHEDUTIL"
"-e CPU_FREQ_DEFAULT_GOV_PERFORMANCE"
# _tcp_bbr3, defaults to "y"
"-m TCP_CONG_CUBIC"
"-d DEFAULT_CUBIC"
"-e TCP_CONG_BBR"
"-e DEFAULT_BBR"
"--set-str DEFAULT_TCP_CONG bbr"
"-m NET_SCH_FQ_CODEL"
"-e NET_SCH_FQ"
"-d DEFAULT_FQ_CODEL"
"-e DEFAULT_FQ"
"--set-str DEFAULT_NET_SCH fq"
# Nixpkgs don't support this
"-d CONFIG_SECURITY_TOMOYO"
]
++ ltoConfig
++ ticksHzConfig
++ tickRateConfig
++ preemptConfig
++ [
# _cc_harder, defaults to "y"
"-d CC_OPTIMIZE_FOR_PERFORMANCE"
"-e CC_OPTIMIZE_FOR_PERFORMANCE_O3"
# _lru_config, defaults to "standard"
"-e LRU_GEN"
"-e LRU_GEN_ENABLED"
"-d LRU_GEN_STATS"
# _vma_config, defaults to "standard"
"-e PER_VMA_LOCK"
"-d PER_VMA_LOCK_STATS"
]
++ hugePagesConfig
++ damonConfig
++ ntSyncConfig
++ hdrConfig
++ disableDebug;
# _cachy_config, defaults to "y"
basicCachyConfig = lib.optional cachyConfig.basicCachy "-e CACHY";
# _processor_opt config, defaults to ""
mArchConfig =
if cachyConfig.mArch == null then
[ ]
else if cachyConfig.mArch == "NATIVE" then
[
"-d GENERIC_CPU"
"-d MZEN4"
"-e X86_NATIVE_CPU"
]
else if cachyConfig.mArch == "ZEN4" then
[
"-d GENERIC_CPU"
"-e MZEN4"
"-d X86_NATIVE_CPU"
]
else if builtins.match "GENERIC_V[1-4]" cachyConfig.mArch != null then
let
v = lib.strings.removePrefix "GENERIC_V" cachyConfig.mArch;
in
[
"-e GENERIC_CPU"
"-d MZEN4"
"-d X86_NATIVE_CPU"
"--set-val X86_64_VERSION ${v}"
]
else
throw "Unsuppoted cachyos mArch";
# _cpusched, defaults to "cachyos"
cpuSchedConfig =
if cachyConfig.cpuSched == "eevdf" then
[ ]
else if cachyConfig.cpuSched == "hardened" then
[ "-e SCHED_BORE" ]
else if cachyConfig.cpuSched == "sched-ext" then
[ "-e SCHED_CLASS_EXT" ]
else if cachyConfig.cpuSched == "cachyos" then
[
"-e SCHED_BORE"
"-e SCHED_CLASS_EXT"
]
else
throw "Unsupported cachyos scheduler";
# _HZ_ticks, defaults to "500"
ticksHzConfig =
if cachyConfig.ticksHz == 300 then
[
"-e HZ_300"
"--set-val HZ 300"
]
else
[
"-d HZ_300"
"--set-val HZ ${toString cachyConfig.ticksHz}"
"-e HZ_${toString cachyConfig.ticksHz}"
];
# _use_llvm_lto, defaults to "none"
ltoConfig =
assert (cachyConfig.useLTO == "none" || stdenv.cc.isClang);
if cachyConfig.useLTO == "thin" then
[
"-e LTO"
"-e LTO_CLANG"
"-e ARCH_SUPPORTS_LTO_CLANG"
"-e ARCH_SUPPORTS_LTO_CLANG_THIN"
"-d LTO_NONE"
"-e HAS_LTO_CLANG"
"-d LTO_CLANG_FULL"
"-e LTO_CLANG_THIN"
"-e HAVE_GCC_PLUGINS"
]
else if cachyConfig.useLTO == "full" then
[
"-e LTO"
"-e LTO_CLANG"
"-e ARCH_SUPPORTS_LTO_CLANG"
"-e ARCH_SUPPORTS_LTO_CLANG_THIN"
"-d LTO_NONE"
"-e HAS_LTO_CLANG"
"-e LTO_CLANG_FULL"
"-d LTO_CLANG_THIN"
"-e HAVE_GCC_PLUGINS"
]
else if cachyConfig.useLTO == "none" then
[ ]
else
throw "Unsupported cachyos _use_llvm_lto";
# _tickrate defaults to "full"
tickRateConfig =
if cachyConfig.tickRate == "idle" then
[
"-d HZ_PERIODIC"
"-d NO_HZ_FULL"
"-e NO_HZ_IDLE"
"-e NO_HZ"
"-e NO_HZ_COMMON"
]
else if cachyConfig.tickRate == "full" then
[
"-d HZ_PERIODIC"
"-d NO_HZ_IDLE"
"-d CONTEXT_TRACKING_FORCE"
"-e NO_HZ_FULL_NODEF"
"-e NO_HZ_FULL"
"-e NO_HZ"
"-e NO_HZ_COMMON"
"-e CONTEXT_TRACKING"
]
else
throw "Unsupported cachyos _tickrate";
# _preempt, defaults to "full"
preemptConfig =
if cachyConfig.preempt == "full" then
[
"-e PREEMPT_BUILD"
"-d PREEMPT_NONE"
"-d PREEMPT_VOLUNTARY"
"-e PREEMPT"
"-e PREEMPT_COUNT"
"-e PREEMPTION"
"-e PREEMPT_DYNAMIC"
]
else if cachyConfig.preempt == "server" then
[
"-e PREEMPT_NONE_BUILD"
"-e PREEMPT_NONE"
"-d PREEMPT_VOLUNTARY"
"-d PREEMPT"
"-d PREEMPTION"
"-d PREEMPT_DYNAMIC"
]
else
throw "Unsupported cachyos _preempt";
# _hugepage, defaults to "always"
hugePagesConfig =
if cachyConfig.hugePages == "always" then
[
"-d TRANSPARENT_HUGEPAGE_MADVISE"
"-e TRANSPARENT_HUGEPAGE_ALWAYS"
]
else if cachyConfig.hugePages == "madvise" then
[
"-d TRANSPARENT_HUGEPAGE_ALWAYS"
"-e TRANSPARENT_HUGEPAGE_MADVISE"
]
else
throw "Unsupported cachyos _hugepage";
# _damon, defaults to empty
damonConfig = lib.optionals cachyConfig.withDAMON [
"-e DAMON"
"-e DAMON_VADDR"
"-e DAMON_DBGFS"
"-e DAMON_SYSFS"
"-e DAMON_PADDR"
"-e DAMON_RECLAIM"
"-e DAMON_LRU_SORT"
];
# _ntsync, defaults to empty
ntSyncConfig = lib.optionals cachyConfig.withNTSync [ "-m NTSYNC" ];
# custom made
hdrConfig = lib.optionals cachyConfig.withHDR [ "-e AMD_PRIVATE_COLOR" ];
# https://github.com/CachyOS/linux-cachyos/issues/187
disableDebug =
lib.optionals
(
cachyConfig.withoutDebug && cachyConfig.cpuSched != "sched-ext" && cachyConfig.cpuSched != "cachyos"
)
[
"-d DEBUG_INFO"
"-d DEBUG_INFO_BTF"
"-d DEBUG_INFO_DWARF4"
"-d DEBUG_INFO_DWARF5"
"-d PAHOLE_HAS_SPLIT_BTF"
"-d DEBUG_INFO_BTF_MODULES"
"-d SLUB_DEBUG"
"-d PM_DEBUG"
"-d PM_ADVANCED_DEBUG"
"-d PM_SLEEP_DEBUG"
"-d ACPI_DEBUG"
"-d SCHED_DEBUG"
"-d LATENCYTOP"
"-d DEBUG_PREEMPT"
];
in
stdenv.mkDerivation (finalAttrs: {
inherit src patches;
name = "linux-cachyos-config";
nativeBuildInputs = kernel.nativeBuildInputs ++ kernel.buildInputs;
makeFlags = commonMakeFlags;
postPhase = ''
${finalAttrs.passthru.extraVerPatch}
'';
buildPhase = ''
runHook preBuild
cp "${config-src}/${cachyConfig.taste}/config" ".config"
make $makeFlags olddefconfig
patchShebangs scripts/config
scripts/config ${lib.concatStringsSep " " pkgbuildConfig}
make $makeFlags olddefconfig
runHook postBuild
'';
installPhase = ''
runHook preInstall
cp .config $out
runHook postInstall
'';
meta = ogKernelConfigfile.meta // {
# at the time of this writing, they don't have config files for aarch64
platforms = [ "x86_64-linux" ];
};
passthru = {
inherit cachyConfig commonMakeFlags stdenv;
kernelPatches = patches;
extraVerPatch = ''
sed -Ei"" 's/EXTRAVERSION = ?(.*)$/EXTRAVERSION = \1${cachyConfig.versions.suffix}/g' Makefile
'';
};
})

View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -eu
for flavor in cachyos{,-lto,-server,-lts,-rc,-hardened}; do
cat "$(nix build ".#legacyPackages.x86_64-linux.linuxPackages_${flavor}.kernel.kconfigToNix" --no-link --print-out-paths)" \
>"pkgs/linux-cachyos/config-nix/${flavor}.x86_64-linux.nix"
done

View File

@@ -0,0 +1,73 @@
# Run with:
# nix build -L .#linux_cachyos.passthru.tests.plymouth.driverInteractive && result/bin/nixos-test-driver
{
nixpkgs,
chaotic,
kernelPackages,
}:
import "${nixpkgs}/nixos/tests/make-test-python.nix" (
{ pkgs, lib, ... }:
{
name = "cachyos-plymouth";
meta.maintainers = with pkgs.lib.maintainers; [ pedrohlc ];
nodes.machine =
{ pkgs, ... }:
{
imports = [
chaotic.nixosModules.default
"${nixpkgs}/nixos/tests/common/user-account.nix"
];
virtualisation.qemu.options = [
"-m 16G"
"-vga none"
"-device virtio-vga-gl"
"-display gtk,gl=on"
];
virtualisation.qemu.package = lib.mkForce pkgs.qemu_full;
boot = {
inherit kernelPackages;
# kernelPackages = pkgs.linuxPackages_latest;
# Based on https://wiki.nixos.org/wiki/Plymouth
plymouth = {
enable = true;
theme = "rings";
themePackages = with pkgs; [
(adi1090x-plymouth-themes.override {
selected_themes = [ "rings" ];
})
];
};
consoleLogLevel = lib.mkForce 3;
initrd.verbose = false;
# using mkForce to properly mix with virtualisation stuff
kernelParams = lib.mkForce [
"console=ttyS0"
"clocksource=acpi_pm"
"lsm=landlock,yama,bpf"
"boot.shell_on_fail"
"quiet"
"rd.systemd.show_status=auto"
"splash"
"udev.log_priority=3"
"plymouth.ignore-serial-consoles"
];
loader.timeout = 0;
};
};
# TODO: TODO
testScript = ''
start_all()
'';
}
)

View File

@@ -0,0 +1,116 @@
{
writeShellScript,
lib,
coreutils,
findutils,
gnugrep,
gnused,
curl,
jq,
git,
nix,
nix-prefetch-git,
moreutils,
withUpdateScript,
}:
let
path = lib.makeBinPath [
coreutils
curl
findutils
gnugrep
gnused
jq
moreutils
git
nix-prefetch-git
nix
];
releaseSrcUrl = "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-\${latestVer%.0}.tar.xz";
major =
if withUpdateScript == "stable" then
{
versionsFile = "versions.json";
suffix = "";
flavors = [
"-gcc"
"-lto"
"-server"
];
srcUrl = releaseSrcUrl;
}
else if withUpdateScript == "rc" then
{
versionsFile = "versions-rc.json";
suffix = "-rc";
flavors = [ "-rc" ];
srcUrl = "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/snapshot/linux-\${latestVer%.0}.tar.gz";
}
else if withUpdateScript == "hardened" then
{
versionsFile = "versions-hardened.json";
suffix = "-hardened";
flavors = [ "-hardened" ];
srcUrl = releaseSrcUrl;
}
else if withUpdateScript == "lts" then
{
versionsFile = "versions-lts.json";
suffix = "-lts";
flavors = [ "-lts" ];
srcUrl = releaseSrcUrl;
}
else
throw "Unsupported update-script for linux-cachyos";
in
with major;
writeShellScript "update-cachyos" ''
set -euo pipefail
PATH=${path}
srcJson=/etc/nixos/packages/linux-cachyos/${versionsFile}
localVer=$(jq -r .linux.version < $srcJson)
latestVer=$(curl 'https://raw.githubusercontent.com/CachyOS/linux-cachyos/master/linux-cachyos${suffix}/.SRCINFO' | grep -Po '(?<=pkgver = )(.+)$' | sed 's/\.rc/-rc/')
if [ "$localVer" == "$latestVer" ]; then
exit 0
fi
latestSha256=$(nix-prefetch-url --type sha256 "${srcUrl}")
latestHash=$(nix-hash --to-sri --type sha256 $latestSha256)
configRepo=$(nix-prefetch-git --quiet 'https://github.com/CachyOS/linux-cachyos.git')
configRev=$(echo "$configRepo" | jq -r .rev)
configHash=$(echo "$configRepo" | jq -r .hash)
configPath=$(echo "$configRepo" | jq -r .path)
patchesRepo=$(nix-prefetch-git --quiet 'https://github.com/CachyOS/kernel-patches.git')
patchesRev=$(echo "$patchesRepo" | jq -r .rev)
patchesHash=$(echo "$patchesRepo" | jq -r .hash)
zfsRev=$(grep -Po '(?<=zfs.git#commit=)([^"]+)' $configPath/linux-cachyos${suffix}/PKGBUILD)
zfsRepo=$(nix-prefetch-git --quiet 'https://github.com/CachyOS/zfs.git' --rev $zfsRev)
zfsHash=$(echo "$zfsRepo" | jq -r .hash)
jq \
--arg latestVer "$latestVer" --arg latestHash "$latestHash" \
--arg configRev "$configRev" --arg configHash "$configHash" \
--arg patchesRev "$patchesRev" --arg patchesHash "$patchesHash" \
--arg zfsRev "$zfsRev" --arg zfsHash "$zfsHash" \
".linux.version = \$latestVer | .linux.hash = \$latestHash |\
.config.rev = \$configRev | .config.hash = \$configHash |\
.patches.rev = \$patchesRev | .patches.hash = \$patchesHash |\
.zfs.rev = \$zfsRev | .zfs.hash = \$zfsHash" \
"$srcJson" | sponge "$srcJson"
${lib.strings.concatMapStrings (flavor: ''
cat "$(nix build '.#legacyPackages.x86_64-linux.linuxPackages_cachyos${flavor}.kernel.kconfigToNix' --no-link --print-out-paths)" \
> /etc/nixos/packages/linux-cachyos/config-nix/cachyos${flavor}.x86_64-linux.nix || true
'') flavors}
git add /etc/nixos/packages/linux-cachyos
git commit -m "linux_cachyos${suffix}: $localVer -> $latestVer"
''

View File

@@ -0,0 +1,19 @@
{
"suffix": "-cachyos",
"linux": {
"version": "6.17.9",
"hash": "sha256-bQiAO5U8UJ30jUTTKB7TklJDIdi7NT6yHAVVeQyPjgY="
},
"config": {
"rev": "40aacb76c4f391fbeede811b7dfee1ea7e778e9f",
"hash": "sha256-vshDmoDLtbOfha0HKQPOdud4+gkeF8M+oaoj1Npt4rM="
},
"patches": {
"rev": "b8f46aff318e08b1d088b8d6f8f46c7f463a78cc",
"hash": "sha256-WyNbpFLNUMhOgezAsOpjRovuDz2LcyU2gwrN99xG5dg="
},
"zfs": {
"rev": "fe5ed524c72e0b2e2cd4c47ee5bc987290e89666",
"hash": "sha256-N+d7AnvE8X6+NU/FuBvs8OeHalMwo2cra1LdA7QWOx8="
}
}

View File

@@ -0,0 +1,19 @@
{
"suffix": "-cachyos",
"linux": {
"version": "6.12.60",
"hash": "sha256-pjCWshR0EdaDzsv4diK7L/SIW6wrNkHT1PECUMic3Pg="
},
"config": {
"rev": "acf85ecb3d8a03fb9fd3160ce6d9bdb05ef1c124",
"hash": "sha256-FgEoeJWSlq3keIsY8WAjudBX49MWvTKoLZBuyiPpp5k="
},
"patches": {
"rev": "0ac7e72d6b9f973a1682806d0166042869aa4144",
"hash": "sha256-0hQy5EoDK2p/smbzg1QOoJVV7oapnGr3Tu4KT8tU9xw="
},
"zfs": {
"rev": "fe5ed524c72e0b2e2cd4c47ee5bc987290e89666",
"hash": "sha256-N+d7AnvE8X6+NU/FuBvs8OeHalMwo2cra1LdA7QWOx8="
}
}

View File

@@ -0,0 +1,19 @@
{
"suffix": "-cachyos",
"linux": {
"version": "6.18-rc7",
"hash": "sha256-SikW8FoO2bdxr5nOdxCwB7YYuTwVjNdUngK4AhivzDU="
},
"config": {
"rev": "40aacb76c4f391fbeede811b7dfee1ea7e778e9f",
"hash": "sha256-vshDmoDLtbOfha0HKQPOdud4+gkeF8M+oaoj1Npt4rM="
},
"patches": {
"rev": "b8f46aff318e08b1d088b8d6f8f46c7f463a78cc",
"hash": "sha256-WyNbpFLNUMhOgezAsOpjRovuDz2LcyU2gwrN99xG5dg="
},
"zfs": {
"rev": "fe5ed524c72e0b2e2cd4c47ee5bc987290e89666",
"hash": "sha256-N+d7AnvE8X6+NU/FuBvs8OeHalMwo2cra1LdA7QWOx8="
}
}

View File

@@ -0,0 +1,24 @@
{
"_suffix": "Matches `Add-extra-version-CachyOS.patch`",
"suffix": "-cachyos",
"_linux": "pkgver from config's PKGBUILD",
"linux": {
"version": "6.18.0",
"hash": "sha256-kQakYF2p4x/xdlnZWHgrgV+VkaswjQOw7iGq1sfc7Us="
},
"_config": "latest commit from https://github.com/CachyOS/linux-cachyos/commits/master/linux-cachyos",
"config": {
"rev": "acf85ecb3d8a03fb9fd3160ce6d9bdb05ef1c124",
"hash": "sha256-FgEoeJWSlq3keIsY8WAjudBX49MWvTKoLZBuyiPpp5k="
},
"_patches": "latest commit from https://github.com/CachyOS/kernel-patches/commits/master/x.y",
"patches": {
"rev": "0ac7e72d6b9f973a1682806d0166042869aa4144",
"hash": "sha256-0hQy5EoDK2p/smbzg1QOoJVV7oapnGr3Tu4KT8tU9xw="
},
"_zfs": "search for `git+https://github.com/cachyos/zfs.git` in config's PKGBUILD",
"zfs": {
"rev": "7de9800e5ce45d03c797be57a3e959fc914b2adb",
"hash": "sha256-FctR3yy/APamDo4O0bXoRoJBldJGrTsTm5RBgTDkLKc="
}
}