1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 buildLinux,
6 variant,
7 ...
8}@args:
9
10let
11 # Default priority is 100 for common kernel options (see common-config.nix
12 # file), we need something lower to override them, but we still want users to
13 # override options if they need using lib.mkForce (that has 50 priority)
14 mkKernelOverride = lib.mkOverride 90;
15 # Comments with variant added for update script
16 variants = {
17 # ./update-zen.py zen
18 zen = {
19 version = "6.15.8"; # zen
20 suffix = "zen1"; # zen
21 sha256 = "010k50c9anjbcrwh9cgc6wn91hh3xa1x3mpxbaa2x1v8f5773vd4"; # zen
22 isLqx = false;
23 };
24 # ./update-zen.py lqx
25 lqx = {
26 version = "6.15.8"; # lqx
27 suffix = "lqx1"; # lqx
28 sha256 = "1z85h8k49acw5w1m7z6lclnr62rgr6dbi2sci7in59qkq1zfvkb9"; # lqx
29 isLqx = true;
30 };
31 };
32 zenKernelsFor =
33 {
34 version,
35 suffix,
36 sha256,
37 isLqx,
38 }:
39 buildLinux (
40 args
41 // {
42 inherit version;
43 pname = "linux-${if isLqx then "lqx" else "zen"}";
44 modDirVersion = lib.versions.pad 3 "${version}-${suffix}";
45 isZen = true;
46
47 src = fetchFromGitHub {
48 owner = "zen-kernel";
49 repo = "zen-kernel";
50 rev = "v${version}-${suffix}";
51 inherit sha256;
52 };
53
54 # This is based on the following sources:
55 # - zen: https://gitlab.archlinux.org/archlinux/packaging/packages/linux-zen/-/blob/main/config
56 # - lqx: https://github.com/damentz/liquorix-package/blob/6.13/master/linux-liquorix/debian/config/kernelarch-x86/config-arch-64
57 # - Liquorix features: https://liquorix.net/
58 # The list below is not exhaustive, so the kernels probably doesn't match
59 # the upstream, but should bring most of the improvements that will be
60 # expected by users
61 structuredExtraConfig =
62 with lib.kernel;
63 {
64 # Zen Interactive tuning
65 ZEN_INTERACTIVE = yes;
66
67 # FQ-Codel Packet Scheduling
68 NET_SCH_DEFAULT = yes;
69 DEFAULT_FQ_CODEL = yes;
70
71 # Preempt (low-latency)
72 PREEMPT = mkKernelOverride yes;
73 PREEMPT_VOLUNTARY = mkKernelOverride no;
74
75 # Preemptible tree-based hierarchical RCU
76 TREE_RCU = yes;
77 PREEMPT_RCU = yes;
78 RCU_EXPERT = yes;
79 TREE_SRCU = yes;
80 TASKS_RCU_GENERIC = yes;
81 TASKS_RCU = yes;
82 TASKS_RUDE_RCU = yes;
83 TASKS_TRACE_RCU = yes;
84 RCU_STALL_COMMON = yes;
85 RCU_NEED_SEGCBLIST = yes;
86 RCU_FANOUT = freeform "64";
87 RCU_FANOUT_LEAF = freeform "16";
88 RCU_BOOST = yes;
89 RCU_BOOST_DELAY = option (freeform "500");
90 RCU_NOCB_CPU = yes;
91 RCU_LAZY = yes;
92 RCU_DOUBLE_CHECK_CB_TIME = yes;
93
94 # BFQ I/O scheduler
95 IOSCHED_BFQ = mkKernelOverride yes;
96
97 # Futex WAIT_MULTIPLE implementation for Wine / Proton Fsync.
98 FUTEX = yes;
99 FUTEX_PI = yes;
100
101 # NT synchronization primitive emulation
102 NTSYNC = yes;
103
104 # Preemptive Full Tickless Kernel at 1000Hz
105 HZ = freeform "1000";
106 HZ_1000 = yes;
107
108 }
109 // lib.optionalAttrs (isLqx) {
110 # https://github.com/damentz/liquorix-package/commit/07b176edc002f2a7825ae181613e1f79a3650fd2
111 CMDLINE_BOOL = yes;
112 CMDLINE = freeform "audit=0 intel_pstate=disable amd_pstate=disable ";
113
114 # Google's BBRv3 TCP congestion Control
115 TCP_CONG_BBR = yes;
116 DEFAULT_BBR = yes;
117
118 # PDS Process Scheduler
119 SCHED_ALT = yes;
120 SCHED_PDS = yes;
121
122 # https://github.com/damentz/liquorix-package/commit/a7055b936c0f4edb8f6afd5263fe1d2f8a5cd877
123 RCU_BOOST = no;
124 RCU_LAZY = mkKernelOverride no;
125
126 # Swap storage is compressed with LZ4 using zswap
127 ZSWAP_COMPRESSOR_DEFAULT_LZ4 = yes;
128 ZSWAP_COMPRESSOR_DEFAULT_ZSTD = mkKernelOverride no;
129
130 # https://github.com/damentz/liquorix-package/commit/3a82381a4db3452599e2b2a607046a379c72ad27
131 SLAB_BUCKETS = mkKernelOverride (option no);
132 # https://github.com/damentz/liquorix-package/commit/ca7efe07abd478f3f4cbe0725a3383fd235aa5be
133 ENERGY_MODE = mkKernelOverride (option no);
134 # https://github.com/damentz/liquorix-package/commit/fdc93f5633d22c26f0994fba751a26de0cb51a17
135 WQ_POWER_EFFICIENT_DEFAULT = mkKernelOverride (option no);
136
137 # Fix error: unused option: XXX.
138 CFS_BANDWIDTH = mkKernelOverride (option no);
139 PSI = mkKernelOverride (option no);
140 RT_GROUP_SCHED = mkKernelOverride (option no);
141 SCHED_AUTOGROUP = mkKernelOverride (option no);
142 SCHED_CLASS_EXT = mkKernelOverride (option no);
143 SCHED_CORE = mkKernelOverride (option no);
144 UCLAMP_TASK = mkKernelOverride (option no);
145 UCLAMP_TASK_GROUP = mkKernelOverride (option no);
146 };
147
148 extraPassthru.updateScript = [
149 ./update-zen.py
150 (if isLqx then "lqx" else "zen")
151 ];
152
153 extraMeta = {
154 branch = lib.versions.majorMinor version + "/master";
155 maintainers = with lib.maintainers; [
156 thiagokokada
157 jerrysm64
158 axertheaxe
159 ];
160 teams = [ ];
161 description =
162 "Built using the best configuration and kernel sources for desktop, multimedia, and gaming workloads."
163 + lib.optionalString isLqx " (Same as linux_zen, but less aggressive release schedule and additional extra config)";
164 broken = stdenv.hostPlatform.isAarch64;
165 };
166
167 }
168 // (args.argsOverride or { })
169 );
170in
171zenKernelsFor variants.${variant}