-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.nix
More file actions
194 lines (173 loc) · 5.38 KB
/
kernel.nix
File metadata and controls
194 lines (173 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
{
stdenv,
lib,
flex,
bison,
bc,
perl,
gcc,
openssl,
python3Minimal,
pkg-config,
fetchurl,
buildPackages,
elfutils,
zstd,
hexdump,
ubootTools,
pkgsBuildBuild,
pahole,
zlib,
kernelConfig ? null,
}:
stdenv.mkDerivation (finalAttrs: {
name = "linux";
version = "6.19.2";
src = fetchurl {
url = "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-${finalAttrs.version}.tar.xz";
hash = "sha256-iGEZgVgszrfN1NaI2diBBzz0l3F2JSGTojym1LmC7lo=";
};
# BUG: "MIPS: mm: tlb-r4k: Uniquify TLB entries on init" since 6.16.1
postPatch = lib.optionalString stdenv.hostPlatform.isMips64 ''
substituteInPlace arch/mips/mm/tlb-r4k.c \
--replace-fail "r4k_tlb_uniquify();" "local_flush_tlb_all();"
'';
buildInputs = [ ];
nativeBuildInputs = [
flex
bison
bc
perl
pkg-config
python3Minimal
elfutils
openssl
pahole # needed for EBPF CONFIG_DEBUG_INFO_BTF
zlib # needed for EBPF (libbpf.so)
]
++ lib.optionals stdenv.targetPlatform.isLoongArch64 [
hexdump
zstd
]
++ lib.optionals stdenv.targetPlatform.isMips [
pkgsBuildBuild.ubootTools
];
strictDeps = true;
dontStrip = true;
depsBuildBuild = [ buildPackages.stdenv.cc ];
enableParallelBuilding = true;
env = {
ARCH = "${stdenv.hostPlatform.linuxArch}";
CROSS_COMPILE = "${stdenv.cc.targetPrefix}";
# TODO: vdso armv7l on aarch64? (VDSO COMPAT)
# NIX_CFLAGS_COMPILE =" -fno-omit-frame-pointer -O2";
};
preBuild =
let
defconfig =
if stdenv.hostPlatform.isMips32 then
"malta_defconfig"
else if stdenv.hostPlatform.isMips64 then
"loongson3_defconfig"
else
"defconfig";
in
''
make ${defconfig}
patchShebangs scripts/
# Enable debug symbols
scripts/config --disable CONFIG_DEBUG_INFO_REDUCED
scripts/config --enable CONFIG_FRAME_POINTER
scripts/config --enable CONFIG_DEBUG_KERNEL
scripts/config --enable CONFIG_DEBUG_INFO
scripts/config --enable CONFIG_DEBUG_INFO_DWARF5
scripts/config --enable CONFIG_GDB_SCRIPTS
# ebpf
scripts/config --enable CONFIG_BPF
scripts/config --enable CONFIG_DEBUG_INFO_BTF
scripts/config --enable CONFIG_BPF_SYSCALL
scripts/config --enable CONFIG_BPF_JIT
scripts/config --enable CONFIG_BPF_EVENTS
scripts/config --enable CONFIG_BPF_LSM
scripts/config --enable CONFIG_NETFILTER_BPF_LINK
scripts/config --enable CONFIG_NET_SCH_BPF
scripts/config --enable CONFIG_NET_CLS_BPF
scripts/config --enable CONFIG_NET_ACT_BPF
scripts/config --enable CONFIG_CGROUP_BPF
# debug
scripts/config --enable CONFIG_DEBUG_FS
scripts/config --enable CONFIG_PTDUMP
scripts/config --enable CONFIG_PTDUMP_DEBUGFS
scripts/config --enable CONFIG_ANON_VMA_NAME
scripts/config --enable CONFIG_IKCONFIG
scripts/config --enable CONFIG_IKCONFIG_PROC
scripts/config --enable CONFIG_IKHEADERS
# Virtio
scripts/config --enable CONFIG_FS_POSIX_ACL
scripts/config --enable CONFIG_FUSE_FS
scripts/config --enable CONFIG_BLOCK
scripts/config --enable CONFIG_EROFS_FS
scripts/config --enable CONFIG_VIRTIO_FS
scripts/config --enable CONFIG_VIRTIO_VSOCKETS
scripts/config --enable CONFIG_VIRTIO_BLK
scripts/config --enable CONFIG_VIRTIO_NET
scripts/config --enable CONFIG_VIRTIO_PCI
scripts/config --enable CONFIG_VIRTIO_MEM
scripts/config --enable CONFIG_VIRTIO_MMIO
scripts/config --enable CONFIG_VIRTIO_IOMMU
scripts/config --enable CONFIG_VIRTIO_CONSOLE
scripts/config --enable CONFIG_VSOCKETS
scripts/config --enable CONFIG_VHOST_NET
scripts/config --enable CONFIG_NET_9P
scripts/config --enable CONFIG_NET_9P_VIRTIO
scripts/config --enable CONFIG_9P_FS
scripts/config --enable CONFIG_9P_FS_POSIX_ACL
# extra
scripts/config --enable CONFIG_OVERLAY_FS
scripts/config --enable CONFIG_SQUASHFS
scripts/config --enable CONFIG_SQUASHFS_ZLIB
sed -i 's/=m$/=n/' .config
''
+ lib.optionalString (stdenv.hostPlatform.isMips || stdenv.hostPlatform.isSparc) ''
scripts/config --enable CONFIG_USER_NS
scripts/config --enable CONFIG_CGROUPS
''
+ lib.optionalString stdenv.hostPlatform.isBigEndian ''
scripts/config --enable CONFIG_CPU_BIG_ENDIAN
scripts/config --disable CONFIG_CPU_LITTLE_ENDIAN
''
+ lib.optionalString stdenv.hostPlatform.isLittleEndian ''
scripts/config --disable CONFIG_CPU_BIG_ENDIAN
scripts/config --enable CONFIG_CPU_LITTLE_ENDIAN
''
+ lib.optionalString (kernelConfig != null) ''
'';
installPhase = ''
make scripts_gdb
mkdir -p $out/scripts/
cp ./vmlinux-gdb.py $out/
cp -rf ./scripts/gdb/ $out/scripts/
cp vmlinux $out/vmlinux
cp vmlinux $out/vmlinux.debug
cp .config $out/
cp System.map $out/
cp arch/*/boot/Image $out/ || true
cp arch/*/boot/bzImage $out/ || true
cp arch/*/boot/zImage $out/ || true
cp -rf arch/*/boot/dts/ $out/ || true
${stdenv.cc.targetPrefix}strip --strip-debug $out/vmlinux
'';
passthru = {
source_unpacked = finalAttrs.overrideAttrs (o: {
phases = [
"unpackPhase"
"patchPhase"
"installPhase"
];
installPhase = ''
mkdir -p $out
cp -r $(pwd) $out
'';
});
};
})