-
Notifications
You must be signed in to change notification settings - Fork 5
/
gentoo.sh
1352 lines (1249 loc) · 55.7 KB
/
gentoo.sh
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SPDX-License-Identifier: GPL-3.0-or-later
packages=(app-shells/bash sys-apps/coreutils)
packages_buildroot=()
options[enforcing]=
function create_buildroot() {
local -r arch=${options[arch]:=$DEFAULT_ARCH}
local -r host=${options[host]:=$arch-${options[distro]}-linux-gnu$([[ $arch == arm* ]] && echo eabi${options[hardfp]:+hf})}
local -r profile=${options[profile]-$(archmap_profile "$arch")}
local -r stage3=${options[stage3]:-$(archmap_stage3)}
opt bootable || opt selinux && packages_buildroot+=(sys-kernel/gentoo-sources)
opt gpt && opt uefi && packages_buildroot+=(sys-fs/dosfstools sys-fs/mtools)
opt ramdisk || opt selinux || opt verity_sig && packages_buildroot+=(app-arch/cpio)
opt read_only && ! opt squash && packages_buildroot+=(sys-fs/erofs-utils)
opt secureboot && packages_buildroot+=(app-crypt/pesign dev-libs/nss)
opt selinux && packages_buildroot+=(app-emulation/qemu sys-apps/busybox)
opt squash && packages_buildroot+=(sys-fs/squashfs-tools)
opt uefi && packages_buildroot+=('<gnome-base/librsvg-2.41' media-gfx/imagemagick x11-themes/gentoo-artwork)
opt uefi_vars && packages_buildroot+=(app-emulation/qemu)
opt verity && packages_buildroot+=(sys-fs/cryptsetup)
packages_buildroot+=(dev-util/debugedit)
$curl -L "$stage3.asc" > "$output/stage3.txz.sig"
$curl -L "$stage3" > "$output/stage3.txz"
verify_distro "$output"/stage3.txz{.sig,}
$tar -C "$buildroot" -xJf "$output/stage3.txz"
$rm -f "$output"/stage3.txz{.sig,}
# Write a portage profile common to the native host and target system.
local portage="$buildroot/etc/portage"
$mv "$portage" "$portage.stage3"
$mkdir -p "$portage"/{env,make.profile,package.{accept_keywords,env,license,mask,unmask,use},profile/{package.,}use.{force,mask},repos.conf,sets}
$cp -at "$portage" "$portage.stage3/make.conf"
$cat << EOF >> "$portage/make.profile/parent"
gentoo:$(archmap_profile)
gentoo:targets/systemd$(
opt selinux && echo -e '\ngentoo:features/selinux')
EOF
echo "$buildroot"/etc/env.d/gcc/config-* | $sed 's,.*/[^-]*-\(.*\),\nCBUILD="\1",' >> "$portage/make.conf"
$cat << EOF >> "$portage/make.conf"
EMERGE_DEFAULT_OPTS="--jobs=$(c=(/sys/devices/system/cpu/cpu[0-9]*);for((n=${#c[@]}>>2,p=2;p<n;p<<=1))do :;done;echo $p)"
FEATURES="multilib-strict parallel-fetch parallel-install xattr -merge-sync -network-sandbox -news -selinux"
GRUB_PLATFORMS="${options[uefi]:+efi-$([[ $arch == *64* ]] && echo 64 || echo 32)}"
INPUT_DEVICES="libinput"
LLVM_TARGETS="$(archmap_llvm "$arch")"
POLICY_TYPES="${options[selinux]:-targeted}"
RUSTFLAGS="-Copt-level=3"
USE="\$USE system-icu system-png -dracut -gtk-doc -initramfs -installkernel -introspection -telemetry -vala"
VIDEO_CARDS=""
EOF
$cat << 'EOF' >> "$portage/package.accept_keywords/core.conf"
# Accept core utilities with no stable versions.
app-crypt/pesign ~*
sys-apps/keyutils *
sys-boot/vboot-utils ~*
sys-fs/erofs-utils ~*
EOF
$cat << 'EOF' >> "$portage/package.accept_keywords/firefox.conf"
# Accept the latest (non-ESR) Firefox release.
dev-libs/nspr ~*
dev-libs/nss ~*
www-client/firefox ~*
EOF
$cat << 'EOF' >> "$portage/package.accept_keywords/gnome.conf"
# Accept viable versions of GNOME packages.
gnome-base/* *
gnome-extra/* *
app-arch/gnome-autoar *
dev-libs/libgweather *
gui-libs/libhandy *
media-gfx/gnome-screenshot *
media-libs/gsound *
net-wireless/gnome-bluetooth *
sci-geosciences/geocode-glib *
x11-libs/colord-gtk *
x11-terms/gnome-terminal *
x11-wm/mutter *
EOF
$cat << 'EOF' >> "$portage/package.accept_keywords/linux.conf"
# Accept the newest kernel and SELinux policy.
dev-debug/strace ~*
sec-policy/* ~*
sys-kernel/gentoo-kernel ~*
sys-kernel/gentoo-sources ~*
sys-kernel/git-sources ~*
sys-kernel/linux-headers ~*
virtual/dist-kernel ~*
EOF
$cat << 'EOF' >> "$portage/package.accept_keywords/rust.conf"
# Accept Rust users to bypass bad keywording.
dev-lang/rust *
dev-lang/spidermonkey *
dev-libs/gjs *
gnome-base/librsvg *
virtual/rust *
x11-themes/adwaita-icon-theme *
EOF
$cat << 'EOF' >> "$portage/package.accept_keywords/sway.conf"
# Accept viable versions of Sway packages.
dev-libs/tllist *
gui-apps/foot *
gui-apps/swaybg *
gui-apps/swayidle *
gui-apps/swaylock *
gui-libs/wlroots *
gui-wm/sway *
media-libs/fcft *
sys-auth/seatd *
EOF
$cat << 'EOF' >> "$portage/package.license/ucode.conf"
# Accept CPU microcode licenses.
sys-firmware/intel-microcode intel-ucode
sys-kernel/linux-firmware linux-fw-redistributable no-source-code
EOF
$cat << 'EOF' >> "$portage/package.mask/emacs.conf"
# Block newer Emacs until cross-compiling is fixed again.
>=app-editors/emacs-29
EOF
$cat << 'EOF' >> "$portage/package.mask/rust.conf"
# Block the wildly inappropriate default behavior of not compiling Rust.
dev-lang/rust-bin
EOF
$cat << 'EOF' >> "$portage/package.unmask/rust.conf"
# Unmask Rust users to bypass bad architecture profiles.
dev-lang/rust
dev-lang/spidermonkey
dev-libs/gjs
gnome-base/librsvg
virtual/rust
x11-themes/adwaita-icon-theme
EOF
$cat << 'EOF' >> "$portage/package.use/busybox.conf"
# Make busybox static by default since nobody expects it to be otherwise.
sys-apps/busybox static -pam
EOF
$cat << 'EOF' >> "$portage/package.use/cdrtools.conf"
# Support file capabilities when making ISO images.
app-cdr/cdrtools caps
EOF
$cat << 'EOF' >> "$portage/package.use/cryptsetup.conf"
# Choose nettle as the crypto backend.
sys-fs/cryptsetup nettle -gcrypt -kernel -openssl
EOF
$cat << 'EOF' >> "$portage/package.use/emacs.conf"
# Disable native Emacs Lisp compilation until cross-compiling works.
app-editors/emacs -jit
EOF
$cat << 'EOF' >> "$portage/package.use/firefox.conf"
# Fix Firefox builds by preferring GCC over Clang.
www-client/firefox -clang
EOF
$cat << 'EOF' >> "$portage/package.use/gtk.conf"
# Disable EOL GTK+ 2 by default.
*/* -gtk2
EOF
$cat << 'EOF' >> "$portage/package.use/linux.conf"
# Disable trying to build an initrd, and use hardened options.
sys-kernel/gentoo-kernel hardened -initramfs
# Apply patches to support more CPU optimizations, and link a default version.
sys-kernel/gentoo-sources experimental symlink
# Also link a default version when building release candidates.
sys-kernel/git-sources symlink
EOF
$cat << 'EOF' >> "$portage/package.use/llvm.conf"
# Make clang use its own linker by default.
sys-devel/clang default-lld
EOF
$cat << 'EOF' >> "$portage/package.use/pulseaudio.conf"
# Skip the PulseAudio daemon by default since PipeWire gets priority.
media-sound/pulseaudio -daemon
media-video/pipewire sound-server -modemmanager
EOF
$cat << 'EOF' >> "$portage/package.use/selinux.conf"
# Don't pull in Qt for SELinux tools.
app-admin/setools -X
EOF
$cat << 'EOF' >> "$portage/package.use/shadow.conf"
# Don't use shadow's built in cracklib support since PAM provides it.
sys-apps/shadow -cracklib
EOF
$cat << 'EOF' >> "$portage/package.use/squashfs-tools.conf"
# Support zstd squashfs compression.
sys-fs/squashfs-tools zstd
EOF
$cat << 'EOF' >> "$portage/package.use/sudo.conf"
# Prefer gcrypt's digest functions instead of those from sudo or OpenSSL.
app-admin/sudo gcrypt -ssl
EOF
$cat << 'EOF' >> "$portage/profile/package.use.mask/emacs.conf"
# Support Emacs browser widgets everywhere so Emacs can handle everything.
app-editors/emacs -xwidgets
EOF
$cat << 'EOF' >> "$portage/profile/package.use.mask/rust.conf"
# Allow sharing LLVM and the native Rust for cross-bootstrapping.
dev-lang/rust -system-bootstrap -system-llvm
EOF
$cat << 'EOF' >> "$portage/profile/use.mask/rust.conf"
# Unmask Rust users to bypass bad architecture profiles.
-svg
EOF
$cat << 'EOF' >> "$portage/profile/use.mask/ssl.conf"
# Mask support for insecure protocols.
sslv2
sslv3
EOF
# Permit selectively toggling important features.
echo -e '-selinux\n-static\n-static-libs' >> "$portage/profile/use.force/unforce.conf"
echo -e '-clang\n-systemd' >> "$portage/profile/use.mask/unmask.conf"
# Write build environment modifiers for later use.
echo "CTARGET=\"$host\"" >> "$portage/env/ctarget.conf"
$cat << 'EOF' >> "$portage/env/no-lto.conf"
CFLAGS="$CFLAGS -fno-lto"
CXXFLAGS="$CXXFLAGS -fno-lto"
FFLAGS="$FFLAGS -fno-lto"
FCFLAGS="$FCFLAGS -fno-lto"
EOF
$cat << EOF >> "$portage/env/rust-map.conf"
I_KNOW_WHAT_I_AM_DOING_CROSS="yes"
RUST_CROSS_TARGETS="$(archmap_llvm "$arch"):$(archmap_rust "$arch"):$host"
EOF
# Accept busybox-1.36 to fix compiling with Linux 6.8.
echo '<sys-apps/busybox-1.37 ~*' >> "$portage/package.accept_keywords/busybox.conf"
# Accept libgpiod-2 to use the new kernel API.
echo '<dev-libs/libgpiod-3 ~*' >> "$portage/package.accept_keywords/libgpiod.conf"
write_unconditional_patches "$portage/patches"
# Create the target portage profile based on the native root's.
portage="$buildroot/usr/$host/etc/portage"
$mkdir -p "${portage%/portage}"
$cp -at "${portage%/portage}" "$buildroot/etc/portage"
$cat << EOF > "$portage/make.profile/parent"
$([[ -n $profile ]] && echo "gentoo:$profile" || {
generic=(base arch/base default/linux releases/17.0)
IFS=$'\n' ; echo "${generic[*]/#/gentoo:}"
})
gentoo:targets/systemd$(
opt selinux && echo -e '\ngentoo:features/selinux')
EOF
$sed -i -e '/^COMMON_FLAGS=/s/[" ]*$/ -ggdb -flto&/' "$portage/make.conf"
$cat <(echo) - << EOF >> "$portage/make.conf"
BUILD_PKG_CONFIG_LIBDIR="/usr/lib$([[ $DEFAULT_ARCH == *64* ]] && echo 64)/pkgconfig"
CHOST="$host"
GOARCH="$(archmap_go "$arch")"$(
[[ $arch == i[3-5]86 ]] && echo -e '\nGO386="softfloat"'
[[ $arch == armv[5-7]* ]] && echo -e "\nGOARM=\"${arch:4:1}\"")
RUST_TARGET="$(archmap_rust "$arch")"
EOF
$cat << 'EOF' >> "$portage/make.conf"
ROOT="/usr/$CHOST"
BINPKG_COMPRESS="zstd"
BINPKG_COMPRESS_FLAGS="--fast --threads=0"
FEATURES="$FEATURES buildpkg compressdebug installsources pkgdir-index-trusted splitdebug"
PKG_INSTALL_MASK="$PKG_INSTALL_MASK .keep*dir .keep_*_*-*"
PKGDIR="$ROOT/var/cache/binpkgs"
PYTHON_TARGETS="$PYTHON_SINGLE_TARGET"
SYSROOT="$ROOT"
USE="$USE modules-sign -kmod -multiarch -static -static-libs"
EOF
$cat << 'EOF' >> "$portage/package.use/gnutls.conf"
# When a package requires a single TLS implementation, standardize on GnuTLS.
net-misc/curl gnutls -curl_ssl_* curl_ssl_gnutls
net-misc/networkmanager gnutls -nss
EOF
$cat << 'EOF' >> "$portage/package.use/nftables.conf"
# Use the newer backend in iptables.
net-firewall/iptables nftables
EOF
$cat << 'EOF' >> "$portage/package.use/python.conf"
# Disable bad dependencies that break cross-compilation.
dev-python/urllib3 -brotli
EOF
$cat << 'EOF' >> "$portage/package.use/sqlite.conf"
# Always enable secure delete for SQLite.
dev-db/sqlite secure-delete
EOF
echo 'gl_cv_macro_MB_CUR_MAX_good="yes"' >> "$portage/env/cross-coreutils.conf"
{ [[ $host == x86_64-gentoo-linux-gnu ]] || echo 'EXTRA_EMAKE="SECCOMP_FILTER="' ; } >> "$portage/env/cross-emacs.conf"
echo 'EXTRA_EMAKE="GDBUS_CODEGEN=/usr/bin/gdbus-codegen GLIB_MKENUMS=/usr/bin/glib-mkenums"' >> "$portage/env/cross-emake-utils.conf"
echo 'MYMESONARGS="-Dedje-cc=/usr/bin/edje_cc -Deet=/usr/bin/eet -Deldbus-codegen=/usr/bin/eldbus-codegen"' >> "$portage/env/cross-enlightenment.conf"
echo 'GLIB_COMPILE_RESOURCES="/usr/bin/glib-compile-resources"' >> "$portage/env/cross-glib-compile-resources.conf"
echo 'GLIB_GENMARSHAL="/usr/bin/glib-genmarshal"' >> "$portage/env/cross-glib-genmarshal.conf"
echo 'GLIB_MKENUMS="/usr/bin/glib-mkenums"' >> "$portage/env/cross-glib-mkenums.conf"
echo 'LIBASSUAN_CONFIG="/usr/bin/$CHOST-pkg-config libassuan"' >> "$portage/env/cross-libassuan.conf"
echo 'CFLAGS="$CFLAGS -I$SYSROOT/usr/include/libnl3"' >> "$portage/env/cross-libnl.conf"
echo 'CPPFLAGS="$CPPFLAGS -I$SYSROOT/usr/include/libusb-1.0"' >> "$portage/env/cross-libusb.conf"
echo 'EXTRA_EMAKE="PYTHON_INCLUDES=/usr/\$(host)/usr/include/\$\${PYTHON##*/}"' >> "$portage/env/cross-libxml2-python.conf"
echo 'NPTH_CONFIG="$SYSROOT/usr/bin/npth-config"' >> "$portage/env/cross-npth.conf"
echo 'PKG_CONFIG_LIBDIR="$SYSROOT/usr/lib'$([[ ${options[arch]} == *64* ]] && echo 64)'/pkgconfig:$SYSROOT/usr/share/pkgconfig"' >> "$portage/env/cross-qt5.conf"
echo -e 'QT_HOST_PATH="/usr"\nMYCMAKEARGS="-DQT_HOST_PATH_CMAKE_DIR:PATH=/usr/lib'$([[ $DEFAULT_ARCH == *64* ]] && echo 64)'/cmake"' >> "$portage/env/cross-qt6.conf"
echo 'AT_M4DIR="m4"' >> "$portage/env/kbd.conf"
echo 'EXTRA_ECONF="--with-sdkdir=/usr/include/xorg"' >> "$portage/env/xf86-sdk.conf"
$cat << 'EOF' >> "$portage/package.env/fix-cross-compiling.conf"
# Adjust the environment for cross-compiling broken packages.
app-crypt/gnupg cross-libusb.conf cross-npth.conf
app-crypt/gpgme cross-libassuan.conf
app-editors/emacs cross-emacs.conf
app-i18n/ibus cross-glib-genmarshal.conf
dev-libs/dbus-glib cross-glib-genmarshal.conf
dev-libs/libxml2 cross-libxml2-python.conf
dev-qt/*:5 cross-qt5.conf
dev-qt/qtbase:6 cross-qt6.conf
gnome-base/librsvg cross-emake-utils.conf
net-libs/libmbim cross-emake-utils.conf
net-misc/modemmanager cross-emake-utils.conf
net-wireless/wpa_supplicant cross-libnl.conf
sys-apps/coreutils cross-coreutils.conf
x11-drivers/xf86-input-libinput xf86-sdk.conf
x11-libs/gtk+ cross-glib-compile-resources.conf cross-glib-genmarshal.conf cross-glib-mkenums.conf
x11-wm/enlightenment cross-enlightenment.conf
EOF
echo 'sys-apps/kbd kbd.conf' >> "$portage/package.env/kbd.conf"
$cat << 'EOF' >> "$portage/package.env/no-lto.conf"
# Turn off LTO for broken packages.
dev-libs/icu no-lto.conf
dev-libs/libaio no-lto.conf
dev-libs/libbsd no-lto.conf
media-gfx/potrace no-lto.conf
sys-apps/sandbox no-lto.conf
sys-libs/libselinux no-lto.conf
sys-libs/libsemanage no-lto.conf
sys-libs/libsepol no-lto.conf
x11-drivers/xf86-video-intel no-lto.conf
EOF
echo '>=dev-lang/spidermonkey-91 -lto' >> "$portage/package.use/spidermonkey.conf"
echo -e '-audit\n-caps' >> "$portage/profile/use.force/selinux.conf"
echo split-usr >> "$portage/profile/use.mask/usrmerge.conf"
# Write portage profile settings that only apply to the native root.
portage="$buildroot/etc/portage"
# Preserve bindist in the build root, and don't build documentation.
$sed -i -e '/^USE=/s/USE /&-doc bindist /' "$portage/make.conf"
# Compile GRUB modules for the target system.
echo 'sys-boot/grub ctarget.conf' >> "$portage/package.env/grub.conf"
# Support cross-compiling Rust projects.
[[ $(archmap_rust) == $(archmap_rust "$arch") ]] ||
echo 'dev-lang/rust rust-map.conf' >> "$portage/package.env/rust.conf"
# Mask self-dependent edits in the native root.
$cat << 'EOF' >> "$portage/package.mask/self.conf"
dev-libs/efl::fixes
dev-libs/nss::fixes
dev-qt/qtbase:6::fixes
EOF
# Skip systemd for busybox since the labeling initrd has no real init.
echo 'sys-apps/busybox -selinux -systemd' >> "$portage/package.use/busybox.conf"
# Install colord utilities without the daemon due to huge dependencies.
echo 'x11-misc/colord -daemon' >> "$portage/package.use/colord.conf"
# Only install basic EFL tools.
echo 'dev-libs/efl -* lua_single_target_lua5-1' >> "$portage/package.use/efl.conf"
# Support zstd in CMake builds.
echo 'app-arch/libarchive zstd' >> "$portage/package.use/libarchive.conf"
# Make a static libcrypt in the buildroot for busybox.
echo -e 'sys-libs/libxcrypt static-libs\nvirtual/libcrypt static-libs' >> "$portage/package.use/libcrypt.conf"
# Preserve JIT support in libpcre2 to avoid a needless rebuild.
echo 'dev-libs/libpcre2 jit' >> "$portage/package.use/libpcre2.conf"
# Rust isn't built into the stage3 to bootstrap, but it can share LLVM.
echo 'dev-lang/rust system-llvm -system-bootstrap' >> "$portage/package.use/rust.conf"
# Disable journal compression to skip the massive CMake dependency.
echo 'sys-apps/systemd -lz4' >> "$portage/package.use/systemd.conf"
# Support building the UEFI logo image and signing tools.
opt uefi && $cat << 'EOF' >> "$portage/package.use/uefi.conf"
dev-libs/nss utils
media-gfx/imagemagick svg xml
EOF
# Work around bad dependencies requiring X on the host.
$cat << 'EOF' >> "$portage/package.use/X.conf"
dev-qt/qtgui:5 X
media-libs/libepoxy X
media-libs/libglvnd X
media-libs/mesa X
x11-libs/cairo X
x11-libs/gtk+ X
x11-libs/libxkbcommon X
EOF
# Prevent accidentally disabling required modules.
echo 'dev-libs/libxml2 python' >> "$portage/profile/package.use.force/libxml2.conf"
# Write portage scripts for bootstrapping circular dependencies later.
$cat << 'EOF' > "$buildroot/usr/bin/deepdeps"
#!/usr/bin/env python3
import portage, sys
def process(atom):
matches = portage.portdb.match(atom)
if len(matches) < 1: return
settings.setcpv(portage.best(matches), mydb=portage.portdb)
global deps
if settings.mycpv in deps: return
deps += [settings.mycpv]
for dep in portage.dep.use_reduce(settings.get('DEPEND', '') + '\n' + settings.get('PDEPEND', '') + '\n' + settings.get('RDEPEND', ''), uselist=settings.get('PORTAGE_USE', '').split()):
if type(dep) is not str or dep == '||' or dep.startswith('!'): continue
process(dep.split('[')[0])
deps = []
settings = portage.config(clone=portage.settings)
for arg in sys.argv[1:]: process(arg)
for pkg in deps: print(pkg)
EOF
$cat << 'EOF' > "$buildroot/usr/bin/using"
#!/usr/bin/env python3
import portage, sys
def using(atom, flags):
settings = portage.config(clone=portage.settings)
matches = portage.portdb.match(atom)
if len(matches) >= 1:
settings.setcpv(portage.best(matches), mydb=portage.portdb)
return {f for f in settings.get('PORTAGE_USE', '').split() if f in flags} == flags
sys.exit(2 if len(sys.argv) < 3 else 0 if using(sys.argv[1], set(sys.argv[2:])) else 1)
EOF
$chmod 0755 "$buildroot"/usr/bin/{deepdeps,using}
# Write cross-clang wrappers. They'll fail if clang isn't installed.
$cat << 'EOF' > "$buildroot/usr/bin/$host-clang"
#!/bin/sh -eu
name="${0##*/}"
host="${name%-*}"
prog="/usr/lib/llvm/18/bin/${name##*-}"
exec "$prog" --sysroot="/usr/$host" --target="$host" "$@"
EOF
$chmod 0755 "$buildroot/usr/bin/$host-clang"
$ln -fn "$buildroot/usr/bin/$host-clang"{,++}
# Work around bad PolicyKit dependencies.
$mkdir -p "$buildroot/usr/share/gettext/its"
$ln -fst "$buildroot/usr/share/gettext/its" \
"/usr/$host/usr/share/gettext/its"/polkit.{its,loc}
write_base_kernel_config
initialize_buildroot "$@"
$cat <(declare -f write_overlay) - << 'EOF' | script "$host" "${packages_buildroot[@]}"
host=$1 ; shift
# Fetch the latest package definitions, and fix them in an overlay.
emerge-webrsync
mkdir -p /var/db/repos/fixes/{eclass,metadata}
cat << 'EOG' > /var/db/repos/fixes/metadata/layout.conf
masters = gentoo
repo-name = fixes
EOG
tee {,/usr/"$host"}/etc/portage/repos.conf/fixes.conf << 'EOG'
[fixes]
location = /var/db/repos/fixes
EOG
write_overlay /var/db/repos/fixes
(cd /var/db/repos/gentoo/eclass && exec ln -bst . ../../fixes/eclass/*)
# Update the native build root packages to the latest versions.
emerge --changed-use --deep --update --verbose --with-bdeps=y \
@world sys-devel/crossdev
# Create the sysroot layout and cross-compiler toolchain.
export {PORTAGE_CONFIG,,SYS}ROOT="/usr/$host"
mkdir -p "$ROOT"/usr/{bin,src}
ln -fns bin "$ROOT/usr/sbin"
ln -fst "$ROOT" usr/{bin,sbin}
emerge --nodeps --oneshot --verbose sys-apps/baselayout
unset {PORTAGE_CONFIG,,SYS}ROOT
cat << 'EOG' >> /etc/portage/repos.conf/crossdev.conf
[crossdev]
location = /var/db/repos/crossdev
EOG
crossdev --stable --target "$host"
# Install all requirements for building the target image.
exec emerge --changed-use --update --verbose "$@"
EOF
build_relabel_kernel
}
function install_packages() {
local -rx {PORTAGE_CONFIG,,SYS}ROOT="/usr/${options[host]}"
local -a packages_sysroot=()
opt bootable || opt networkd && packages+=(acct-group/mail sys-apps/systemd)
opt selinux && packages+=(sec-policy/selinux-base-policy)
# If a system-specific kernel config was not given, use dist-kernel.
if opt bootable
then
[[ -s /etc/kernel/config.d/system.config ]] &&
: ${options[raw_kernel]=1}
cat << EOF >> /etc/kernel/config.d/keys.config
CONFIG_MODULE_SIG_KEY="$keydir/sign.pem"
$(opt verity_sig || echo '#')CONFIG_SYSTEM_TRUSTED_KEYS="$keydir/verity.crt"
EOF
if ! opt raw_kernel
then
chgrp portage "$keydir" ; chmod g+x "$keydir"
packages_sysroot+=(sys-kernel/gentoo-kernel)
fi
fi
cat << EOF >> "$ROOT/etc/portage/make.conf"
MODULES_SIGN_CERT="$keydir/sign.pem"
MODULES_SIGN_KEY="$keydir/sign.pem"
EOF
# Build an unpackaged kernel now so external modules can use its files.
if opt raw_kernel
then
local -r kernel_arch="$(archmap_kernel "${options[arch]}")"
KCONFIG_CONFIG=/root/config \
/usr/src/linux/scripts/kconfig/merge_config.sh \
-m -r /etc/kernel/config.d/*.config
make -C /usr/src/linux -j"$(nproc)" \
allnoconfig KCONFIG_ALLCONFIG=/root/config \
ARCH="$kernel_arch" CROSS_COMPILE="${options[host]}-" V=1
make -C /usr/src/linux -j"$(nproc)" \
ARCH="$kernel_arch" CROSS_COMPILE="${options[host]}-" V=1
ln -fst "$ROOT/usr/src" ../../../../usr/src/linux
cat << 'EOF' >> "$ROOT/etc/portage/profile/package.provided"
# The kernel source is shared between the host and cross-compiled root.
sys-kernel/gentoo-sources-9999
EOF
fi < /dev/null
# Build the cross-compiled toolchain packages first.
COLLISION_IGNORE='*' USE=-selinux emerge --oneshot --verbose \
sys-devel/gcc virtual/libc virtual/libcrypt virtual/os-headers
packages+=(sys-devel/gcc virtual/libc) # Install libstdc++ etc.
# Cheat bootstrapping packages with circular dependencies.
local -a bootstrap_packages=()
using media-libs/freetype harfbuzz && bootstrap_packages+=(media-libs/harfbuzz)
using media-libs/libsndfile minimal || bootstrap_packages+=(media-libs/libsndfile)
using media-libs/libwebp tiff && using media-libs/tiff webp && bootstrap_packages+=(media-libs/libwebp)
using media-libs/mesa vaapi && using media-libs/libva opengl && bootstrap_packages+=(media-libs/libva)
if [[ ${#bootstrap_packages[@]} -gt 0 ]]
then
deepdeps "${packages[@]}" "${packages_sysroot[@]}" "$@" |
sed 's/-[0-9].*//' |
{ grep -Fsx "${bootstrap_packages[@]/#/-e}" || : ; } | sort -u
fi > "$ROOT/etc/portage/sets/bootstrap-packages"
if
{ using sys-fs/cryptsetup udev || using sys-fs/lvm2 udev && using sys-apps/systemd cryptsetup ; } ||
using sys-apps/systemd fido2 || using sys-apps/util-linux systemd
then
USE="-* python_single_target_$(portageq envvar PYTHON_SINGLE_TARGET)" \
emerge --oneshot --onlydeps{,-with-rdeps=n} --selective --verbose sys-apps/systemd
USE="-* python_single_target_$(portageq envvar PYTHON_SINGLE_TARGET)" \
emerge --oneshot --nodeps --selective --verbose sys-apps/systemd
fi
[[ -s $ROOT/etc/portage/sets/bootstrap-packages ]] &&
USE='-* drm minimal truetype' \
emerge --changed-use --oneshot --verbose @bootstrap-packages
# Cross-compile everything and make binary packages for the target.
emerge --changed-use --deep --update --verbose --with-bdeps=y \
"${packages[@]}" "${packages_sysroot[@]}" "$@"
# Without GDB, assume debuginfo is unwanted to be like other distros.
[[ -x $ROOT/usr/bin/gdb ]] && : ${options[debuginfo]=1}
opt debuginfo || local -rx INSTALL_MASK='/usr/lib/.build-id /usr/lib/debug /usr/share/gdb /usr/src'
# Install the target root from binaries with no build dependencies.
mkdir -p root/{dev,home,proc,srv,sys,usr/bin}
mkdir -pm 0700 root/root
ln -fns bin root/usr/sbin
ln -fst root usr/{bin,sbin}
ln -fns .. "root$ROOT" # Lazily work around bad packaging.
emerge --{,sys}root=root --jobs="$(nproc)" -1KOv sys-apps/baselayout
emerge --{,sys}root=root --jobs="$(nproc)" -1Kv "${packages[@]}" "$@"
mv -t root/usr/bin root/gcc-bin/*/* ; rm -fr root/{binutils,gcc}-bin
# Create a UTF-8 locale so things work.
mkdir -p root/usr/lib/locale
localedef --prefix=root -c -f UTF-8 -i en_US en_US.UTF-8
# If a modular unpackaged kernel was configured, install the modules.
opt raw_kernel && grep -Fqsx CONFIG_MODULES=y /usr/src/linux/.config &&
make -C /usr/src/linux modules_install \
INSTALL_MOD_PATH=/wd/root \
INSTALL_MOD_STRIP=$(opt debuginfo || echo 1) \
ARCH="$kernel_arch" CROSS_COMPILE="${options[host]}-" V=1
# List everything installed in the image and what was used to build it.
qlist -CIRSSUv > packages-sysroot.txt
qlist --root=/ -CIRSSUv > packages-buildroot.txt
qlist --root=root -CIRSSUv > packages.txt
}
function distro_tweaks() {
rm -fr root/etc/init.d root/etc/kernel
ln -fns ../lib/systemd/systemd root/usr/sbin/init
ln -fns ../proc/self/mounts root/etc/mtab
[[ -s root/etc/bash/bashrc ]] &&
sed -i -e 's/PS1+=..[[]/&\\033[01;33m\\]$? \\[/;/\$ .$/s/PS1+=./&$? /' root/etc/bash/bashrc
echo "alias ll='ls -l'" >> root/etc/skel/.bashrc
# Add a mount point to support the ESP mount generator.
opt uefi && mkdir -p root/boot
# Create some usual stuff in /var that is missing.
echo 'd /var/empty' > root/usr/lib/tmpfiles.d/var-compat.conf
[[ -s root/usr/lib/sysusers.d/acct-user-polkitd.conf ]] &&
echo 'd /var/lib/polkit-1 - polkitd polkitd' >> root/usr/lib/tmpfiles.d/polkit.conf
# Conditionalize wireless interfaces on their configuration files.
[[ -s root/usr/lib/systemd/system/[email protected] ]] &&
sed -i \
-e '/^\[Unit]/aConditionFileNotEmpty=/etc/wpa_supplicant/wpa_supplicant-nl80211-%I.conf' \
root/usr/lib/systemd/system/[email protected]
# The targeted policy does not support a sensitivity level.
[[ ${options[selinux]:-targeted} == targeted ]] &&
sed -i -e 's/t:s0/t/g' root/usr/lib/systemd/system/*.mount
# Perform case-insensitive searches in less by default.
[[ -s root/etc/env.d/70less ]] &&
sed -i -e '/^LESS=/s/[" ]*$/ -i&/' root/etc/env.d/70less
# Default to the nftables firewall interface if it was built.
ROOT=root eselect iptables list |& grep -Fqs xtables-nft-multi &&
ROOT=root eselect iptables set xtables-nft-multi
# Set some sensible key behaviors for a bare X session.
[[ -x root/usr/bin/startx ]] &&
mkdir -p root/etc/X11/xorg.conf.d &&
cat << 'EOF' > root/etc/X11/xorg.conf.d/00-keyboard.conf
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbOptions" "ctrl:nocaps"
EndSection
EOF
# Don't hijack key presses for searching in the web browser.
compgen -G 'root/usr/lib*/firefox/browser/defaults/preferences/gentoo-prefs.js' &&
sed -i -e /typeaheadfind/d root/usr/lib*/firefox/browser/defaults/preferences/gentoo-prefs.js
# Prioritize available daemons for the user audio service.
local daemon dir=root/usr/lib/systemd/user
for daemon in pipewire-pulse pulseaudio
do
if [[ -s $dir/$daemon.socket ]]
then
mkdir -p "$dir/sockets.target.wants"
ln -fst "$dir/sockets.target.wants" "../$daemon.socket"
break
fi
done
for daemon in wireplumber pipewire-media-session
do
if [[ -s $dir/$daemon.service ]]
then
mkdir -p "$dir/pipewire.service.wants"
ln -fst "$dir/pipewire.service.wants" "../$daemon.service"
break
fi
done
[[ -s $dir/pipewire.socket ]] &&
ln -fst "$dir/sockets.target.wants" ../pipewire.socket
# Select a default desktop environment for startx, or default to twm.
local wm ; for wm in Xfce4 wmaker
do
if [[ -s root/etc/X11/Sessions/$wm ]]
then
echo "XSESSION=$wm" > root/etc/env.d/90xsession
break
fi
done
# Magenta looks more "Gentoo" than green, as in the website and logo.
sed -i -e '/^ANSI_COLOR=/s/32/35/' root/etc/os-release
}
# Override ramdisk creation to drop microcode and support a builtin initramfs.
eval "$(declare -f squash | $sed \
-e 's/build_microcode_ramdisk/:/' \
-e 's/zstd --[^;]*/if opt monolithic ; then cat > /root/initramfs.cpio ; else & ; fi/')"
function save_boot_files() if opt bootable
then
local -rx {PORTAGE_CONFIG,,SYS}ROOT="/usr/${options[host]}"
opt uefi && USE='boot kernel-install' emerge --buildpkg=n --changed-use --oneshot --verbose sys-apps/systemd
opt uefi && [[ ! -s logo.bmp ]] &&
sed '/namedview/,/<.g>/d' /usr/share/pixmaps/gentoo/misc/svg/GentooWallpaper_2.svg > /root/logo.svg &&
magick -background none /root/logo.svg -trim logo.bmp
[[ -s $(opt monolithic && echo /root/initramfs.cpio || echo initrd.img) ]] || build_busybox_initrd
opt monolithic && if opt raw_kernel
then cat >> /usr/src/linux/.config
else cat >> /etc/kernel/config.d/monolithic.config
fi << EOF
CONFIG_CMDLINE="$(sed 's/["\]/\\&/g' kernel_args.txt)"
CONFIG_CMDLINE_FORCE=y
CONFIG_INITRAMFS_COMPRESSION_ZSTD=y
CONFIG_INITRAMFS_FORCE=y
$([[ -s /root/initramfs.cpio ]] || echo '#')CONFIG_INITRAMFS_SOURCE="/root/initramfs.cpio"
EOF
create_ipe_policy
local -r arch="$(archmap_kernel "${options[arch]}")"
[[ -s vmlinux || -s vmlinuz ]] || if opt raw_kernel
then
if opt ipe || opt monolithic
then
make -C /usr/src/linux -j"$(nproc)" olddefconfig \
ARCH="$arch" CROSS_COMPILE="${options[host]}-" V=1
make -C /usr/src/linux -j"$(nproc)" \
ARCH="$arch" CROSS_COMPILE="${options[host]}-" V=1
fi
make -C /usr/src/linux install \
ARCH="$arch" CROSS_COMPILE="${options[host]}-" V=1
cp -p /boot/vmlinux-* vmlinux || cp -p /boot/vmlinuz-* vmlinuz
else
if opt ipe || opt monolithic
then
chgrp portage /root ; chmod g+x /root
emerge --buildpkg=n --oneshot --verbose \
sys-kernel/gentoo-kernel
chgrp root /root ; chmod g-x /root
fi
local -r bd="$ROOT/usr/src/linux/arch/$arch/boot"
[[ -s $bd/Image.gz ]] && gzip -cd "$bd/Image.gz" > vmlinux ||
cp -p "$bd"/*Image* vmlinuz
fi < /dev/null
fi
# Override the UEFI function to support non-native stub files in Gentoo.
eval "$(declare -f produce_uefi_exe | $sed \
-e 's/objcopy\|objdump/"${options[host]}-&"/' \
-e 's,/[^ ]*.efi.stub,/usr/${options[host]}&,')"
# Override default OVMF paths for this distro's packaging.
eval "$(declare -f set_uefi_variables | $sed \
-e 's,/usr/\S*VARS\S*.fd,/usr/share/edk2-ovmf/OVMF_VARS.fd,' \
-e 's,/usr/\S*CODE\S*.fd,/usr/share/edk2-ovmf/OVMF_CODE.secboot.fd,' \
-e 's,/usr/\S*/\(Shell\|EnrollDefaultKeys\).efi,/usr/share/edk2-ovmf/\1.efi,g')"
function create_ipe_policy() if opt ipe
then
if opt monolithic
then local -r initrd=/root/initramfs.cpio
else local -r initrd=initrd.img
fi
# Make the default policy a whitelist based on enabled options.
[[ -s ipe.policy ]] || {
cat << EOF
policy_name="default" policy_version=0.0.0
DEFAULT action=DENY
EOF
if [[ -s $initrd ]]
then
echo op=EXECUTE boot_verified=TRUE action=ALLOW
echo op=KERNEL_READ boot_verified=TRUE action=ALLOW
fi
if opt verity_sig
then
echo op=EXECUTE dmverity_signature=TRUE action=ALLOW
echo op=KERNEL_READ dmverity_signature=TRUE action=ALLOW
elif opt verity
then
local -r roothash=$(mapfile -d ' ' < dmsetup.txt && echo ${MAPFILE[11]})
echo op=EXECUTE dmverity_roothash="$roothash" action=ALLOW
echo op=KERNEL_READ dmverity_roothash="$roothash" action=ALLOW
fi
} > ipe.policy
# Update the kernel configuration to include the policy.
if opt raw_kernel
then cat >> /usr/src/linux/.config
else cat >> /etc/kernel/config.d/ipe.config
fi << EOF
CONFIG_IPE_BOOT_POLICY="/wd/ipe.policy"
$([[ -s $initrd ]] || echo '#')CONFIG_IPE_PROP_BOOT_VERIFIED=y
EOF
fi
function build_busybox_initrd() if opt ramdisk || opt verity_sig
then
local -r root=$(mktemp --directory --tmpdir="$PWD" ramdisk.XXXXXXXXXX)
mkdir -p "$root"/{bin,dev,proc,sys,sysroot}
# Cross-compile minimal static tools required for the initrd.
local -rx {PORTAGE_CONFIG,,SYS}ROOT="/usr/${options[host]}"
opt verity && USE=static-libs \
emerge --buildpkg=n --changed-use --oneshot --verbose \
dev-libs/libaio sys-apps/util-linux virtual/libcrypt
USE='-* static' \
emerge --buildpkg=n --nodeps --oneshot --verbose \
sys-apps/busybox \
${options[verity]:+sys-fs/lvm2} \
${options[verity_sig]:+sys-apps/keyutils}
# Import the cross-compiled tools into the initrd root.
cp -pt "$root/bin" "$ROOT/bin/busybox"
local cmd ; for cmd in ash cat losetup mount mountpoint sleep switch_root
do ln -fns busybox "$root/bin/$cmd"
done
opt verity && cp -p "$ROOT/sbin/dmsetup.static" "$root/bin/dmsetup"
opt verity_sig && cp -pt "$root/bin" "$ROOT/bin/keyctl"
# Write an init script and include required build artifacts.
cat << EOF > "$root/init" ; chmod 0755 "$root/init"
#!/bin/ash -eux
export PATH=/bin
mountpoint -q /dev || mount -nt devtmpfs devtmpfs /dev
mountpoint -q /proc || mount -nt proc proc /proc
mountpoint -q /sys || mount -nt sysfs sysfs /sys
$(opt ramdisk && echo "losetup ${options[read_only]:+-r }/dev/loop0 /root.img"
opt verity_sig && echo 'keyctl padd user verity:root @u < /verity.sig'
opt verity && cat << 'EOG' ||
dmv=" $(cat /proc/cmdline) "
dmv=${dmv##* \"DVR=} ; dmv=${dmv##* DVR=\"} ; dmv=${dmv%%\"*}
for attempt in 1 2 3 4 0
do dmsetup create --concise "$dmv" && break || sleep "$attempt"
done
mount -no ro /dev/mapper/root /sysroot
EOG
echo "mount -n${options[read_only]:+o ro} /dev/loop0 /sysroot")
exec switch_root /sysroot /sbin/init
EOF
opt ramdisk && ln -fn final.img "$root/root.img"
opt verity_sig && ln -ft "$root" verity.sig
# Build the initrd.
find "$root" -mindepth 1 -printf '%P\n' |
cpio -D "$root" -H newc -R 0:0 -o |
if opt monolithic
then cat > /root/initramfs.cpio
else zstd --threads=0 --ultra -22 > initrd.img
fi
fi
function write_unconditional_patches() {
local -r patches="$1"
$mkdir -p "$patches/app-arch/snappy-1.1.10"
$cat << 'EOF' > "$patches/app-arch/snappy-1.1.10/neon.patch"
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -207,9 +207,9 @@
check_cxx_source_compiles("
#include <arm_neon.h>
int main() {
- uint8_t val = 3, dup[8];
+ uint8_t val = 3;
uint8x16_t v = vld1q_dup_u8(&val);
- vst1q_u8(dup, v);
+ val = vmaxvq_u8(v);
return 0;
}" SNAPPY_HAVE_NEON)
EOF
$mkdir -p "$patches"/{dev-lang/spidermonkey,www-client/firefox}
$ln -fst "$patches/dev-lang/spidermonkey" ../../www-client/firefox/rust.patch
$cat << 'EOF' > "$patches/www-client/firefox/rust.patch"
--- a/build/moz.configure/rust.configure
+++ b/build/moz.configure/rust.configure
@@ -491,12 +491,13 @@
rustc, target, c_compiler, rust_supported_targets, arm_target, when=rust_compiler
)
@checking("for rust target triplet")
+@imports('os')
def rust_target_triple(
rustc, target, compiler_info, rust_supported_targets, arm_target
):
- rustc_target = detect_rustc_target(
+ rustc_target = os.getenv('RUST_TARGET', detect_rustc_target(
target, compiler_info, arm_target, rust_supported_targets
- )
+ ))
assert_rust_compile(target, rustc_target, rustc)
return rustc_target
EOF
$mkdir -p "$patches/net-misc/networkmanager"
$cat << 'EOF' > "$patches/net-misc/networkmanager/cross.patch"
--- a/meson.build
+++ b/meson.build
@@ -248,7 +248,7 @@
dbus_dep = dependency('dbus-1', version: '>= 1.1')
libndp_dep = dependency('libndp')
-jansson_dep = dependency('jansson', version: '>= 2.7', required: false)
+jansson_dep = disabler()
config_h.set10('WITH_JANSSON', jansson_dep.found())
jansson_msg = 'no'
EOF
}
function write_base_kernel_config() if opt bootable
then
$mkdir -p "$buildroot/etc/kernel/config.d"
{
echo '# Basic settings
CONFIG_ACPI=y
CONFIG_BASE_FULL=y
CONFIG_BLOCK=y
CONFIG_EXPERT=y
CONFIG_JUMP_LABEL=y
CONFIG_KERNEL_'$([[ ${options[arch]} == *[3-6x]86* ]] && echo ZSTD || echo XZ)'=y
CONFIG_MULTIUSER=y
CONFIG_SHMEM=y
CONFIG_UNIX=y
# File system settings
CONFIG_DEVTMPFS=y
CONFIG_PROC_FS=y
CONFIG_SYSFS=y
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
# Executable settings
CONFIG_BINFMT_ELF=y
CONFIG_BINFMT_SCRIPT=y
# Security settings
CONFIG_BPF_JIT=y
CONFIG_BPF_JIT_ALWAYS_ON=y
CONFIG_DEVTMPFS_SAFE=y
CONFIG_FORTIFY_SOURCE=y
CONFIG_HARDEN_BRANCH_PREDICTOR=y
CONFIG_HARDENED_USERCOPY=y
CONFIG_LOCK_DOWN_KERNEL_FORCE_CONFIDENTIALITY=y
CONFIG_RANDOMIZE_BASE=y
CONFIG_RANDOMIZE_KSTACK_OFFSET=y
CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=y
CONFIG_RANDOMIZE_MEMORY=y
CONFIG_RELOCATABLE=y
CONFIG_RETPOLINE=y
CONFIG_SECURITY_DMESG_RESTRICT=y
CONFIG_SECURITY_LOCKDOWN_LSM=y
CONFIG_SECURITY_LOCKDOWN_LSM_EARLY=y
CONFIG_STACKPROTECTOR=y
CONFIG_STACKPROTECTOR_STRONG=y
CONFIG_STRICT_KERNEL_RWX=y
CONFIG_VMAP_STACK=y
# Signing settings
CONFIG_KEXEC_SIG=y
CONFIG_KEXEC_SIG_FORCE=y
CONFIG_MODULE_COMPRESS_'$(opt loadpin && echo NONE || echo ZSTD)'=y
CONFIG_MODULE_SIG=y
CONFIG_MODULE_SIG_ALL=y
CONFIG_MODULE_SIG_FORCE=y
CONFIG_MODULE_SIG_SHA512=y'
[[ ${options[arch]} == *64* ]] && echo '# Architecture settings
CONFIG_64BIT=y'
[[ ${options[arch]} == x86_64 ]] && echo 'CONFIG_SMP=y
CONFIG_X86_LOCAL_APIC=y' &&
[[ ${options[host]} == *x32 ]] && echo CONFIG_X86_X32_ABI=y
opt ipe && { echo -n '# IPE settings
CONFIG_SECURITY=y
CONFIG_SECURITYFS=y
CONFIG_SECURITY_IPE=y
CONFIG_IPE_AUDIT_HASH_SHA512=y' ; opt ramdisk || opt verity_sig && echo -n '
CONFIG_IPE_PROP_BOOT_VERIFIED=y' ; opt verity && echo -n '
CONFIG_IPE_PROP_DM_VERITY_ROOTHASH=y' ; opt verity_sig && echo -n '
CONFIG_IPE_PROP_DM_VERITY_SIGNATURE=y' ; echo ; }
opt loadpin && { echo -n '# LoadPin settings
CONFIG_SECURITY=y
CONFIG_SECURITY_LOADPIN=y
CONFIG_SECURITY_LOADPIN_ENFORCE=y' ; opt verity && echo -n '
CONFIG_SECURITYFS=y
CONFIG_SECURITY_LOADPIN_VERITY=y' ; echo ; }
opt networkd && echo '# Network settings
CONFIG_NET=y
CONFIG_INET=y
CONFIG_IPV6=y
CONFIG_PACKET=y'
opt ramdisk || opt verity_sig && echo '# Initrd settings
CONFIG_BLK_DEV_INITRD=y
CONFIG_RD_ZSTD=y'
opt ramdisk && echo '# Loop settings
CONFIG_BLK_DEV=y
CONFIG_BLK_DEV_LOOP=y
CONFIG_BLK_DEV_LOOP_MIN_COUNT=1' || echo '# Loop settings
CONFIG_BLK_DEV_LOOP_MIN_COUNT=0'
opt read_only && echo '# Overlay settings
CONFIG_OVERLAY_FS=y'
[[ " ${options[rootmod]-} " == *' nvme '* ]] && echo '# NVMe settings
CONFIG_PCI=y
CONFIG_BLK_DEV_NVME=y'
opt selinux && echo '# SELinux settings
CONFIG_AUDIT=y
CONFIG_SECURITY=y
CONFIG_SECURITY_NETWORK=y
CONFIG_SECURITY_SELINUX=y
CONFIG_SECURITY_SELINUX_DEVELOP=y # XXX: Start permissive.
CONFIG_SECURITY_SELINUX_BOOTPARAM=y # XXX: Support toggling at boot to test.'
opt squash && echo '# Squashfs settings
CONFIG_MISC_FILESYSTEMS=y
CONFIG_SQUASHFS=y
CONFIG_SQUASHFS_FILE_DIRECT=y
CONFIG_SQUASHFS_DECOMP_MULTI=y
CONFIG_SQUASHFS_XATTR=y
CONFIG_SQUASHFS_ZSTD=y' || { opt read_only && echo '# EROFS settings
CONFIG_MISC_FILESYSTEMS=y
CONFIG_EROFS_FS=y
CONFIG_EROFS_FS_XATTR=y
CONFIG_EROFS_FS_POSIX_ACL=y
CONFIG_EROFS_FS_SECURITY=y' ; } || echo '# Ext[2-4] settings
CONFIG_EXT4_FS=y
CONFIG_EXT4_FS_POSIX_ACL=y