]> Git — Sourcephile - julm/julm-nix.git/blob - hosts/aubergine/Makefile
git: add .git-blame-ignore-revs
[julm/julm-nix.git] / hosts / aubergine / Makefile
1 #cwd := $(notdir $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
2 hostName := aubergine
3 disk_sd := /dev/disk/by-id/mmc-SU08G_0xb0320f0f
4 disk_ssd := /dev/null
5 rpool := $(hostName)
6 cipher := aes-128-gcm
7 autotrim := on
8 reservation := 1G
9
10 wipe-sd:
11 sudo $$(which sgdisk) --zap-all $(disk_sd)
12 wipe-ssd:
13 sudo $$(which sgdisk) --zap-all $(disk_ssd)
14 sudo zpool labelclear -f /dev/disk/by-partlabel/$(hostName)_ssd_rpool || true
15
16 part: wipe-sd wipe-ssd
17 part-sd: wipe-sd
18 sudo $$(which sgdisk) -a1 -n0:34:2047 -t0:EF02 -c0:"$(hostName)_sd_bios" $(disk_sd)
19 sudo $$(which sgdisk) -n0:1M:+100M -t0:EF00 -c0:"$(hostName)_sd_efi" $(disk_sd)
20 sudo $$(which sgdisk) -n0:0:0 -t0:8300 -c0:"$(hostName)_sd_root" $(disk_sd)
21 sudo $$(which sgdisk) --randomize-guids $(disk_sd)
22 sudo $$(which sgdisk) --backup=$(hostName)_sd.sgdisk $(disk_sd)
23 part-ssd:
24 sudo $$(which sgdisk) -a1 -n0:34:2047 -t0:EF02 -c0:"$(hostName)_ssd_bios" $(disk_ssd)
25 sudo $$(which sgdisk) -n0:1M:+100M -t0:EF00 -c0:"$(hostName)_ssd_efi" $(disk_ssd)
26 sudo $$(which sgdisk) -n0:0:+256M -t0:8300 -c0:"$(hostName)_ssd_boot" $(disk_ssd)
27 sudo $$(which sgdisk) -n0:0:+8G -t0:8200 -c0:"$(hostName)_ssd_swap" $(disk_ssd)
28 sudo $$(which sgdisk) -n0:0:0 -t0:BF01 -c0:"$(hostName)_ssd_rpool" $(disk_ssd)
29 sudo $$(which sgdisk) --randomize-guids $(disk_ssd)
30 sudo $$(which sgdisk) --backup=$(hostName)_ssd.sgdisk $(disk_ssd)
31
32 format: umount format-sd-efi format-sd-boot format-ssd-efi format-ssd-boot
33 format-sd: format-sd-root format-sd-efi
34 format-sd-efi: | format-sd-root
35 sudo blkid /dev/disk/by-partlabel/$(hostName)_sd_efi -t TYPE=vfat || \
36 sudo mkfs.vfat -F 32 -s 1 -n EFI /dev/disk/by-partlabel/$(hostName)_sd_efi
37 format-sd-root:
38 sudo mkdir -p /mnt/install/$(hostName)
39 sudo blkid -t TYPE=ext4 /dev/disk/by-partlabel/$(hostName)_sd_root; test $$? != 2 || \
40 sudo mkfs.ext4 /dev/disk/by-partlabel/$(hostName)_sd_root
41 format-ssd-efi:
42 sudo blkid /dev/disk/by-partlabel/$(hostName)_ssd_efi -t TYPE=vfat || \
43 sudo mkfs.vfat -F 32 -s 1 -n EFI /dev/disk/by-partlabel/$(hostName)_ssd_efi
44 format-ssd-boot:
45 sudo blkid -t TYPE=ext2 /dev/disk/by-partlabel/$(hostName)_ssd_boot; test $$? != 2 || \
46 sudo mkfs.ext2 /dev/disk/by-partlabel/$(hostName)_ssd_boot
47
48 mount: mount-root mount-efi
49 mount-root:
50 sudo mkdir -p /mnt/install/$(hostName)
51 sudo mountpoint /mnt/install/$(hostName) || \
52 sudo mount -v /dev/disk/by-partlabel/$(hostName)_sd_root /mnt/install/$(hostName)
53 mount-efi: | mount-root
54 sudo mkdir -p /mnt/install/$(hostName)/boot/efi
55 sudo mountpoint /mnt/install/$(hostName)/boot/efi || \
56 sudo mount -v /dev/disk/by-partlabel/$(hostName)_sd_efi /mnt/install/$(hostName)/boot/efi
57
58 bootstrap: mount
59 # Workaround https://dev.gnupg.org/T3908
60 chmod o+rw $$GPG_TTY $$XAUTHORITY
61
62 sudo --preserve-env \
63 $$(which nixos-install) \
64 --root /mnt/install/$(hostName) \
65 --flake '.#$(hostName)' \
66 --no-root-passwd \
67 --no-channel-copy \
68 --show-trace
69
70 # End workaround https://dev.gnupg.org/T3908
71 chmod o-rw $$GPG_TTY $$XAUTHORITY
72
73 umount:
74 for p in \
75 boot/efi \
76 boot \
77 home \
78 nix \
79 var/cache \
80 var/log \
81 var/tmp \
82 var \
83 "" \
84 ; do \
85 ! sudo mountpoint /mnt/install/$(hostName)/"$$p" || \
86 sudo umount -v /mnt/install/$(hostName)/"$$p" ; \
87 done
88 ! sudo zpool list $(rpool) 2>/dev/null || \
89 zfs get -H encryption $(rpool) | \
90 grep -q '^$(rpool)\s*encryption\s*off' || \
91 zfs get -H keystatus $(rpool) | \
92 grep -q '^$(rpool)\s*keystatus\s*unavailable' || \
93 sudo zfs unload-key $(rpool)
94 #! sudo zpool list bpool 2>/dev/null || \
95 #sudo zpool export bpool
96 ! sudo zpool list $(rpool) 2>/dev/null || \
97 sudo zpool export $(rpool)