1 #cwd := $(notdir $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
2 NIXOPS_DEPLOYMENT := maintenance
3 mermet_disk := $(shell sed -ne 's/^device: \(.*\)/\1/p' sfdisk.txt)
5 mermet_cipher := aes-128-gcm
7 mermet_reservation := 40G
8 #mermet_channel := $$(nix-env -p /nix/var/nix/profiles/per-user/$$USER/channels -q nixpkgs --no-name --out-path)
14 sudo zpool labelclear -f $(mermet_disk)-part3 || true
15 sudo zpool labelclear -f $(mermet_disk)-part5 || true
16 sudo $$(which sgdisk) --zap-all $(mermet_disk)
20 sudo $$(which sfdisk) $(mermet_disk) <sfdisk.txt
21 sudo $$(which sgdisk) --randomize-guids $(mermet_disk)
25 # DOC: https://github.com/zfsonlinux/zfs/wiki/Debian-Buster-Root-on-ZFS
26 sudo mkdir -p /mnt/mermet
27 blkid -t TYPE=ext2 $(mermet_disk)-part3; test $$? != 2 || \
28 mkfs.ext2 $(mermet_disk)-part3
30 ## NOTE: enable only ZFS features supported by GRUB
31 #sudo zpool list bpool 2>/dev/null || \
32 #sudo zpool create -o ashift=12 -d \
33 # -o feature@allocation_classes=enabled \
34 # -o feature@async_destroy=enabled \
35 # -o feature@bookmarks=enabled \
36 # -o feature@embedded_data=enabled \
37 # -o feature@empty_bpobj=enabled \
38 # -o feature@enabled_txg=enabled \
39 # -o feature@extensible_dataset=enabled \
40 # -o feature@filesystem_limits=enabled \
41 # -o feature@hole_birth=enabled \
42 # -o feature@large_blocks=enabled \
43 # -o feature@lz4_compress=enabled \
44 # -o feature@project_quota=enabled \
45 # -o feature@resilver_defer=enabled \
46 # -o feature@spacemap_histogram=enabled \
47 # -o feature@spacemap_v2=enabled \
48 # -o feature@userobj_accounting=enabled \
49 # -o feature@zpool_checkpoint=enabled \
50 # -o feature@multi_vdev_crash_dump=disabled \
51 # -o feature@large_dnode=disabled \
52 # -o feature@sha512=disabled \
53 # -o feature@skein=disabled \
54 # -o feature@edonr=disabled \
55 # -O normalization=formD \
56 # -R /mnt/mermet bpool $(mermet_disk)-part3
68 # Note: configured with a volatile key in mermet.nix
69 #blkid -t TYPE=crypto_LUKS $(mermet_disk)-part4; test $$? != 2 || \
70 #sudo cryptsetup luksFormat --cipher aes-xts-plain64 --key-size 256 --hash sha256 $(mermet_disk)-part4
71 #sudo cryptsetup luksOpen $(mermet_disk)-part4 swap
72 #blkid -t TYPE=swap /dev/mapper/-swap; test $$? != 2 || \
73 #sudo mkswap --check --label swap
74 #sudo cryptsetup luksClose $(mermet_disk)-part4 swap
76 sudo zpool list rpool 2>/dev/null || \
77 sudo zpool create -o ashift=12 \
78 $(if $(mermet_cipher),-O encryption=$(mermet_cipher) \
79 -O keyformat=passphrase \
80 -O keylocation=prompt) \
81 -O normalization=formD \
82 -R /mnt/mermet rpool $(mermet_disk)-part5
86 $(if $(mermet_autotrim),autotrim=on) \
91 $(if $(mermet_reservation),reservation=$(mermet_reservation)) \
96 # NOTE: mountpoint=legacy is required to let NixOS mount the ZFS filesystems.
97 sudo zfs list rpool/root 2>/dev/null || \
100 -o mountpoint=legacy \
103 #sudo zfs list bpool/boot 2>/dev/null || \
106 # -o mountpoint=legacy \
109 sudo blkid $(mermet_disk)-part2 -t TYPE=vfat || \
110 sudo mkfs.vfat -F 32 -s 1 -n EFI $(mermet_disk)-part2
123 sudo zfs list rpool/"$$p" 2>/dev/null || \
126 -o mountpoint=legacy \
130 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
184 #test "$$(sudo grub-probe /mnt/mermet/boot)" = zfs
185 # NOTE: nixos-install will install GRUB following mermet.nix
187 #sudo grub-install $(mermet_disk)
190 # --target=x86_64-efi \
191 # --efi-directory=/mnt/mermet/boot/efi \
192 # --bootloader-id=nixos \
196 pass servers/mermet/dropbear/host.key | \
197 sudo install -D -o root -g root -m 400 /dev/stdin \
198 /mnt/mermet/etc/dropbear/host.key && \
199 test -s /mnt/mermet/etc/dropbear/host.key
201 #trap "test ! -e SHRED-ME || sudo find SHRED-ME -type f -exec shred -u {} + && sudo rm -rf SHRED-ME" EXIT ;
203 GNUPGHOME="$$GNUPGHOME" \
204 GPG_TTY="$$GPG_TTY" \
206 LC_CTYPE="$$LC_CTYPE" \
207 NIXOPS_DEPLOYMENT="$(NIXOPS_DEPLOYMENT)" \
208 NIXOS_CONFIG="$$(readlink -e ../mermet.nix)" \
209 NIX_CONF_DIR="$$NIX_CONF_DIR" \
210 NIX_PATH="$$NIX_PATH" \
211 PASSWORD_STORE_DIR="$$PASSWORD_STORE_DIR" \
213 SSL_CERT_FILE="$$SSL_CERT_FILE" \
214 $$(which nixos-install) \
216 $(if $(mermet_channel),--channel "$(mermet_channel)") \
235 ! sudo mountpoint /mnt/mermet/"$$p" || \
236 sudo umount -v /mnt/mermet/"$$p" ; \
238 ! sudo zpool list rpool 2>/dev/null || \
239 zfs get -H encryption rpool | \
240 grep -q '^rpool\s*encryption\s*off' || \
241 zfs get -H keystatus rpool | \
242 grep -q '^rpool\s*keystatus\s*unavailable' || \
243 sudo zfs unload-key rpool
244 #! sudo zpool list bpool 2>/dev/null || \
245 #sudo zpool export bpool
246 ! sudo zpool list rpool 2>/dev/null || \
247 sudo zpool export rpool
250 pass servers/mermet/zfs/rpool | \
251 NIXOPS_DEPLOYMENT="$${NIXOPS_DEPLOYMENT:-$(NIXOPS_DEPLOYMENT)}" \
252 nixops ssh mermet -p 2222 'zfs load-key rpool && pkill zfs'