-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprovision-initial-layout.yml
3053 lines (2827 loc) · 89.6 KB
/
provision-initial-layout.yml
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
# https://gentoo.duxsco.de/
# https://gentoo.duxsco.de/bootup_setup/
# https://gentoo.duxsco.de/unified_kernel_image/
# https://wiki.archlinux.org/title/EFI_system_partition#Mount_the_partition
# https://cryptsetup-team.pages.debian.net/cryptsetup/README.keyctl.html doesn't work
# https://unix.stackexchange.com/a/752355/27133
# https://wiki.archlinux.org/title/Dm-crypt/System_configuration#Using_systemd-cryptsetup-generator
# https://wiki.archlinux.org/title/Dm-crypt/System_configuration#crypttab
# https://man.archlinux.org/man/crypttab.5
# https://wiki.archlinux.org/title/Dm-crypt/System_configuration#Mounting_at_boot_time
# https://wiki.archlinux.org/title/Dm-crypt/System_configuration#Mounting_on_demand
# https://man.archlinux.org/man/systemd-cryptsetup.8
# https://wiki.archlinux.org/title/Dm-crypt/Encrypting_an_entire_system#Avoiding_having_to_enter_the_passphrase_twice
# https://wiki.archlinux.org/title/Dm-crypt/Swap_encryption#With_suspend-to-disk_support
# https://uapi-group.org/specifications/specs/discoverable_partitions_specification/
# https://swsnr.de/arch-linux-with-luks-and-almost-no-configuration/
# https://swsnr.de/simple-secure-boot-in-fedora/
# https://swsnr.de/unlock-luks-rootfs-with-tpm2-key/
# https://wiki.gentoo.org/wiki/Full_Disk_Encryption_From_Scratch
# https://wiki.archlinux.org/title/Dracut
# https://wiki.archlinux.org/title/Dm-crypt/System_configuration
# https://wiki.archlinux.org/title/Dm-crypt/Specialties#Discard/TRIM_support_for_solid_state_drives_(SSD)
# http://jpetazzo.github.io/2024/02/23/archlinux-luks-tpm-secureboot-install/
# https://0pointer.net/blog/authenticated-boot-and-disk-encryption-on-linux.html
# https://wiki.archlinux.org/title/Trusted_Platform_Module#systemd-cryptenroll
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Kernel#Secure_Boot
# https://wiki.gentoo.org/wiki/Systemd/systemd-boot
# https://wiki.gentoo.org/wiki/NetworkManager
# https://wiki.archlinux.org/title/Laptop/Lenovo
# https://wiki.gentoo.org/wiki/Lenovo_ThinkPad_P16v_1st_Generation_(Intel)
# https://wiki.gentoo.org/wiki/Lenovo_ThinkPad_Z16_(Gen_1)
# https://wiki.archlinux.org/title/Lenovo_ThinkPad_P16s_(AMD)_Gen_2
# https://linux-hardware.org/?id=cpu:amd-25-116-1-ryzen-9-pro-7940hs-w-radeon-780m-graphics
# https://wiki.gentoo.org/wiki/Suspend_and_hibernate
# https://wiki.archlinux.org/title/Dm-crypt/System_configuration
# https://wiki.gentoo.org/wiki/Systemd
# https://www.freedesktop.org/software/systemd/man/latest/crypttab.html
# https://wiki.gentoo.org/wiki/WireGuard
# https://wiki.gentoo.org/wiki/Trusted_Platform_Module
# https://wiki.gentoo.org/wiki/AMDGPU
# https://wiki.gentoo.org/wiki/Plymouth
# https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers
# https://wiki.gentoo.org/wiki/NVIDIA/Optimus
# https://wiki.gentoo.org/wiki/NVIDIA/Bumblebee
# https://wiki.gentoo.org/wiki/NVIDIA/Optimus/xorg.conf
# https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers#Open_source_kernel_modules
# https://github.com/NVIDIA/open-gpu-kernel-modules
# https://github.com/dracut-ng/dracut-ng/wiki
# https://wiki.gentoo.org/wiki/Systemd/systemd-boot#Secure_Boot
# https://uapi-group.org/specifications/specs/boot_loader_specification/
# https://wiki.gentoo.org/wiki/Efivarfs
# https://wiki.archlinux.org/title/Systemd-boot
# https://wiki.gentoo.org/wiki/Installkernel
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Kernel
# https://wiki.gentoo.org/wiki/Rootfs_encryption
# https://github.com/jhatler/gentoo-precision-7540/commit/71f1320ffc85666114003a2446112f41d7403d30
# https://wiki.gentoo.org/wiki/Dracut
# https://wiki.gentoo.org/wiki/Signed_kernel_module_support
# https://wiki.gentoo.org/wiki/Shim
# https://wiki.gentoo.org/wiki/Zram
# https://wiki.gentoo.org/wiki/Zswap
# https://matt-w.net/blog/luks-arch-secureboot/
# https://wiki.gentoo.org/wiki/LVM#Dracut
# https://wiki.gentoo.org/wiki/Secure_Boot
# https://wiki.gentoo.org/wiki/Security_Handbook/Boot_Path_Security
# https://wiki.archlinux.org/title/Systemd-cryptenroll
# https://wiki.gentoo.org/wiki/NetworkManager
# https://discourse.nixos.org/t/gtkgreet-or-regreeter-with-greetd-with-hyprland/29202
# https://gist.github.com/noghartt/8388f7d8543e3eb1777cb6ed4a3d7807
# https://github.com/Foxboron/sbctl
# https://gist.github.com/orhun/02102b3af3acfdaf9a5a2164bea7c3d6
# https://wiki.archlinux.org/title/Unified_Extensible_Firmware_Interface/Secure_Boot
# https://wiki.archlinux.org/title/Systemd-boot#Signing_for_Secure_Boot
# https://wiki.archlinux.org/title/Unified_Extensible_Firmware_Interface/Secure_Boot#Using_a_signed_boot_loader
# https://amedeos.github.io/gentoo/2020/12/26/install-gentoo-with-uefi-luks-btrfs-and-systemd.html
# https://wiki.gentoo.org/wiki/SSD
# https://wiki.gentoo.org/wiki/Hyprpaper
# https://wiki.hyprland.org/Useful-Utilities/Screen-Sharing/
# https://wiki.hyprland.org/Configuring/Variables/
# https://wiki.hyprland.org/Configuring/Monitors/
# https://wiki.hyprland.org/Configuring/Tearing/
# https://wiki.hyprland.org/Nvidia/
# https://wiki.hyprland.org/hyprland-wiki/pages/Nvidia/
# https://wiki.hyprland.org/Configuring/Uncommon-tips--tricks/
# https://wiki.hyprland.org/Configuring/XWayland/
# https://wiki.hyprland.org/Configuring/Environment-variables/
# https://wiki.hyprland.org/Configuring/Multi-GPU/
# https://wiki.gentoo.org/wiki/Recommended_applications#File_managerso
# https://www.reddit.com/r/hyprland/comments/17nvgw1/what_set_of_apps_do_you_use_with_hyprland_for/
# https://wiki.archlinux.org/title/Hyprland
# https://www.lorenzobettini.it/2024/02/hyprland-and-kde-applications/
# https://wiki.gentoo.org/wiki/Recommended_applications#3D
# https://github.com/coffeeispower/woomer
# https://github.com/fwupd/fwupd/wiki/Blocked-executable-in-the-ESP,-ensure-grub-and-shim-are-up-to-date
# https://askubuntu.com/a/1436957
# https://github.com/fwupd/fwupd/issues/5121
# https://www.setphaserstostun.org/posts/secure-boot-on-gentoo-with-shim-grub/#gentoo-binary-distribution-kernel
# https://wiki.gentoo.org/wiki/Project:Distribution_Kernel
# https://github.com/jlaunonen/gentoo-uefi-secure
# https://github.com/lateralblast/ansible-lvm-luks
# https://psref.lenovo.com/syspool/Sys/PDF/ThinkPad/ThinkPad_P16v_Gen_1_AMD/ThinkPad_P16v_Gen_1_AMD_Spec.pdf
# https://wiki.gentoo.org/wiki/Lenovo_ThinkPad_P16v_1st_Generation_(AMD)
# https://www.reddit.com/r/linux/comments/1c63fgz/latest_update_of_chrome_on_wayland/
# https://wiki.gentoo.org/wiki/Chrome#Using_Wayland_backend
# https://wiki.archlinux.org/title/Chromium#Native_Wayland_support
# https://bbs.archlinux.org/viewtopic.php?id=288181
# https://download.nvidia.com/XFree86/Linux-x86_64/435.17/README/powermanagement.html
# https://gist.github.com/bmcbm/375f14eaa17f88756b4bdbbebbcfd029
# https://forums.gentoo.org/viewtopic-p-8840967.html?sid=9bd8b468db1268652c937a36fcaf9011
# https://forums.gentoo.org/viewtopic-p-8811468.html?sid=4314228234fb7b9ff69dc764ebfc01f5
# https://wiki.archlinux.org/title/Wayland#Electron
# https://github.com/JaKooLit/Hyprland-Dots
# https://swayos.github.io
# https://www.reddit.com/r/swaywm/comments/16u89ep/pure_wayland_gui_file_manager/
# https://wiki.hyprland.org/Useful-Utilities/File-Managers/
# https://wiki.gentoo.org/wiki/File_managers
# https://wiki.hyprland.org/Useful-Utilities/Must-have/
# https://wiki.hyprland.org/Useful-Utilities/
# https://wiki.hyprland.org/Hypr-Ecosystem/xdg-desktop-portal-hyprland/
# https://wiki.hyprland.org/Hypr-Ecosystem/hyprlock/
# https://wiki.hyprland.org/Hypr-Ecosystem/hypridle/
# https://systemd.io/INHIBITOR_LOCKS/
# https://man.archlinux.org/man/systemd-inhibit.1.en
# https://forums.gentoo.org/viewtopic-t-1045730-start-0.html
# https://codeberg.org/dnkl/yambar/src/branch/master/examples/configurations/laptop.conf
# https://codeberg.org/dnkl/yambar/src/branch/master/examples/configurations/river-tags.conf
# https://codeberg.org/dnkl/yambar
# https://wiki.gentoo.org/wiki/List_of_software_for_Wayland#Multiple_display_configuration
# https://github.com/hyprwm/hyprlock
# https://github.com/hyprland-community/awesome-hyprland
# https://wiki.archlinux.org/title/Desktop_entries
# https://wiki.gentoo.org/wiki/Hyprland#xdg-desktop-portal-hyprland
# https://wiki.gentoo.org/wiki/NetworkManager#Dnsmasq
# https://wiki.ubuntu.com/DebuggingNetworkManager
# https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/introduction-to-networkmanager-debugging_configuring-and-managing-networking#introduction-to-networkmanager-reapply-method_introduction-to-networkmanager-debugging
#
# NOTE: A new GPT label must be created when repartitioning disks with LUKS
# fdisk -> g -> w
---
- name: Initialize Gentoo Linux layout
hosts: laptop
gather_facts: true
become: yes
vars:
gentoo_prefix: /mnt/gentoo
lvm_volume_group: lvm-on-luks
vars_prompt:
- name: luks_password
private: true
prompt: Enter the LUKS password
- name: machine_id
private: false
prompt: Enter the machine-id value
tasks:
- name: Detect NVME drives
set_fact:
nvme_devices: >-
{{
ansible_devices
| dict2items
| rejectattr('value.removable', 'eq', '1')
| rejectattr('value.rotational', 'eq', '1')
| selectattr('key', 'match', 'nvme[0-9]+n[0-9]+')
| sort(attribute='value.sectors')
}}
- name: Set individual NVME drive variables
set_fact:
nvme_1tb_disk: >-
{{ (nvme_devices | first).key }}
nvme_2tb_disk: >-
{{ (nvme_devices | last).key }}
- name: Set privileges for the shared memory devices
ansible.builtin.file:
force: true
mode: 1777
path: >-
{{ mount_point }}
state: directory
loop:
- /dev/shm
- /run/shm
loop_control:
loop_var: mount_point
- name: Set the block device variables
set_fact:
rootfs_dev: /dev/{{ lvm_volume_group }}/rootfs
homefs_dev: /dev/{{ lvm_volume_group }}/homefs
swap_dev: /dev/{{ lvm_volume_group }}/swap
efifs_dev: /dev/{{ nvme_2tb_disk }}p1
- name: Stop the dirmngr daemon from the previous run
ansible.builtin.command:
argv:
- killall
- dirmngr
failed_when: false
- name: Unmount any mounted in-chroot file systems
ansible.builtin.command:
argv:
- umount
- --recursive
- >-
{{ gentoo_prefix }}
when: >-
ansible_mounts
| selectattr(
'mount',
'eq',
gentoo_prefix
)
| length
- name: Unmount swap on LUKS
ansible.builtin.command:
argv:
- swapoff
- >-
{{ swap_dev }}
failed_when: false
- name: Set the LUKS device path vars
set_fact:
first_nvme_disk_luks_dev: >-
/dev/{{ nvme_2tb_disk }}p2
second_nvme_disk_luks_dev: >-
/dev/{{ nvme_1tb_disk }}p1
- name: Ensure LUKS devices sealed if they exist
community.crypto.luks_device:
device: >-
{{ device_path }}
name: >-
decrypted-luks-{{ luks_container_index }}
state: closed
failed_when: false
loop:
- >-
{{ first_nvme_disk_luks_dev }}
- >-
{{ second_nvme_disk_luks_dev }}
loop_control:
loop_var: device_path
index_var: luks_container_index
- name: Refresh the facts gathered from the host
ansible.builtin.gather_facts:
- name: Create an EFI partition
community.general.parted:
device: >-
{{ device_path }}
flags:
- esp
fs_type: fat32
label: gpt
name: unencrypted-efi-on-2tb-nvme
number: 1
part_end: 1GiB
state: present
# state: absent
unit: GiB
vars:
device_path: /dev/{{ nvme_2tb_disk }}
- name: Create a LUKS partition on 2 TB disk
community.general.parted:
device: >-
{{ device_path }}
label: gpt
name: luks-on-2tb-nvme
number: 2
part_start: 1GiB
part_end: 100%
state: present
# state: absent
unit: GiB
vars:
device_path: /dev/{{ nvme_2tb_disk }}
- name: Create a LUKS partition on 1 TB disk
community.general.parted:
device: >-
{{ device_path }}
label: gpt
name: luks-on-1tb-nvme
number: 1
part_start: 0%
part_end: 100%
state: present
# state: absent
unit: GiB
vars:
device_path: /dev/{{ nvme_1tb_disk }}
- name: Initialize LUKS partitions
community.crypto.luks_device:
allow_discards: true # TRIM: https://wiki.gentoo.org/wiki/SSD
cipher: aes-cbc-essiv:sha256
device: >-
{{ device_path }}
passphrase: >-
{{ luks_password }}
pbkdf:
algorithm: argon2id
parallel: >- # ThinkPad P16v has 16 cores
{{ ansible_processor_nproc | int + 1 }}
persistent: true
state: present
# state: absent
type: luks2
loop:
- >-
{{ first_nvme_disk_luks_dev }}
- >-
{{ second_nvme_disk_luks_dev }}
loop_control:
loop_var: device_path
- name: Retrieve the 2tb disk LUKS UUID
ansible.builtin.command:
argv:
- cryptsetup
- luksUUID
- >-
{{ first_nvme_disk_luks_dev }}
register: cryptsetup_2tb_uuid_cmd
- name: Save the 2tb disk LUKS UUID
set_fact:
first_luks_dev_uuid: >-
{{ cryptsetup_2tb_uuid_cmd.stdout | trim }}
- name: Retrieve the 1tb disk LUKS UUID
ansible.builtin.command:
argv:
- cryptsetup
- luksUUID
- >-
{{ second_nvme_disk_luks_dev }}
register: cryptsetup_1tb_uuid_cmd
- name: Save the 1tb disk LUKS UUID
set_fact:
second_luks_dev_uuid: >-
{{ cryptsetup_1tb_uuid_cmd.stdout | trim }}
- name: Unseal LUKS partitions
community.crypto.luks_device:
allow_discards: true # TRIM: https://wiki.gentoo.org/wiki/SSD
device: >-
{{ device_path }}
name: >-
decrypted-luks-{{ luks_container_index }}
passphrase: >-
{{ luks_password }}
state: opened
loop:
- >-
{{ first_nvme_disk_luks_dev }}
- >-
{{ second_nvme_disk_luks_dev }}
loop_control:
loop_var: device_path
index_var: luks_container_index
- name: Add unsealed LUKS partition to LVM volume group
community.general.lvg:
pvs:
- /dev/mapper/decrypted-luks-0
- /dev/mapper/decrypted-luks-1
state: present
vg: >-
{{ lvm_volume_group }}
- name: Create a root LVM partition
community.general.lvol:
active: true
lv: rootfs
size: 150G
shrink: false
state: present
vg: >-
{{ lvm_volume_group }}
- name: Create a home LVM partition
community.general.lvol:
active: true
lv: homefs
size: 350G
shrink: false
state: present
vg: >-
{{ lvm_volume_group }}
- name: Create a SWAP LVM partition
community.general.lvol:
active: true
lv: swap
size: 64G
shrink: false
state: present
vg: >-
{{ lvm_volume_group }}
- name: Make a SWAP filesystem
community.general.filesystem:
dev: >-
{{ swap_dev }}
fstype: swap
- name: Retrieve the swap dev UUID
ansible.builtin.command:
argv:
- blkid
- --match-tag
- UUID
- --output
- value
- >-
{{ swap_dev }}
register: swap_dev_blkid_cmd
- name: Save the swap dev UUID
set_fact:
swap_dev_uuid: >-
{{ swap_dev_blkid_cmd.stdout | trim }}
- name: Make an EFI filesystem
community.general.filesystem:
dev: >-
{{ efifs_dev }}
# force: true
fstype: vfat # EFI
- name: Make home and root filesystems
community.general.filesystem:
dev: >-
{{ device_path }}
# force: true
fstype: xfs # https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Disks#Filesystems
loop:
- >-
{{ rootfs_dev }}
- >-
{{ homefs_dev }}
loop_control:
loop_var: device_path
- name: Retrieve the efi dev UUID
ansible.builtin.command:
argv:
- blkid
- --match-tag
- UUID
- --output
- value
- >-
{{ efifs_dev }}
register: efifs_dev_blkid_cmd
- name: Save the efifs dev UUID
set_fact:
efifs_dev_uuid: >-
{{ efifs_dev_blkid_cmd.stdout | trim }}
- name: Retrieve the rootfs dev UUID
ansible.builtin.command:
argv:
- blkid
- --match-tag
- UUID
- --output
- value
- >-
{{ rootfs_dev }}
register: rootfs_dev_blkid_cmd
- name: Save the rootfs dev UUID
set_fact:
rootfs_dev_uuid: >-
{{ rootfs_dev_blkid_cmd.stdout | trim }}
- name: Retrieve the homefs dev UUID
ansible.builtin.command:
argv:
- blkid
- --match-tag
- UUID
- --output
- value
- >-
{{ homefs_dev }}
register: homefs_dev_blkid_cmd
- name: Save the homefs dev UUID
set_fact:
homefs_dev_uuid: >-
{{ homefs_dev_blkid_cmd.stdout | trim }}
# https://github.com/ansible-collections/ansible.posix/issues/106
# - ansible.posix.mount:
# fstype: swap
# opts: auto,sw,lazytime
# path: none
# src: >-
# {{ swap_dev }}
# state: ephemeral # mount but don't amend /etc/fstab
- name: Activate swap
ansible.builtin.command:
argv:
- swapon
- >-
{{ swap_dev }}
failed_when: false
- name: Mount {{ rootfs_dev }} @ {{ gentoo_prefix }}
ansible.posix.mount:
fstype: xfs
opts: auto,rw,lazytime
path: >-
{{ gentoo_prefix }}
src: >-
{{ rootfs_dev }}
state: ephemeral # mount but don't amend /etc/fstab
- name: Mount {{ efifs_dev }} @ {{ gentoo_prefix }}/efi
ansible.posix.mount:
fstype: vfat
opts: >-
auto,defaults,discard,rw,lazytime,uid=0,gid=0,umask=0077,x-systemd.automount,x-systemd.idle-timeout=600,errors=remount-ro
path: >-
{{ gentoo_prefix }}/efi
src: >-
{{ efifs_dev }}
state: ephemeral # mount but don't amend /etc/fstab
- name: Mount {{ homefs_dev }} @ {{ gentoo_prefix }}/home
ansible.posix.mount:
fstype: xfs
opts: auto,rw,lazytime
path: >-
{{ gentoo_prefix }}/home
src: >-
{{ homefs_dev }}
state: ephemeral # mount but don't amend /etc/fstab
- name: Refresh the facts gathered from the host
ansible.builtin.gather_facts:
# - community.crypto.openssl_signature_info_module:
- name: Download the latest stage3 metadata
ansible.builtin.uri:
return_content: true
url: https://ftp.fi.muni.cz/pub/linux/gentoo/releases/amd64/autobuilds/latest-stage3-amd64-desktop-systemd.txt
register: latest_stage3_data
- name: Compose the latest stage3 URL
set_fact:
latest_stage3_url: >-
https://ftp.fi.muni.cz/pub/linux/gentoo/releases/amd64/autobuilds/{{
(
latest_stage3_data.content
| ansible.builtin.split('-----BEGIN PGP SIGNATURE-----')
| first
| trim
| ansible.builtin.split
)[-2]
}}
- name: Compose the latest stage3 SHA-256 hash file URL
set_fact:
latest_stage3_sha256_url: >-
{{ latest_stage3_url }}.sha256
- name: Retrieve the latest stage3 metadata
ansible.builtin.uri:
return_content: true
url: >-
{{ latest_stage3_sha256_url }}
register: latest_stage3_sha256_data
- name: Compose the latest stage3 SHA-256 hash value
set_fact:
latest_stage3_sha256_hash: >-
{{
(
latest_stage3_sha256_data.content
| ansible.builtin.split('-----BEGIN PGP SIGNATURE-----')
| first
| trim
| ansible.builtin.split
)[-2]
}}
- name: Inspect the unpacked stage3 layout in chroot
ansible.builtin.stat:
path: >-
{{ gentoo_prefix }}/var/tmp
register: var_tmp_stat_data
- name: Download the latest stage3 archive
ansible.builtin.get_url:
checksum: >-
sha256:{{ latest_stage3_sha256_hash }}
dest: /tmp
url: >-
{{ latest_stage3_url }}
register: latest_stage3
when: not var_tmp_stat_data.stat.exists
# this probably doesn't preserve all the args
# - ansible.builtin.unarchive:
# dest: >-
# {{ gentoo_prefix }}
# remote_src: true
# src: >-
# {{ latest_stage3.dest }}
# when: not var_tmp_stat_data.stat.exists
- name: Unpack Gentoo stage3 base file system layout
ansible.builtin.command:
argv:
- tar
- xpvf
- >-
{{ latest_stage3.dest }}
- --xattrs-include='*.*'
- --numeric-owner
chdir: >-
{{ gentoo_prefix }}
creates: >-
{{ gentoo_prefix }}/var/tmp
when: not var_tmp_stat_data.stat.exists
- name: Create EFI directory layout
ansible.builtin.file:
path: >-
{{ mount_point }}
state: directory
loop:
- >-
{{ gentoo_prefix }}
- >-
{{ gentoo_prefix }}/efi
- >-
{{ gentoo_prefix }}/efi/EFI
- >-
{{ gentoo_prefix }}/efi/EFI/BOOT
- >-
{{ gentoo_prefix }}/efi/EFI/systemd
loop_control:
loop_var: mount_point
- name: Configure crypttab
ansible.builtin.copy:
content: |
decrypted-luks-0 UUID={{ first_luks_dev_uuid }} none luks,fido2-device=auto,tpm2-device=auto,tpm2-pcrs=1+5+7+8+11+12+14+15,discard
decrypted-luks-1 UUID={{ second_luks_dev_uuid }} none luks,fido2-device=auto,tpm2-device=auto,tpm2-pcrs=1+5+7+8+11+12+14+15,discard
dest: >-
{{ gentoo_prefix }}/etc/crypttab
- name: Set up tmp directories' privileges
ansible.builtin.file:
mode: 1777
path: >-
{{ mount_point }}
state: directory
loop:
- >-
{{ gentoo_prefix }}/tmp
- >-
{{ gentoo_prefix }}/var/tmp
loop_control:
loop_var: mount_point
- name: Copy the DNS configuration from the live OS into chroot
ansible.builtin.copy:
dest: >-
{{ gentoo_prefix }}/etc/resolv.conf
local_follow: true
src: /etc/resolv.conf
- name: Ensure the configuration entries present in `make.conf`
ansible.builtin.lineinfile:
line: >-
{{ entry }}
path: >-
{{ gentoo_prefix }}/etc/portage/make.conf
loop:
- >-
MAKEOPTS="-j{{
ansible_processor_nproc
}} -l{{
ansible_processor_nproc | int + 1
}}"
- >-
FEATURES="${FEATURES} getbinpkg"
- >-
FEATURES="${FEATURES} binpkg-request-signature"
- >-
GENTOO_MIRRORS="https://ftp.fi.muni.cz/pub/linux/gentoo/ https://mirror.it4i.cz/gentoo/ https://mirror.dkm.cz/gentoo/"
- >-
PORTAGE_RSYNC_EXTRA_OPTS="-4"
loop_control:
loop_var: entry
# mutate the config:
# https://github.com/ansible-collections/ansible.posix/issues/106
- name: Add {{ swap_dev }} as swap to fstab in chroot
ansible.posix.mount:
dump: 0 # fs_freq
fstab: >-
{{ gentoo_prefix }}/etc/fstab
fstype: swap
opts: auto,sw,lazytime
passno: 0
path: none
src: >-
UUID={{ swap_dev_uuid }}
state: present # amend /etc/fstab but don't mount
- name: Add a {{ rootfs_dev }} @ / mount point to fstab in chroot
ansible.posix.mount:
dump: 1 # fs_freq
fstab: >-
{{ gentoo_prefix }}/etc/fstab
fstype: xfs
opts: auto,rw,lazytime
passno: 1
path: /
src: >-
UUID={{ rootfs_dev_uuid }}
state: present # amend /etc/fstab but don't mount
- name: Add a {{ efifs_dev }} @ /efi mount point to fstab in chroot
# https://wiki.gentoo.org/wiki/EFI_System_Partition
ansible.posix.mount:
dump: 1 # fs_freq
fstab: >-
{{ gentoo_prefix }}/etc/fstab
fstype: vfat
opts: >-
auto,defaults,discard,rw,lazytime,uid=0,gid=0,umask=0077,x-systemd.automount,x-systemd.idle-timeout=600,errors=remount-ro
passno: 2
path: /efi
src: >-
UUID={{ efifs_dev_uuid }}
state: present # amend /etc/fstab but don't mount
- name: Add a {{ homefs_dev }} @ /home mount point to fstab in chroot
ansible.posix.mount:
dump: 1 # fs_freq
fstab: >-
{{ gentoo_prefix }}/etc/fstab
fstype: xfs
opts: auto,rw,lazytime
passno: 2
path: /home
src: >-
UUID={{ homefs_dev_uuid }}
state: present # amend /etc/fstab but don't mount
- name: Add a tmpfs @ /tmp mount point to fstab in chroot
# TODO: consider using zram
# noatime,noexec,nodev,nosuid,rootcontext=system_u:object_r:var_run_t:s0
ansible.builtin.lineinfile:
line: >-
tmpfs
/tmp
tmpfs
noatime,nodev,nosuid
0
0
path: >-
{{ gentoo_prefix }}/etc/fstab
- name: Mount virtual filesystems into chroot
ansible.builtin.command: >-
mount {{ mount_cmd }}
loop:
- >-
--types proc /proc {{ gentoo_prefix }}/proc
- >-
--rbind /sys {{ gentoo_prefix }}/sys
- >-
--make-rslave {{ gentoo_prefix }}/sys
- >-
--rbind /dev {{ gentoo_prefix }}/dev
- >-
--make-rslave {{ gentoo_prefix }}/dev
- >-
--bind /run {{ gentoo_prefix }}/run
- >-
--make-slave {{ gentoo_prefix }}/run
- >- # https://wiki.gentoo.org/wiki/SELinux/Installation#Setting_file_system_contexts
--types tmpfs --options nosuid,nodev,noexec shm /dev/shm
# - >-
# --types tmpfs --options nosid,nodev,noexec,rootcontext=system_u:object_r:var_run_t:s0 shm /dev/shm
- >-
--types tmpfs --options nosuid,nodev,noexec,rootcontext=system_u:object_r:var_run_t:s0 tmpfs {{ gentoo_prefix }}/tmp
loop_control:
loop_var: mount_cmd
- name: Instruct systemd to reload the unit files
ansible.builtin.command:
argv:
- chroot
- >-
{{ gentoo_prefix }}
- systemctl
- daemon-reload
chdir: >-
{{ gentoo_prefix }}
- name: Create config folder for accepted licenses
ansible.builtin.file:
path: >-
{{ gentoo_prefix }}/etc/portage/package.license
state: directory
- name: Create config folder for accepted keywords
ansible.builtin.file:
path: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords
state: directory
- name: Create config folder for masked ebuilds
ansible.builtin.file:
path: >-
{{ gentoo_prefix }}/etc/portage/package.mask
state: directory
- name: Create config folder for unmasked ebuilds
ansible.builtin.file:
path: >-
{{ gentoo_prefix }}/etc/portage/package.unmask
state: directory
- name: Accept www-client/google-chrome google-chrome license
ansible.builtin.copy:
content: |
www-client/google-chrome google-chrome
dest: >-
{{ gentoo_prefix }}/etc/portage/package.license/www-client--google-chrome
- name: Accept www-plugins/chrome-binary-plugins google-chrome license
ansible.builtin.copy:
content: |
www-plugins/chrome-binary-plugins google-chrome
dest: >-
{{ gentoo_prefix }}/etc/portage/package.license/www-plugins--chrome-binary-plugins
- name: Accept sys-kernel/linux-firmware linux-fw-redistributable license
ansible.builtin.copy:
content: |
sys-kernel/linux-firmware linux-fw-redistributable
dest: >-
{{ gentoo_prefix }}/etc/portage/package.license/sys-kernel--linux-firmware
- name: Accept x11-drivers/nvidia-drivers NVIDIA-r2 license
ansible.builtin.copy:
content: |
x11-drivers/nvidia-drivers NVIDIA-r2
dest: >-
{{ gentoo_prefix }}/etc/portage/package.license/x11-drivers--nvidia-drivers
- name: Accept media-sound/spotify Spotify license
ansible.builtin.copy:
content: |
media-sound/spotify Spotify
dest: >-
{{ gentoo_prefix }}/etc/portage/package.license/media-sound--spotify
- name: Accept net-im/slack all-rights-reserved license
ansible.builtin.copy:
content: |
net-im/slack all-rights-reserved
dest: >-
{{ gentoo_prefix }}/etc/portage/package.license/net-im--slack
- name: Accept media-fonts/kochi-substitute free-noncomm license
ansible.builtin.copy:
content: |
media-fonts/kochi-substitute free-noncomm
dest: >-
{{ gentoo_prefix }}/etc/portage/package.license/media-fonts--kochi-substitute
- name: Accept media-fonts/ipamonafont grass-ipafonts license
ansible.builtin.copy:
content: |
media-fonts/ipamonafont grass-ipafonts
dest: >-
{{ gentoo_prefix }}/etc/portage/package.license/media-fonts--ipamonafont
- name: Allow sys-boot/mokutil::gentoo ~amd64
ansible.builtin.copy:
content: |
sys-boot/mokutil::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/sys-boot--mokutil::gentoo--managed
- name: Allow gui-apps/tuigreet::gentoo ~amd64
ansible.builtin.copy:
content: |
gui-apps/tuigreet::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/gui-apps--tuigreet::gentoo--managed
- name: Allow app-crypt/kbfs::gentoo ~amd64
ansible.builtin.copy:
content: |
app-crypt/kbfs::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/app-crypt--kbfs::gentoo--managed
- name: Allow app-crypt/keybase::gentoo ~amd64
ansible.builtin.copy:
content: |
app-crypt/keybase::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/app-crypt--keybase::gentoo--managed
- name: Allow net-im/slack::gentoo ~amd64
ansible.builtin.copy:
content: |
net-im/slack::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/net-im--slack::gentoo--managed
- name: Allow gui-wm/hyprland::gentoo ~amd64
ansible.builtin.copy:
content: |
gui-wm/hyprland::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/gui-wm--hyprland::gentoo--managed
- name: Allow gui-libs/aquamarine::gentoo ~amd64
ansible.builtin.copy:
content: |
gui-libs/aquamarine::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/gui-libs--aquamarine::gentoo--managed
- name: Allow dev-libs/hyprgraphics::gentoo ~amd64
ansible.builtin.copy:
content: |
dev-libs/hyprgraphics::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/dev-libs--hyprgraphics::gentoo--managed
- name: Allow dev-libs/hyprlang::gentoo ~amd64
ansible.builtin.copy:
content: |
dev-libs/hyprlang::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/dev-libs--hyprlang::gentoo--managed
- name: Allow gui-libs/hyprland-qtutils::gentoo ~amd64
ansible.builtin.copy:
content: |
gui-libs/hyprland-qtutils::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/gui-libs--hyprland-qtutils::gentoo--managed
- name: Allow gui-libs/hyprutils::gentoo ~amd64
ansible.builtin.copy:
content: |
gui-libs/hyprutils::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/gui-libs--hyprutils::gentoo--managed
- name: Allow dev-libs/hyprland-protocols::gentoo ~amd64
ansible.builtin.copy:
content: |
dev-libs/hyprland-protocols::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/dev-libs--hyprland-protocols::gentoo--managed
- name: Allow dev-util/hyprwayland-scanner::gentoo ~amd64
ansible.builtin.copy:
content: |
dev-util/hyprwayland-scanner::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/dev-util--hyprwayland-scanner::gentoo--managed
- name: Allow sys-devel/gcc-14::gentoo ~amd64
ansible.builtin.copy:
content: |
sys-devel/gcc:14::gentoo ~amd64
dest: >-
{{ gentoo_prefix }}/etc/portage/package.accept_keywords/sys-devel--gcc::gentoo--managed
- name: Mask */*::guru
ansible.builtin.copy:
content: |
*/*::guru
dest: >-
{{ gentoo_prefix }}/etc/portage/package.mask/third-party-overlay--guru
- name: Mask */*::wayland-desktop
ansible.builtin.copy:
content: |
*/*::wayland-desktop