1{ lib, stdenv, fetchFromGitHub, buildLinux, ... } @ args:
2
3let
4 # comments with variant added for update script
5 # ./update-zen.py zen
6 zenVariant = {
7 version = "6.10.1"; #zen
8 suffix = "zen1"; #zen
9 sha256 = "0lr9qjz4hlvx3yc0lj65fnmbciyh6symycbi9ass761l1niswbk5"; #zen
10 isLqx = false;
11 };
12 # ./update-zen.py lqx
13 lqxVariant = {
14 version = "6.9.11"; #lqx
15 suffix = "lqx1"; #lqx
16 sha256 = "0i6i0ak10gswlk60pnkn5dlz74g4nd7n1xbnvf24nnwwp69kkd44"; #lqx
17 isLqx = true;
18 };
19 zenKernelsFor = { version, suffix, sha256, isLqx }: buildLinux (args // {
20 inherit version;
21 pname = "linux-${if isLqx then "lqx" else "zen"}";
22 modDirVersion = lib.versions.pad 3 "${version}-${suffix}";
23 isZen = true;
24
25 src = fetchFromGitHub {
26 owner = "zen-kernel";
27 repo = "zen-kernel";
28 rev = "v${version}-${suffix}";
29 inherit sha256;
30 };
31
32 # This is based on the following sources:
33 # - zen: https://gitlab.archlinux.org/archlinux/packaging/packages/linux-zen/-/blob/main/config
34 # - lqx: https://github.com/damentz/liquorix-package/blob/6.8/master/linux-liquorix/debian/config/kernelarch-x86/config-arch-64
35 # - Liquorix features: https://liquorix.net/
36 # The list below is not exhaustive, so the kernels probably doesn't match
37 # the upstream, but should bring most of the improvements that will be
38 # expected by users
39 structuredExtraConfig = with lib.kernel; {
40 # Zen Interactive tuning
41 ZEN_INTERACTIVE = yes;
42
43 # FQ-Codel Packet Scheduling
44 NET_SCH_DEFAULT = yes;
45 DEFAULT_FQ_CODEL = yes;
46
47 # Preempt (low-latency)
48 PREEMPT = lib.mkOverride 60 yes;
49 PREEMPT_VOLUNTARY = lib.mkOverride 60 no;
50
51 # Preemptible tree-based hierarchical RCU
52 TREE_RCU = yes;
53 PREEMPT_RCU = yes;
54 RCU_EXPERT = yes;
55 TREE_SRCU = yes;
56 TASKS_RCU_GENERIC = yes;
57 TASKS_RCU = yes;
58 TASKS_RUDE_RCU = yes;
59 TASKS_TRACE_RCU = yes;
60 RCU_STALL_COMMON = yes;
61 RCU_NEED_SEGCBLIST = yes;
62 RCU_FANOUT = freeform "64";
63 RCU_FANOUT_LEAF = freeform "16";
64 RCU_BOOST = yes;
65 RCU_BOOST_DELAY = option (freeform "500");
66 RCU_NOCB_CPU = yes;
67 RCU_LAZY = yes;
68 RCU_DOUBLE_CHECK_CB_TIME = yes;
69
70 # BFQ I/O scheduler
71 IOSCHED_BFQ = lib.mkOverride 60 yes;
72
73 # Futex WAIT_MULTIPLE implementation for Wine / Proton Fsync.
74 FUTEX = yes;
75 FUTEX_PI = yes;
76
77 # NT synchronization primitive emulation
78 NTSYNC = yes;
79
80 # Preemptive Full Tickless Kernel at 1000Hz
81 HZ = freeform "1000";
82 HZ_1000 = yes;
83
84 # Alternative zpool for zswap
85 Z3FOLD = yes;
86 } // lib.optionalAttrs (isLqx) {
87 # Google's BBRv3 TCP congestion Control
88 TCP_CONG_BBR = yes;
89 DEFAULT_BBR = yes;
90
91 # PDS Process Scheduler
92 SCHED_ALT = yes;
93 SCHED_PDS = yes;
94
95 # https://github.com/damentz/liquorix-package/commit/a7055b936c0f4edb8f6afd5263fe1d2f8a5cd877
96 RCU_BOOST = no;
97 RCU_LAZY = lib.mkOverride 60 no;
98
99 # Swap storage is compressed with LZ4 using zswap
100 ZSWAP_COMPRESSOR_DEFAULT_LZ4 = lib.mkOptionDefault yes;
101 ZSWAP_COMPRESSOR_DEFAULT_ZSTD = lib.mkDefault no;
102 ZSWAP_ZPOOL_DEFAULT_Z3FOLD = yes;
103
104 # Fix error: unused option: XXX.
105 CFS_BANDWIDTH = lib.mkForce (option no);
106 PSI = lib.mkForce (option no);
107 RT_GROUP_SCHED = lib.mkForce (option no);
108 SCHED_AUTOGROUP = lib.mkForce (option no);
109 SCHED_CORE = lib.mkForce (option no);
110 UCLAMP_TASK = lib.mkForce (option no);
111 UCLAMP_TASK_GROUP = lib.mkForce (option no);
112 };
113
114 passthru.updateScript = [ ./update-zen.py (if isLqx then "lqx" else "zen") ];
115
116 extraMeta = {
117 branch = lib.versions.majorMinor version + "/master";
118 maintainers = with lib.maintainers; [ thiagokokada jerrysm64 ];
119 description = "Built using the best configuration and kernel sources for desktop, multimedia, and gaming workloads." +
120 lib.optionalString isLqx " (Same as linux_zen, but less aggressive release schedule and additional extra config)";
121 broken = stdenv.isAarch64;
122 };
123
124 } // (args.argsOverride or { }));
125in
126{
127 zen = zenKernelsFor zenVariant;
128 lqx = zenKernelsFor lqxVariant;
129}