]> Git — Sourcephile - julm/julm-nix.git/blob - hosts/aubergine/Makefile
Revert "aubergine: hack dbus"
[julm/julm-nix.git] / hosts / aubergine / Makefile
1 #cwd := $(notdir $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
2 hostName := aubergine
3 disk_sd := /dev/disk/by-id/mmc-SU08G_0xb0320f0f
4 disk_ssd := /dev/null
5 rpool := $(hostName)
6 cipher := aes-128-gcm
7 autotrim := on
8 reservation := 1G
9
10 wipe-sd:
11 sudo $$(which sgdisk) --zap-all $(disk_sd)
12 wipe-ssd:
13 sudo $$(which sgdisk) --zap-all $(disk_ssd)
14 sudo zpool labelclear -f /dev/disk/by-partlabel/$(hostName)_ssd_rpool || true
15
16 part: wipe-sd wipe-ssd
17 part-sd: wipe-sd
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)
23 part-ssd:
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)
31
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
37 format-sd-root:
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
41 format-ssd-efi:
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
44 format-ssd-boot:
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
47
48 mount: mount-root mount-efi
49 mount-root:
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
57
58 bootstrap: mount
59 # Workaround https://dev.gnupg.org/T3908
60 chmod o+rw $$GPG_TTY $$XAUTHORITY
61
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
65 sudo --preserve-env \
66 $$(which nixos-install) \
67 --root /mnt/$(hostName) \
68 --flake '.#$(hostName)' \
69 --no-root-passwd \
70 --no-channel-copy \
71 --show-trace
72 git reset private/root private/hosts
73
74 # End workaround https://dev.gnupg.org/T3908
75 chmod o-rw $$GPG_TTY $$XAUTHORITY
76
77 umount:
78 for p in \
79 boot/efi \
80 boot \
81 home \
82 nix \
83 var/cache \
84 var/log \
85 var/tmp \
86 var \
87 "" \
88 ; do \
89 ! sudo mountpoint /mnt/$(hostName)/"$$p" || \
90 sudo umount -v /mnt/$(hostName)/"$$p" ; \
91 done
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)
102
103 unlock:
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'