nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1# Note: lib/systems/default.nix takes care of producing valid,
2# fully-formed "platform" values (e.g. hostPlatform, buildPlatform,
3# targetPlatform, etc) containing at least the minimal set of attrs
4# required (see types.parsedPlatform in lib/systems/parse.nix). This
5# file takes an already-valid platform and further elaborates it with
6# optional fields; currently these are: linux-kernel, gcc, and rustc.
7
8{ lib }:
9rec {
10 pc = {
11 linux-kernel = {
12 name = "pc";
13
14 baseConfig = "defconfig";
15 # Build whatever possible as a module, if not stated in the extra config.
16 autoModules = true;
17 target = "bzImage";
18 };
19 };
20
21 pc_simplekernel = lib.recursiveUpdate pc {
22 linux-kernel.autoModules = false;
23 };
24
25 ##
26 ## POWER
27 ##
28
29 powernv = {
30 linux-kernel = {
31 name = "PowerNV";
32
33 baseConfig = "powernv_defconfig";
34 target = "vmlinux";
35 autoModules = true;
36 };
37 };
38
39 ppc64 = {
40 linux-kernel = {
41 name = "powerpc64";
42
43 baseConfig = "ppc64_defconfig";
44 target = "vmlinux";
45 autoModules = true;
46 };
47 };
48
49 ##
50 ## ARM
51 ##
52
53 pogoplug4 = {
54 linux-kernel = {
55 name = "pogoplug4";
56
57 baseConfig = "multi_v5_defconfig";
58 autoModules = false;
59 extraConfig = ''
60 # Ubi for the mtd
61 MTD_UBI y
62 UBIFS_FS y
63 UBIFS_FS_XATTR y
64 UBIFS_FS_ADVANCED_COMPR y
65 UBIFS_FS_LZO y
66 UBIFS_FS_ZLIB y
67 UBIFS_FS_DEBUG n
68 '';
69 makeFlags = [ "LOADADDR=0x8000" ];
70 target = "uImage";
71 # TODO reenable once manual-config's config actually builds a .dtb and this is checked to be working
72 #DTB = true;
73 };
74 gcc = {
75 arch = "armv5te";
76 };
77 };
78
79 sheevaplug = {
80 linux-kernel = {
81 name = "sheevaplug";
82
83 baseConfig = "multi_v5_defconfig";
84 autoModules = false;
85 extraConfig = ''
86 BLK_DEV_RAM y
87 BLK_DEV_INITRD y
88 BLK_DEV_CRYPTOLOOP m
89 BLK_DEV_DM m
90 DM_CRYPT m
91 MD y
92 BTRFS_FS m
93 XFS_FS m
94 JFS_FS m
95 EXT4_FS m
96 USB_STORAGE_CYPRESS_ATACB m
97
98 # mv cesa requires this sw fallback, for mv-sha1
99 CRYPTO_SHA1 y
100 # Fast crypto
101 CRYPTO_TWOFISH y
102 CRYPTO_TWOFISH_COMMON y
103 CRYPTO_BLOWFISH y
104 CRYPTO_BLOWFISH_COMMON y
105
106 IP_PNP y
107 IP_PNP_DHCP y
108 NFS_FS y
109 ROOT_NFS y
110 TUN m
111 NFS_V4 y
112 NFS_V4_1 y
113 NFS_FSCACHE y
114 NFSD m
115 NFSD_V2_ACL y
116 NFSD_V3 y
117 NFSD_V3_ACL y
118 NFSD_V4 y
119 NETFILTER y
120 IP_NF_IPTABLES y
121 IP_NF_FILTER y
122 IP_NF_MATCH_ADDRTYPE y
123 IP_NF_TARGET_LOG y
124 IP_NF_MANGLE y
125 IPV6 m
126 VLAN_8021Q m
127
128 CIFS y
129 CIFS_XATTR y
130 CIFS_POSIX y
131 CIFS_FSCACHE y
132 CIFS_ACL y
133
134 WATCHDOG y
135 WATCHDOG_CORE y
136 ORION_WATCHDOG m
137
138 ZRAM m
139 NETCONSOLE m
140
141 # Disable OABI to have seccomp_filter (required for systemd)
142 # https://github.com/raspberrypi/firmware/issues/651
143 OABI_COMPAT n
144
145 # Fail to build
146 DRM n
147 SCSI_ADVANSYS n
148 USB_ISP1362_HCD n
149 SND_SOC n
150 SND_ALI5451 n
151 FB_SAVAGE n
152 SCSI_NSP32 n
153 ATA_SFF n
154 SUNGEM n
155 IRDA n
156 ATM_HE n
157 SCSI_ACARD n
158 BLK_DEV_CMD640_ENHANCED n
159
160 FUSE_FS m
161
162 # systemd uses cgroups
163 CGROUPS y
164
165 # Latencytop
166 LATENCYTOP y
167
168 # Ubi for the mtd
169 MTD_UBI y
170 UBIFS_FS y
171 UBIFS_FS_XATTR y
172 UBIFS_FS_ADVANCED_COMPR y
173 UBIFS_FS_LZO y
174 UBIFS_FS_ZLIB y
175 UBIFS_FS_DEBUG n
176
177 # Kdb, for kernel troubles
178 KGDB y
179 KGDB_SERIAL_CONSOLE y
180 KGDB_KDB y
181 '';
182 makeFlags = [ "LOADADDR=0x0200000" ];
183 target = "uImage";
184 DTB = true; # Beyond 3.10
185 };
186 gcc = {
187 arch = "armv5te";
188 };
189 };
190
191 raspberrypi = {
192 linux-kernel = {
193 name = "raspberrypi";
194
195 baseConfig = "bcm2835_defconfig";
196 DTB = true;
197 autoModules = true;
198 preferBuiltin = true;
199 extraConfig = ''
200 # Disable OABI to have seccomp_filter (required for systemd)
201 # https://github.com/raspberrypi/firmware/issues/651
202 OABI_COMPAT n
203 '';
204 target = "zImage";
205 };
206 gcc = {
207 # https://en.wikipedia.org/wiki/Raspberry_Pi#Specifications
208 arch = "armv6kz";
209 fpu = "vfpv2";
210 };
211 };
212
213 # Legacy attribute, for compatibility with existing configs only.
214 raspberrypi2 = armv7l-hf-multiplatform;
215
216 # Nvidia Bluefield 2 (w. crypto support)
217 bluefield2 = {
218 gcc = {
219 arch = "armv8-a+fp+simd+crc+crypto";
220 };
221 };
222
223 zero-gravitas = {
224 linux-kernel = {
225 name = "zero-gravitas";
226
227 baseConfig = "zero-gravitas_defconfig";
228 # Target verified by checking /boot on reMarkable 1 device
229 target = "zImage";
230 autoModules = false;
231 DTB = true;
232 };
233 gcc = {
234 fpu = "neon";
235 cpu = "cortex-a9";
236 };
237 };
238
239 zero-sugar = {
240 linux-kernel = {
241 name = "zero-sugar";
242
243 baseConfig = "zero-sugar_defconfig";
244 DTB = true;
245 autoModules = false;
246 preferBuiltin = true;
247 target = "zImage";
248 };
249 gcc = {
250 cpu = "cortex-a7";
251 fpu = "neon-vfpv4";
252 float-abi = "hard";
253 };
254 };
255
256 utilite = {
257 linux-kernel = {
258 name = "utilite";
259 maseConfig = "multi_v7_defconfig";
260 autoModules = false;
261 extraConfig = ''
262 # Ubi for the mtd
263 MTD_UBI y
264 UBIFS_FS y
265 UBIFS_FS_XATTR y
266 UBIFS_FS_ADVANCED_COMPR y
267 UBIFS_FS_LZO y
268 UBIFS_FS_ZLIB y
269 UBIFS_FS_DEBUG n
270 '';
271 makeFlags = [ "LOADADDR=0x10800000" ];
272 target = "uImage";
273 DTB = true;
274 };
275 gcc = {
276 cpu = "cortex-a9";
277 fpu = "neon";
278 };
279 };
280
281 guruplug = lib.recursiveUpdate sheevaplug {
282 # Define `CONFIG_MACH_GURUPLUG' (see
283 # <http://kerneltrap.org/mailarchive/git-commits-head/2010/5/19/33618>)
284 # and other GuruPlug-specific things. Requires the `guruplug-defconfig'
285 # patch.
286 linux-kernel.baseConfig = "guruplug_defconfig";
287 };
288
289 beaglebone = lib.recursiveUpdate armv7l-hf-multiplatform {
290 linux-kernel = {
291 name = "beaglebone";
292 baseConfig = "bb.org_defconfig";
293 autoModules = false;
294 extraConfig = ""; # TBD kernel config
295 target = "zImage";
296 };
297 };
298
299 # https://developer.android.com/ndk/guides/abis#v7a
300 armv7a-android = {
301 linux-kernel.name = "armeabi-v7a";
302 gcc = {
303 arch = "armv7-a";
304 float-abi = "softfp";
305 fpu = "vfpv3-d16";
306 };
307 };
308
309 armv7l-hf-multiplatform = {
310 linux-kernel = {
311 name = "armv7l-hf-multiplatform";
312 Major = "2.6"; # Using "2.6" enables 2.6 kernel syscalls in glibc.
313 baseConfig = "multi_v7_defconfig";
314 DTB = true;
315 autoModules = true;
316 preferBuiltin = true;
317 target = "zImage";
318 extraConfig = ''
319 # Serial port for Raspberry Pi 3. Wasn't included in ARMv7 defconfig
320 # until 4.17.
321 SERIAL_8250_BCM2835AUX y
322 SERIAL_8250_EXTENDED y
323 SERIAL_8250_SHARE_IRQ y
324
325 # Hangs ODROID-XU4
326 ARM_BIG_LITTLE_CPUIDLE n
327
328 # Disable OABI to have seccomp_filter (required for systemd)
329 # https://github.com/raspberrypi/firmware/issues/651
330 OABI_COMPAT n
331
332 # >=5.12 fails with:
333 # drivers/net/ethernet/micrel/ks8851_common.o: in function `ks8851_probe_common':
334 # ks8851_common.c:(.text+0x179c): undefined reference to `__this_module'
335 # See: https://lore.kernel.org/netdev/20210116164828.40545-1-marex@denx.de/T/
336 KS8851_MLL y
337 '';
338 };
339 gcc = {
340 # Some table about fpu flags:
341 # http://community.arm.com/servlet/JiveServlet/showImage/38-1981-3827/blogentry-103749-004812900+1365712953_thumb.png
342 # Cortex-A5: -mfpu=neon-fp16
343 # Cortex-A7 (rpi2): -mfpu=neon-vfpv4
344 # Cortex-A8 (beaglebone): -mfpu=neon
345 # Cortex-A9: -mfpu=neon-fp16
346 # Cortex-A15: -mfpu=neon-vfpv4
347
348 # More about FPU:
349 # https://wiki.debian.org/ArmHardFloatPort/VfpComparison
350
351 # vfpv3-d16 is what Debian uses and seems to be the best compromise: NEON is not supported in e.g. Scaleway or Tegra 2,
352 # and the above page suggests NEON is only an improvement with hand-written assembly.
353 arch = "armv7-a";
354 fpu = "vfpv3-d16";
355
356 # For Raspberry Pi the 2 the best would be:
357 # cpu = "cortex-a7";
358 # fpu = "neon-vfpv4";
359 };
360 };
361
362 aarch64-multiplatform = {
363 linux-kernel = {
364 name = "aarch64-multiplatform";
365 baseConfig = "defconfig";
366 DTB = true;
367 autoModules = true;
368 preferBuiltin = true;
369 extraConfig = ''
370 # Raspberry Pi 3 stuff. Not needed for s >= 4.10.
371 ARCH_BCM2835 y
372 BCM2835_MBOX y
373 BCM2835_WDT y
374 RASPBERRYPI_FIRMWARE y
375 RASPBERRYPI_POWER y
376 SERIAL_8250_BCM2835AUX y
377 SERIAL_8250_EXTENDED y
378 SERIAL_8250_SHARE_IRQ y
379
380 # Cavium ThunderX stuff.
381 PCI_HOST_THUNDER_ECAM y
382
383 # Nvidia Tegra stuff.
384 PCI_TEGRA y
385
386 # The default (=y) forces us to have the XHCI firmware available in initrd,
387 # which our initrd builder can't currently do easily.
388 USB_XHCI_TEGRA m
389 '';
390 target = "Image";
391 };
392 gcc = {
393 arch = "armv8-a";
394 };
395 };
396
397 apple-m1 = {
398 gcc = {
399 arch = "armv8.3-a+crypto+sha2+aes+crc+fp16+lse+simd+ras+rdm+rcpc";
400 cpu = "apple-a13";
401 };
402 };
403
404 ##
405 ## MIPS
406 ##
407
408 ben_nanonote = {
409 linux-kernel = {
410 name = "ben_nanonote";
411 };
412 gcc = {
413 arch = "mips32";
414 float = "soft";
415 };
416 };
417
418 fuloong2f_n32 = {
419 linux-kernel = {
420 name = "fuloong2f_n32";
421 baseConfig = "lemote2f_defconfig";
422 autoModules = false;
423 extraConfig = ''
424 MIGRATION n
425 COMPACTION n
426
427 # nixos mounts some cgroup
428 CGROUPS y
429
430 BLK_DEV_RAM y
431 BLK_DEV_INITRD y
432 BLK_DEV_CRYPTOLOOP m
433 BLK_DEV_DM m
434 DM_CRYPT m
435 MD y
436 EXT4_FS m
437 USB_STORAGE_CYPRESS_ATACB m
438
439 IP_PNP y
440 IP_PNP_DHCP y
441 IP_PNP_BOOTP y
442 NFS_FS y
443 ROOT_NFS y
444 TUN m
445 NFS_V4 y
446 NFS_V4_1 y
447 NFS_FSCACHE y
448 NFSD m
449 NFSD_V2_ACL y
450 NFSD_V3 y
451 NFSD_V3_ACL y
452 NFSD_V4 y
453
454 # Fail to build
455 DRM n
456 SCSI_ADVANSYS n
457 USB_ISP1362_HCD n
458 SND_SOC n
459 SND_ALI5451 n
460 FB_SAVAGE n
461 SCSI_NSP32 n
462 ATA_SFF n
463 SUNGEM n
464 IRDA n
465 ATM_HE n
466 SCSI_ACARD n
467 BLK_DEV_CMD640_ENHANCED n
468
469 FUSE_FS m
470
471 # Needed for udev >= 150
472 SYSFS_DEPRECATED_V2 n
473
474 VGA_CONSOLE n
475 VT_HW_CONSOLE_BINDING y
476 SERIAL_8250_CONSOLE y
477 FRAMEBUFFER_CONSOLE y
478 EXT2_FS y
479 EXT3_FS y
480 MAGIC_SYSRQ y
481
482 # The kernel doesn't boot at all, with FTRACE
483 FTRACE n
484 '';
485 target = "vmlinux";
486 };
487 gcc = {
488 arch = "loongson2f";
489 float = "hard";
490 abi = "n32";
491 };
492 };
493
494 # can execute on 32bit chip
495 gcc_mips32r2_o32 = {
496 gcc = {
497 arch = "mips32r2";
498 abi = "32";
499 };
500 };
501 gcc_mips32r6_o32 = {
502 gcc = {
503 arch = "mips32r6";
504 abi = "32";
505 };
506 };
507 gcc_mips64r2_n32 = {
508 gcc = {
509 arch = "mips64r2";
510 abi = "n32";
511 };
512 };
513 gcc_mips64r6_n32 = {
514 gcc = {
515 arch = "mips64r6";
516 abi = "n32";
517 };
518 };
519 gcc_mips64r2_64 = {
520 gcc = {
521 arch = "mips64r2";
522 abi = "64";
523 };
524 };
525 gcc_mips64r6_64 = {
526 gcc = {
527 arch = "mips64r6";
528 abi = "64";
529 };
530 };
531
532 # based on:
533 # https://www.mail-archive.com/qemu-discuss@nongnu.org/msg05179.html
534 # https://gmplib.org/~tege/qemu.html#mips64-debian
535 mips64el-qemu-linux-gnuabi64 = {
536 linux-kernel = {
537 name = "mips64el";
538 baseConfig = "64r2el_defconfig";
539 target = "vmlinuz";
540 autoModules = false;
541 DTB = true;
542 # for qemu 9p passthrough filesystem
543 extraConfig = ''
544 MIPS_MALTA y
545 PAGE_SIZE_4KB y
546 CPU_LITTLE_ENDIAN y
547 CPU_MIPS64_R2 y
548 64BIT y
549 CPU_MIPS64_R2 y
550
551 NET_9P y
552 NET_9P_VIRTIO y
553 9P_FS y
554 9P_FS_POSIX_ACL y
555 PCI y
556 VIRTIO_PCI y
557 '';
558 };
559 };
560
561 ##
562 ## Other
563 ##
564
565 riscv-multiplatform = {
566 linux-kernel = {
567 name = "riscv-multiplatform";
568 target = "Image";
569 autoModules = true;
570 preferBuiltin = true;
571 baseConfig = "defconfig";
572 DTB = true;
573 };
574 };
575
576 loongarch64-multiplatform = {
577 gcc = {
578 # https://github.com/loongson/la-softdev-convention/blob/master/la-softdev-convention.adoc#10-operating-system-package-build-requirements
579 arch = "la64v1.0";
580 strict-align = false;
581 # Avoid text sections of large apps exceeding default code model
582 # Will be default behavior in LLVM 21 and hopefully GCC16
583 # https://github.com/loongson-community/discussions/issues/43
584 # https://github.com/llvm/llvm-project/pull/132173
585 cmodel = "medium";
586 };
587 linux-kernel = {
588 name = "loongarch-multiplatform";
589 target = "vmlinuz.efi";
590 autoModules = true;
591 preferBuiltin = true;
592 baseConfig = "defconfig";
593 DTB = true;
594 };
595 };
596
597 # This function takes a minimally-valid "platform" and returns an
598 # attrset containing zero or more additional attrs which should be
599 # included in the platform in order to further elaborate it.
600 select =
601 platform:
602 # x86
603 if platform.isx86 then
604 pc
605
606 # ARM
607 else if platform.isAarch32 then
608 let
609 version = platform.parsed.cpu.version or null;
610 in
611 if version == null then
612 pc
613 else if lib.versionOlder version "6" then
614 sheevaplug
615 else if lib.versionOlder version "7" then
616 raspberrypi
617 else
618 armv7l-hf-multiplatform
619
620 else if platform.isAarch64 then
621 if platform.isDarwin then apple-m1 else aarch64-multiplatform
622
623 else if platform.isLoongArch64 then
624 loongarch64-multiplatform
625
626 else if platform.isRiscV then
627 riscv-multiplatform
628
629 else if platform.parsed.cpu == lib.systems.parse.cpuTypes.mipsel then
630 (import ./examples.nix { inherit lib; }).mipsel-linux-gnu
631
632 else if platform.isPower64 then
633 if platform.isLittleEndian then powernv else ppc64
634
635 else if platform.isLoongArch64 then
636 loongarch64-multiplatform
637 else
638 { };
639}