Skip to content

Commit 914bcc1

Browse files
committed
Add NixOS module
1 parent b620ed2 commit 914bcc1

1 file changed

Lines changed: 228 additions & 0 deletions

File tree

default.nix

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
{
2+
pkgs,
3+
lib,
4+
config,
5+
...
6+
}:
7+
8+
{
9+
options = {
10+
linux-nitrous = {
11+
processorFamily = lib.mkOption {
12+
type = lib.types.nullOr (
13+
lib.types.enum [
14+
# Intel
15+
"nocona"
16+
"core2"
17+
"penryn"
18+
"bonnell"
19+
"atom"
20+
"silvermont"
21+
"slm"
22+
"goldmont"
23+
"goldmont-plus"
24+
"tremont"
25+
"nehalem"
26+
"corei7"
27+
"westmere"
28+
"sandybridge"
29+
"corei7-avx"
30+
"ivybridge"
31+
"core-avx-i"
32+
"haswell"
33+
"core-avx2"
34+
"broadwell"
35+
"skylake"
36+
"skylake-avx512"
37+
"skx"
38+
"cascadelake"
39+
"cooperlake"
40+
"cannonlake"
41+
"icelake-client"
42+
"rocketlake"
43+
"icelake-server"
44+
"tigerlake"
45+
"sapphirerapids"
46+
"alderlake"
47+
"raptorlake"
48+
"meteorlake"
49+
"arrowlake"
50+
"arrowlake-s"
51+
"lunarlake"
52+
"gracemont"
53+
"pantherlake"
54+
"sierraforest"
55+
"grandridge"
56+
"graniterapids"
57+
"graniterapids-d"
58+
"emeraldrapids"
59+
"clearwaterforest"
60+
"diamondrapids"
61+
# AMD
62+
"knl"
63+
"knm"
64+
"k8"
65+
"athlon64"
66+
"athlon-fx"
67+
"opteron"
68+
"k8-sse3"
69+
"athlon64-sse3"
70+
"opteron-sse3"
71+
"amdfam10"
72+
"barcelona"
73+
"btver1"
74+
"btver2"
75+
"bdver1"
76+
"bdver2"
77+
"bdver3"
78+
"bdver4"
79+
"znver1"
80+
"znver2"
81+
"znver3"
82+
"znver4"
83+
"znver5"
84+
# Generic
85+
"x86-64"
86+
"x86-64-v2"
87+
"x86-64-v3"
88+
"x86-64-v4"
89+
]
90+
);
91+
default = null;
92+
};
93+
enableDrmXe = lib.mkEnableOption "Intel Xe support";
94+
};
95+
};
96+
config = {
97+
boot.kernelPackages = lib.mkOverride 80 (
98+
let
99+
version = "6.17.1-1";
100+
linuxVersion = lib.head (lib.splitString "-" version);
101+
suffix = "nitrous";
102+
llvm = pkgs.unstable.llvmPackages_20;
103+
linux_nitrous_pkg =
104+
{ fetchurl, buildLinux, ... }@args:
105+
buildLinux (
106+
args
107+
// rec {
108+
inherit version;
109+
pname = "linux-${suffix}";
110+
modDirVersion = lib.versions.pad 3 "${linuxVersion}-${suffix}";
111+
stdenv = pkgs.unstable.overrideCC llvm.stdenv (
112+
llvm.stdenv.cc.override { inherit (llvm) bintools; }
113+
);
114+
nativeBuildInputs = [ llvm.lld ];
115+
extraMakeFlags = [
116+
"LLVM=1"
117+
"LD=${llvm.lld}/bin/ld.lld"
118+
"CC=${lib.getExe llvm.clang-unwrapped}"
119+
]
120+
++ (
121+
let
122+
processorFamily = config.linux-nitrous.processorFamily;
123+
in
124+
if processorFamily != null then
125+
[
126+
"KCPPFLAGS=-march=${processorFamily}"
127+
"KCFLAGS=-march=${processorFamily}"
128+
"KRUSTFLAGS=-Ctarget-cpu=${processorFamily}"
129+
]
130+
else
131+
[ ]
132+
);
133+
134+
src = fetchurl {
135+
url = "https://gitlab.com/xdevs23/linux-nitrous/-/archive/v${version}/linux-nitrous-v${version}.tar.gz";
136+
hash = "sha256-Xzm+cD5VkZI80O8zVYkSBdtQ//F/aGwzFghHjp+04to=";
137+
};
138+
139+
structuredExtraConfig = with lib.kernel; {
140+
LOCALVERSION_AUTO = no;
141+
NTSYNC = yes;
142+
#LATENCYTOP = no;
143+
BCACHEFS_FS = module;
144+
DRM_XE = if config.linux-nitrous.enableDrmXe then module else no;
145+
#SCHED_CLASS_EXT = lib.mkForce no;
146+
PREEMPT_VOLUNTARY = lib.mkForce no;
147+
PREEMPT_LAZY = yes;
148+
CC_OPTIMIZE_FOR_PERFORMANCE_O3 = yes;
149+
KVM = yes;
150+
#LTO_CLANG_THIN = yes;
151+
USB_FEW_INIT_RETRIES = yes;
152+
ANDROID_BINDER_IPC = yes;
153+
ANDROID_BINDERFS = yes;
154+
FS_SYSCTL_PROTECTED_SYMLINKS = yes;
155+
FS_SYSCTL_PROTECTED_HARDLINKS = yes;
156+
};
157+
158+
kernelPatches = [
159+
{
160+
name = "nitrous-config";
161+
patch = null;
162+
extraConfig = ''
163+
LOCALVERSION -${suffix}
164+
FS_SYSCTL_PROTECTED_FIFOS 2
165+
FS_SYSCTL_PROTECTED_REGULAR 2
166+
KPTR_RESTRICT 1
167+
'';
168+
}
169+
];
170+
171+
extraMeta.branch = lib.versions.majorMinor version;
172+
}
173+
// (args.argsOverride or { })
174+
);
175+
linux_nitrous = pkgs.callPackage linux_nitrous_pkg { };
176+
in
177+
pkgs.recurseIntoAttrs (
178+
(pkgs.unstable.linuxPackagesFor linux_nitrous).extend (
179+
lpfinal: lpprev: {
180+
ryzen-smu = lpprev.ryzen-smu.overrideAttrs (
181+
oldAttrs:
182+
let
183+
newSrc = oldAttrs.src.override {
184+
owner = "amkillam";
185+
repo = "ryzen_smu";
186+
rev = "172c316f53ac8f066afd7cb9e1da517084273368";
187+
hash = "sha256-U2UMWY7XgLXOpNgl2OsFBRvZSC4/qLa9rzJxFOpZ830=";
188+
};
189+
monitor-cpu = llvm.stdenv.mkDerivation {
190+
pname = "monitor-cpu";
191+
inherit (oldAttrs) version src;
192+
makeFlags = [
193+
"-C userspace"
194+
"CC=${lib.getExe llvm.clang}"
195+
];
196+
installPhase = ''
197+
runHook preInstall
198+
install userspace/monitor_cpu -Dm755 -t $out/bin
199+
runHook postInstall
200+
'';
201+
};
202+
in
203+
{
204+
src = newSrc;
205+
stdenv = pkgs.unstable.overrideCC llvm.stdenv (
206+
llvm.stdenv.cc.override { inherit (llvm) bintools; }
207+
);
208+
nativeBuildInputs = (oldAttrs.nativeBuildInputs or [ ]) ++ [ llvm.lld ];
209+
makeFlags = (oldAttrs.makeFlags or [ ]) ++ [
210+
"CC=${lib.getExe llvm.clang-unwrapped}"
211+
"CXX=${lib.getExe llvm.clang-unwrapped}"
212+
"LD=${llvm.lld}/bin/ld.lld"
213+
];
214+
installPhase = ''
215+
runHook preInstall
216+
install ryzen_smu.ko -Dm444 -t $out/lib/modules/${lpprev.kernel.modDirVersion}/kernel/drivers/ryzen_smu
217+
install ${monitor-cpu}/bin/monitor_cpu -Dm755 -t $out/bin
218+
runHook postInstall
219+
'';
220+
}
221+
);
222+
}
223+
)
224+
)
225+
);
226+
};
227+
}
228+

0 commit comments

Comments
 (0)