1 #cwd := $(notdir $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
3 disk_sd := /dev/disk/by-id/mmc-SU08G_0xb0320f0f
4 disk_ssd := /dev/disk/by-id/ata-YMTC_JGS_2201060101833
12 sudo sgdisk --zap-all $(disk_sd)
14 sudo sgdisk --zap-all $(disk_ssd)
15 sudo zpool labelclear -f /dev/disk/by-partlabel/$(hostName)_ssd_rpool || true
17 part: wipe-sd wipe-ssd
19 sudo sgdisk -a1 -n0:34:2047 -t0:EF02 -c0:"$(hostName)_sd_bios" $(disk_sd)
20 sudo sgdisk -n0:1M:+100M -t0:EF00 -c0:"$(hostName)_sd_efi" $(disk_sd)
21 sudo sgdisk -n0:0:0 -t0:8300 -c0:"$(hostName)_sd_root" $(disk_sd)
22 sudo sgdisk --randomize-guids $(disk_sd)
23 sudo sgdisk --backup=$(hostName)_sd.sgdisk $(disk_sd)
25 sudo sgdisk -a1 -n0:34:2047 -t0:EF02 -c0:"$(hostName)_ssd_bios" $(disk_ssd)
26 sudo sgdisk -n0:1M:+100M -t0:EF00 -c0:"$(hostName)_ssd_efi" $(disk_ssd)
27 sudo sgdisk -n0:0:+256M -t0:8300 -c0:"$(hostName)_ssd_boot" $(disk_ssd)
28 sudo sgdisk -n0:0:+8G -t0:8200 -c0:"$(hostName)_ssd_swap" $(disk_ssd)
29 sudo sgdisk -n0:0:0 -t0:BF01 -c0:"$(hostName)_ssd_rpool" $(disk_ssd)
30 sudo sgdisk --randomize-guids $(disk_ssd)
31 sudo sgdisk --backup=$(hostName)_ssd.sgdisk $(disk_ssd)
33 format-sd: format-sd-root format-sd-efi
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/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: format-ssd-root format-ssd-efi format-ssd-boot
43 sudo blkid /dev/disk/by-partlabel/$(hostName)_ssd_efi -t TYPE=vfat || \
44 sudo mkfs.vfat -F 32 -s 1 -n EFI /dev/disk/by-partlabel/$(hostName)_ssd_efi
46 sudo blkid -t TYPE=ext4 /dev/disk/by-partlabel/$(hostName)_ssd_boot; test $$? != 2 || \
47 sudo mkfs.ext4 /dev/disk/by-partlabel/$(hostName)_ssd_boot
49 sudo zpool list $(rpool) 2>/dev/null || \
50 sudo zpool create -o ashift=12 \
52 -R /mnt/$(hostName) $(rpool) /dev/disk/by-partlabel/$(hostName)_ssd_zpool
54 autotrim=$(autotrim) \
60 compression=$(compression) \
66 # https://nixos.wiki/wiki/NixOS_on_ZFS#Reservations
67 sudo zfs list $(rpool)/reserved 2>/dev/null || \
68 sudo zfs create -o canmount=off -o mountpoint=none $(rpool)/reserved
69 sudo zfs set refreservation=$(reservation) $(rpool)/reserved
71 # mountpoint=legacy is required to let NixOS mount the ZFS filesystems.
72 sudo zfs list $(rpool)/root 2>/dev/null || \
75 -o mountpoint=legacy \
82 sudo zfs list $(rpool)/"$$p" 2>/dev/null || \
85 -o mountpoint=legacy \
91 sudo zfs list $(rpool)/"$$p" 2>/dev/null || \
94 -o mountpoint=legacy \
95 $(if $(cipher),-O encryption=$(cipher) \
96 -o keyformat=passphrase \
97 -o keylocation=prompt) \
100 #sudo zfs set sync=disabled $(rpool)/var/tmp
101 #sudo zfs set copies=2 $(rpool)/home/documents
103 mount-sd: mount-sd-root mount-sd-efi
105 sudo mkdir -p /mnt/install/$(hostName)
106 sudo mountpoint /mnt/install/$(hostName) || \
107 sudo mount -v /dev/disk/by-partlabel/$(hostName)_sd_root /mnt/install/$(hostName)
108 mount-sd-efi: | mount-sd-root
109 sudo mkdir -p /mnt/install/$(hostName)/boot/efi
110 sudo mountpoint /mnt/install/$(hostName)/boot/efi || \
111 sudo mount -v /dev/disk/by-partlabel/$(hostName)_sd_efi /mnt/install/$(hostName)/boot/efi
113 mount-ssd: mount-ssd-root mount-ssd-efi
115 sudo mkdir -p /mnt/install/$(hostName)
116 sudo mountpoint /mnt/install/$(hostName) || \
117 sudo mount -v /dev/disk/by-partlabel/$(hostName)_ssd_root /mnt/install/$(hostName)
118 mount-ssd-efi: | mount-ssd-root
119 sudo mkdir -p /mnt/install/$(hostName)/boot/efi
120 sudo mountpoint /mnt/install/$(hostName)/boot/efi || \
121 sudo mount -v /dev/disk/by-partlabel/$(hostName)_ssd_efi /mnt/install/$(hostName)/boot/efi
124 mountpoint /mnt/install/$(hostName)
126 # Workaround https://dev.gnupg.org/T3908
127 chmod o+rw $$GPG_TTY $$XAUTHORITY
129 sudo --preserve-env \
130 $$(which nixos-install) \
131 --root /mnt/install/$(hostName) \
132 --flake '.#$(hostName)' \
137 # End workaround https://dev.gnupg.org/T3908
138 chmod o-rw $$GPG_TTY $$XAUTHORITY
152 ! sudo mountpoint /mnt/install/$(hostName)/"$$p" || \
153 sudo umount -v /mnt/install/$(hostName)/"$$p" ; \
155 ! sudo zpool list $(rpool) 2>/dev/null || \
156 zfs get -H encryption $(rpool) | \
157 grep -q '^$(rpool)\s*encryption\s*off' || \
158 zfs get -H keystatus $(rpool) | \
159 grep -q '^$(rpool)\s*keystatus\s*unavailable' || \
160 sudo zfs unload-key $(rpool)
161 #! sudo zpool list bpool 2>/dev/null || \
162 #sudo zpool export bpool
163 ! sudo zpool list $(rpool) 2>/dev/null || \
164 sudo zpool export $(rpool)