1 #cwd := $(notdir $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
2 MERMET_MACHINE ?= apu2e4
4 mermet_disk := $(shell sed -ne 's/^device: \(.*\)/\1/p' machine/$(MERMET_MACHINE)/sfdisk.txt)
6 #mermet_cipher := aes-128-gcm
8 mermet_reservation := 40G
9 #mermet_channel := $$(nix-env -p /nix/var/nix/profiles/per-user/$$USER/channels -q nixpkgs --no-name --out-path)
14 mermet-wipeout: mermet-umount
15 sudo zpool labelclear -f $(mermet_disk)-part3 || true
16 sudo zpool labelclear -f $(mermet_disk)-part5 || true
17 sudo $$(which sgdisk) --zap-all $(mermet_disk)
21 sudo $$(which sfdisk) $(mermet_disk) <machine/$(MERMET_MACHINE)/sfdisk.txt
22 sudo $$(which sgdisk) --randomize-guids $(mermet_disk)
26 # DOC: https://github.com/zfsonlinux/zfs/wiki/Debian-Buster-Root-on-ZFS
27 sudo mkdir -p /mnt/mermet
28 blkid -t TYPE=ext2 $(mermet_disk)-part3; test $$? != 2 || \
29 mkfs.ext2 $(mermet_disk)-part3
31 ## NOTE: enable only ZFS features supported by GRUB
32 #sudo zpool list bpool 2>/dev/null || \
33 #sudo zpool create -o ashift=12 -d \
34 # -o feature@allocation_classes=enabled \
35 # -o feature@async_destroy=enabled \
36 # -o feature@bookmarks=enabled \
37 # -o feature@embedded_data=enabled \
38 # -o feature@empty_bpobj=enabled \
39 # -o feature@enabled_txg=enabled \
40 # -o feature@extensible_dataset=enabled \
41 # -o feature@filesystem_limits=enabled \
42 # -o feature@hole_birth=enabled \
43 # -o feature@large_blocks=enabled \
44 # -o feature@lz4_compress=enabled \
45 # -o feature@project_quota=enabled \
46 # -o feature@resilver_defer=enabled \
47 # -o feature@spacemap_histogram=enabled \
48 # -o feature@spacemap_v2=enabled \
49 # -o feature@userobj_accounting=enabled \
50 # -o feature@zpool_checkpoint=enabled \
51 # -o feature@multi_vdev_crash_dump=disabled \
52 # -o feature@large_dnode=disabled \
53 # -o feature@sha512=disabled \
54 # -o feature@skein=disabled \
55 # -o feature@edonr=disabled \
56 # -O normalization=formD \
57 # -R /mnt/mermet bpool $(mermet_disk)-part3
69 # FIXME: configure with a volatile key in configuration.nix
70 #blkid -t TYPE=crypto_LUKS $(mermet_disk)-part4; test $$? != 2 || \
71 #sudo cryptsetup luksFormat --cipher aes-xts-plain64 --key-size 256 --hash sha256 $(mermet_disk)-part4
72 #sudo cryptsetup luksOpen $(mermet_disk)-part4 mermet-swap
73 #blkid -t TYPE=swap /dev/mapper/mermet--swap; test $$? != 2 || \
74 #sudo mkswap --check --label swap
75 #sudo cryptsetup luksClose $(mermet_disk)-part4 mermet-swap
77 sudo zpool list rpool 2>/dev/null || \
78 sudo zpool create -o ashift=12 \
79 $(if $(mermet_cipher),-O encryption=$(mermet_cipher) \
80 -O keyformat=passphrase \
81 -O keylocation=prompt) \
82 -O normalization=formD \
83 -R /mnt/mermet rpool $(mermet_disk)-part5
87 $(if $(mermet_autotrim),autotrim=on) \
92 $(if $(mermet_reservation),reservation=$(mermet_reservation)) \
97 # NOTE: mountpoint=legacy is required to let NixOS mount the ZFS filesystems.
98 sudo zfs list rpool/root 2>/dev/null || \
101 -o mountpoint=legacy \
104 #sudo zfs list bpool/boot 2>/dev/null || \
107 # -o mountpoint=legacy \
110 sudo blkid $(mermet_disk)-part2 -t TYPE=vfat || \
111 sudo mkfs.vfat -F 32 -s 1 -n EFI $(mermet_disk)-part2
124 sudo zfs list rpool/"$$p" 2>/dev/null || \
127 -o mountpoint=legacy \
131 com.sun:auto-snapshot=false \
137 com.sun:auto-snapshot=false \
140 com.sun:auto-snapshot=false \
146 #sudo zpool list bpool || \
147 #sudo zpool import -f bpool
148 sudo zpool list rpool || \
149 sudo zpool import -f rpool
150 # load encryption key
151 zfs get -H encryption rpool | \
152 grep -q '^rpool\s*encryption\s*off' || \
153 zfs get -H keystatus rpool | \
154 grep -q '^rpool\s*keystatus\s*available' || \
155 sudo zfs load-key rpool
157 sudo mkdir -p /mnt/mermet
158 sudo mountpoint /mnt/mermet || \
159 sudo mount -v -t zfs rpool/root /mnt/mermet
161 sudo mkdir -p /mnt/mermet/boot
162 sudo mountpoint /mnt/mermet/boot || \
163 sudo mount -v $(mermet_disk)-part3 /mnt/mermet/boot
164 #sudo mount -v -t zfs bpool/boot /mnt/mermet/boot
166 sudo mkdir -p /mnt/mermet/boot/efi
167 sudo mountpoint /mnt/mermet/boot/efi || \
168 sudo mount -v $(mermet_disk)-part2 /mnt/mermet/boot/efi
181 sudo mkdir -p /mnt/mermet/"$$p"; \
182 sudo mountpoint /mnt/mermet/"$$p" || \
183 sudo mount -v -t zfs rpool/"$$p" /mnt/mermet/"$$p" ; \
185 sudo chmod 1777 /mnt/mermet/var/tmp
187 mermet-bootstrap: mermet-mount
188 sudo rm -rf /mnt/mermet/etc/nixos
189 #test "$$(sudo grub-probe /mnt/mermet/boot)" = zfs
190 # NOTE: nixos-install will install GRUB following configuration.nix
192 #sudo grub-install $(mermet_disk)
195 # --target=x86_64-efi \
196 # --efi-directory=/mnt/mermet/boot/efi \
197 # --bootloader-id=nixos \
201 pass sourcephile/mermet/dropbear/host-ecdsa.key | \
202 sudo install -D -o root -g root -m 400 /dev/stdin \
203 /mnt/mermet/etc/dropbear/host-ecdsa.key && \
204 test -s /mnt/mermet/etc/dropbear/host-ecdsa.key
206 #trap "test ! -e SHRED-ME || sudo find SHRED-ME -type f -exec shred -u {} + && sudo rm -rf SHRED-ME" EXIT ;
208 GNUPGHOME="$$GNUPGHOME" \
209 GPG_TTY="$$GPG_TTY" \
211 LC_CTYPE="$$LC_CTYPE" \
212 MERMET_HOSTING="$(MERMET_HOSTING)" \
213 MERMET_MACHINE="$(MERMET_MACHINE)" \
214 NIXOS_CONFIG="$$(readlink -e ./configuration.nix)" \
215 NIX_CONF_DIR="$$NIX_CONF_DIR" \
216 NIX_PATH="$$NIX_PATH" \
217 PASSWORD_STORE_DIR="$$PASSWORD_STORE_DIR" \
219 SSL_CERT_FILE="$$SSL_CERT_FILE" \
220 $$(which nixos-install) \
222 $(if $(mermet_channel),--channel "$(mermet_channel)") \
241 ! sudo mountpoint /mnt/mermet/"$$p" || \
242 sudo umount -v /mnt/mermet/"$$p" ; \
244 ! sudo zpool list rpool 2>/dev/null || \
245 zfs get -H encryption rpool | \
246 grep -q '^rpool\s*encryption\s*off' || \
247 zfs get -H keystatus rpool | \
248 grep -q '^rpool\s*keystatus\s*unavailable' || \
249 sudo zfs unload-key rpool
250 #! sudo zpool list bpool 2>/dev/null || \
251 #sudo zpool export bpool
252 ! sudo zpool list rpool 2>/dev/null || \
253 sudo zpool export rpool