1 #cwd := $(notdir $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
3 disk_sd := /dev/disk/by-id/mmc-SU08G_0xb0320f0f
11 sudo $$(which sgdisk) --zap-all $(disk_sd)
13 sudo $$(which sgdisk) --zap-all $(disk_ssd)
14 sudo zpool labelclear -f /dev/disk/by-partlabel/$(hostName)_ssd_rpool || true
16 part: wipe-sd wipe-ssd
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)
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)
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
38 sudo mkdir -p /mnt/$(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
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
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
48 mount: mount-root mount-efi
50 sudo mkdir -p /mnt/$(hostName)
51 sudo mountpoint /mnt/$(hostName) || \
52 sudo mount -v /dev/disk/by-partlabel/$(hostName)_sd_root /mnt/$(hostName)
53 mount-efi: | mount-root
54 sudo mkdir -p /mnt/$(hostName)/boot/efi
55 sudo mountpoint /mnt/$(hostName)/boot/efi || \
56 sudo mount -v /dev/disk/by-partlabel/$(hostName)_sd_efi /mnt/$(hostName)/boot/efi
59 # Workaround https://dev.gnupg.org/T3908
60 chmod o+rw $$GPG_TTY $$XAUTHORITY
62 # prevent copying to /nix/store
63 git rm -rf --cached --ignore-unmatch private/root private/hosts/*
64 git reset private/hosts/$(hostName)/credentials private/hosts/$(hostName)/root/machine-id
66 $$(which nixos-install) \
67 --root /mnt/$(hostName) \
68 --flake '.#$(hostName)' \
72 git reset private/root private/hosts
74 # End workaround https://dev.gnupg.org/T3908
75 chmod o-rw $$GPG_TTY $$XAUTHORITY
89 ! sudo mountpoint /mnt/$(hostName)/"$$p" || \
90 sudo umount -v /mnt/$(hostName)/"$$p" ; \
92 ! sudo zpool list $(rpool) 2>/dev/null || \
93 zfs get -H encryption $(rpool) | \
94 grep -q '^$(rpool)\s*encryption\s*off' || \
95 zfs get -H keystatus $(rpool) | \
96 grep -q '^$(rpool)\s*keystatus\s*unavailable' || \
97 sudo zfs unload-key $(rpool)
98 #! sudo zpool list bpool 2>/dev/null || \
99 #sudo zpool export bpool
100 ! sudo zpool list $(rpool) 2>/dev/null || \
101 sudo zpool export $(rpool)
104 pass hosts/$(hostName)/zfs/rpool | \
105 NIXOPS_DEPLOYMENT="$${NIXOPS_DEPLOYMENT:-$(LOSURDO_DEPLOYMENT)}" \
106 nixops ssh $(hostName) -p 2222 'zfs load-key $(rpool) && pkill zfs'