1 mermet_disk := $(shell sed -ne 's/^device: \(.*\)/\1/p' physical/sfdisk.txt)
3 #mermet_cipher := aes-128-gcm
5 mermet_reservation := 40G
6 #mermet_channel := $$(nix-env -p /nix/var/nix/profiles/per-user/$$USER/channels -q nixpkgs --no-name --out-path)
7 MERMET_PHYSICAL ?= apu2e4
10 mermet-wipeout: mermet-umount
11 sudo zpool labelclear -f $(mermet_disk)-part3 || true
12 sudo zpool labelclear -f $(mermet_disk)-part5 || true
13 sudo $$(which sgdisk) --zap-all $(mermet_disk)
17 sudo $$(which sfdisk) $(mermet_disk) <physical/sfdisk.txt
18 sudo $$(which sgdisk) --randomize-guids $(mermet_disk)
22 # DOC: https://github.com/zfsonlinux/zfs/wiki/Debian-Buster-Root-on-ZFS
23 sudo mkdir -p /mnt/mermet
24 blkid -t TYPE=ext2 $(mermet_disk)-part3; test $$? != 2 || \
25 mkfs.ext2 $(mermet_disk)-part3
27 ## NOTE: enable only ZFS features supported by GRUB
28 #sudo zpool list bpool 2>/dev/null || \
29 #sudo zpool create -o ashift=12 -d \
30 # -o feature@allocation_classes=enabled \
31 # -o feature@async_destroy=enabled \
32 # -o feature@bookmarks=enabled \
33 # -o feature@embedded_data=enabled \
34 # -o feature@empty_bpobj=enabled \
35 # -o feature@enabled_txg=enabled \
36 # -o feature@extensible_dataset=enabled \
37 # -o feature@filesystem_limits=enabled \
38 # -o feature@hole_birth=enabled \
39 # -o feature@large_blocks=enabled \
40 # -o feature@lz4_compress=enabled \
41 # -o feature@project_quota=enabled \
42 # -o feature@resilver_defer=enabled \
43 # -o feature@spacemap_histogram=enabled \
44 # -o feature@spacemap_v2=enabled \
45 # -o feature@userobj_accounting=enabled \
46 # -o feature@zpool_checkpoint=enabled \
47 # -o feature@multi_vdev_crash_dump=disabled \
48 # -o feature@large_dnode=disabled \
49 # -o feature@sha512=disabled \
50 # -o feature@skein=disabled \
51 # -o feature@edonr=disabled \
52 # -O normalization=formD \
53 # -R /mnt/mermet bpool $(mermet_disk)-part3
65 # FIXME: configure with a volatile key in configuration.nix
66 #blkid -t TYPE=crypto_LUKS $(mermet_disk)-part4; test $$? != 2 || \
67 #sudo cryptsetup luksFormat --cipher aes-xts-plain64 --key-size 256 --hash sha256 $(mermet_disk)-part4
68 #sudo cryptsetup luksOpen $(mermet_disk)-part4 mermet-swap
69 #blkid -t TYPE=swap /dev/mapper/mermet--swap; test $$? != 2 || \
70 #sudo mkswap --check --label swap
71 #sudo cryptsetup luksClose $(mermet_disk)-part4 mermet-swap
73 sudo zpool list rpool 2>/dev/null || \
74 sudo zpool create -o ashift=12 \
75 $(if $(mermet_cipher),-O encryption=$(mermet_cipher) \
76 -O keyformat=passphrase \
77 -O keylocation=prompt) \
78 -O normalization=formD \
79 -R /mnt/mermet rpool $(mermet_disk)-part5
83 $(if $(mermet_autotrim),autotrim=on) \
88 $(if $(mermet_reservation),reservation=$(mermet_reservation)) \
93 # NOTE: mountpoint=legacy is required to let NixOS mount the ZFS filesystems.
94 sudo zfs list rpool/root 2>/dev/null || \
97 -o mountpoint=legacy \
100 #sudo zfs list bpool/boot 2>/dev/null || \
103 # -o mountpoint=legacy \
106 sudo blkid $(mermet_disk)-part2 -t TYPE=vfat || \
107 sudo mkfs.vfat -F 32 -s 1 -n EFI $(mermet_disk)-part2
120 sudo zfs list rpool/"$$p" 2>/dev/null || \
123 -o mountpoint=legacy \
127 com.sun:auto-snapshot=false \
133 com.sun:auto-snapshot=false \
136 com.sun:auto-snapshot=false \
142 #sudo zpool list bpool || \
143 #sudo zpool import -f bpool
144 sudo zpool list rpool || \
145 sudo zpool import -f rpool
146 # load encryption key
147 zfs get -H encryption rpool | \
148 grep -q '^rpool\s*encryption\s*off' || \
149 zfs get -H keystatus rpool | \
150 grep -q '^rpool\s*keystatus\s*available' || \
151 sudo zfs load-key rpool
153 sudo mkdir -p /mnt/mermet
154 sudo mountpoint /mnt/mermet || \
155 sudo mount -v -t zfs rpool/root /mnt/mermet
157 sudo mkdir -p /mnt/mermet/boot
158 sudo mountpoint /mnt/mermet/boot || \
159 sudo mount -v $(mermet_disk)-part3 /mnt/mermet/boot
160 #sudo mount -v -t zfs bpool/boot /mnt/mermet/boot
162 sudo mkdir -p /mnt/mermet/boot/efi
163 sudo mountpoint /mnt/mermet/boot/efi || \
164 sudo mount -v $(mermet_disk)-part2 /mnt/mermet/boot/efi
177 sudo mkdir -p /mnt/mermet/"$$p"; \
178 sudo mountpoint /mnt/mermet/"$$p" || \
179 sudo mount -v -t zfs rpool/"$$p" /mnt/mermet/"$$p" ; \
181 sudo chmod 1777 /mnt/mermet/var/tmp
183 mermet-bootstrap: mermet-mount
184 sudo rm -rf /mnt/mermet/etc/nixos
185 #test "$$(sudo grub-probe /mnt/mermet/boot)" = zfs
186 # NOTE: nixos-install will install GRUB following configuration.nix
188 #sudo grub-install $(mermet_disk)
191 # --target=x86_64-efi \
192 # --efi-directory=/mnt/mermet/boot/efi \
193 # --bootloader-id=nixos \
197 pass sourcephile/mermet/dropbear/host-ecdsa.key | \
198 sudo install -D -o root -g root -m 400 /dev/stdin \
199 /mnt/mermet/etc/dropbear/host-ecdsa.key && \
200 test -s /mnt/mermet/etc/dropbear/host-ecdsa.key
202 #trap "test ! -e SHRED-ME || sudo find SHRED-ME -type f -exec shred -u {} + && sudo rm -rf SHRED-ME" EXIT ;
204 GNUPGHOME="$$GNUPGHOME" \
205 GPG_TTY="$$GPG_TTY" \
207 LC_CTYPE="$$LC_CTYPE" \
208 MERMET_HOSTING="$(MERMET_HOSTING)" \
209 MERMET_PHYSICAL="$(MERMET_PHYSICAL)" \
210 NIXOS_CONFIG="$$(readlink -e ./configuration.nix)" \
211 NIX_CONF_DIR="$$NIX_CONF_DIR" \
212 NIX_PATH="$$NIX_PATH" \
213 PASSWORD_STORE_DIR="$$PASSWORD_STORE_DIR" \
215 SSL_CERT_FILE="$$SSL_CERT_FILE" \
216 $$(which nixos-install) \
218 $(if $(mermet_channel),--channel "$(mermet_channel)") \
236 ! sudo mountpoint /mnt/mermet/"$$p" || \
237 sudo umount -v /mnt/mermet/"$$p" ; \
239 ! sudo zpool list rpool 2>/dev/null || \
240 zfs get -H encryption rpool | \
241 grep -q '^rpool\s*encryption\s*off' || \
242 zfs get -H keystatus rpool | \
243 grep -q '^rpool\s*keystatus\s*unavailable' || \
244 sudo zfs unload-key rpool
245 #! sudo zpool list bpool 2>/dev/null || \
246 #sudo zpool export bpool
247 ! sudo zpool list rpool 2>/dev/null || \
248 sudo zpool export rpool