#cwd := $(notdir $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
#disk := /dev/disk/by-id/usb-Generic-_Multi-Card_20071114173400000-0:0
#disk := /dev/disk/by-id/nvme-Samsung_SSD_970_EVO_Plus_250GB_S4EUNJ0N211426T
-machine := patate200
+hostName := patate
disk_ssd := /dev/disk/by-id/ata-CT250MX500SSD1_2004E2849DD1
-zpool := $(machine)
+zpool := $(hostName)
cipher := aes-128-gcm
autotrim := on
reservation := 1G
wipe:
sudo modprobe zfs
- sudo zpool labelclear -f /dev/disk/by-partlabel/$(machine)_ssd_zpool || true
+ sudo zpool labelclear -f /dev/disk/by-partlabel/$(hostName)_ssd_zpool || true
sudo $$(which sgdisk) --zap-all $(disk_ssd)
part: wipe
# https://wiki.archlinux.org/index.php/BIOS_boot_partition
- sudo $$(which sgdisk) -a1 -n0:34:2047 -t0:EF02 -c0:"$(machine)_ssd_bios" $(disk_ssd)
- sudo $$(which sgdisk) -n0:1M:+32M -t0:EF00 -c0:"$(machine)_ssd_efi" $(disk_ssd)
- sudo $$(which sgdisk) -n0:0:+256M -t0:8300 -c0:"$(machine)_ssd_boot" $(disk_ssd)
- sudo $$(which sgdisk) -n0:0:+4G -t0:8200 -c0:"$(machine)_ssd_swap" $(disk_ssd)
- sudo $$(which sgdisk) -n0:0:0 -t0:BF01 -c0:"$(machine)_ssd_zpool" $(disk_ssd)
+ sudo $$(which sgdisk) -a1 -n0:34:2047 -t0:EF02 -c0:"$(hostName)_ssd_bios" $(disk_ssd)
+ sudo $$(which sgdisk) -n0:1M:+32M -t0:EF00 -c0:"$(hostName)_ssd_efi" $(disk_ssd)
+ sudo $$(which sgdisk) -n0:0:+256M -t0:8300 -c0:"$(hostName)_ssd_boot" $(disk_ssd)
+ sudo $$(which sgdisk) -n0:0:+4G -t0:8200 -c0:"$(hostName)_ssd_swap" $(disk_ssd)
+ sudo $$(which sgdisk) -n0:0:0 -t0:BF01 -c0:"$(hostName)_ssd_zpool" $(disk_ssd)
# https://wiki.archlinux.org/index.php/Partitioning#Tricking_old_BIOS_into_booting_from_GPT
printf '\200\0\0\0\0\0\0\0\0\0\0\0\001\0\0\0' | sudo dd of=$(disk_ssd) bs=1 seek=462
sudo $$(which sgdisk) --randomize-guids $(disk_ssd)
- sudo $$(which sgdisk) --backup=$(machine)_ssd.sgdisk $(disk_ssd)
+ sudo $$(which sgdisk) --backup=$(hostName)_ssd.sgdisk $(disk_ssd)
format: umount format-efi format-boot format-zpool
format-efi:
- sudo blkid /dev/disk/by-partlabel/$(machine)_ssd_efi -t TYPE=vfat || \
- sudo mkfs.vfat -F 16 -s 1 -n EFI /dev/disk/by-partlabel/$(machine)_ssd_efi
+ sudo blkid /dev/disk/by-partlabel/$(hostName)_ssd_efi -t TYPE=vfat || \
+ sudo mkfs.vfat -F 16 -s 1 -n EFI /dev/disk/by-partlabel/$(hostName)_ssd_efi
format-boot:
- sudo mkdir -p /mnt/$(machine)
- sudo blkid -t TYPE=ext2 /dev/disk/by-partlabel/$(machine)_ssd_boot; test $$? != 2 || \
- sudo mkfs.ext2 /dev/disk/by-partlabel/$(machine)_ssd_boot
+ sudo mkdir -p /mnt/$(hostName)
+ sudo blkid -t TYPE=ext2 /dev/disk/by-partlabel/$(hostName)_ssd_boot; test $$? != 2 || \
+ sudo mkfs.ext2 /dev/disk/by-partlabel/$(hostName)_ssd_boot
format-zpool:
sudo zpool list $(zpool) 2>/dev/null || \
sudo zpool create -o ashift=12 \
$(if $(cipher),-O encryption=$(cipher) \
-O keyformat=passphrase \
-O keylocation=prompt) \
- -R /mnt/$(machine) $(zpool) /dev/disk/by-partlabel/$(machine)_ssd_zpool
+ -R /mnt/$(hostName) $(zpool) /dev/disk/by-partlabel/$(hostName)_ssd_zpool
sudo zpool set \
autotrim=$(autotrim) \
$(zpool)
# /*
for p in \
home \
- home/documents \
+ home/Documents \
+ home/Images \
+ home/Videos \
nix \
var \
var/cache \
$(zpool)/"$$p" ; \
done
sudo zfs set sync=disabled $(zpool)/var/tmp
- sudo zfs set copies=2 $(zpool)/home/documents
+ sudo zfs set copies=2 $(zpool)/home/Documents
+ sudo zfs set compression=off $(zpool)/home/Images
+ sudo zfs set compression=off $(zpool)/home/Videos
mount: mount-zpool mount-boot mount-efi
mount-zpool:
grep -q '^$(zpool)\s*keystatus\s*available' || \
sudo zfs load-key $(zpool)
# /
- sudo mkdir -p /mnt/$(machine)
- sudo mountpoint /mnt/$(machine) || \
- sudo mount -v -t zfs $(zpool)/root /mnt/$(machine)
+ sudo mkdir -p /mnt/$(hostName)
+ sudo mountpoint /mnt/$(hostName) || \
+ sudo mount -v -t zfs $(zpool)/root /mnt/$(hostName)
# /*
for p in \
home \
var/log \
var/tmp \
; do \
- sudo mkdir -p /mnt/$(machine)/"$$p"; \
- sudo mountpoint /mnt/$(machine)/"$$p" || \
- sudo mount -v -t zfs $(zpool)/"$$p" /mnt/$(machine)/"$$p" ; \
+ sudo mkdir -p /mnt/$(hostName)/"$$p"; \
+ sudo mountpoint /mnt/$(hostName)/"$$p" || \
+ sudo mount -v -t zfs $(zpool)/"$$p" /mnt/$(hostName)/"$$p" ; \
done
- sudo chmod 1777 /mnt/$(machine)/var/tmp
+ sudo chmod 1777 /mnt/$(hostName)/var/tmp
mount-boot:
- sudo mkdir -p /mnt/$(machine)/boot
- sudo mountpoint /mnt/$(machine)/boot || \
- sudo mount -v /dev/disk/by-partlabel/$(machine)_ssd_boot /mnt/$(machine)/boot
- #sudo mount -v -t zfs bpool/boot /mnt/$(machine)/boot
+ sudo mkdir -p /mnt/$(hostName)/boot
+ sudo mountpoint /mnt/$(hostName)/boot || \
+ sudo mount -v /dev/disk/by-partlabel/$(hostName)_ssd_boot /mnt/$(hostName)/boot
+ #sudo mount -v -t zfs bpool/boot /mnt/$(hostName)/boot
mount-efi: | mount-boot
- sudo mkdir -p /mnt/$(machine)/boot/efi
- sudo mountpoint /mnt/$(machine)/boot/efi || \
- sudo mount -v /dev/disk/by-partlabel/$(machine)_ssd_efi /mnt/$(machine)/boot/efi
+ sudo mkdir -p /mnt/$(hostName)/boot/efi
+ sudo mountpoint /mnt/$(hostName)/boot/efi || \
+ sudo mount -v /dev/disk/by-partlabel/$(hostName)_ssd_efi /mnt/$(hostName)/boot/efi
bootstrap: mount
# Workaround https://dev.gnupg.org/T3908
sudo --preserve-env \
$$(which nixos-install) \
- --root /mnt/$(machine) \
- --flake '.#$(machine)' \
+ --root /mnt/$(hostName) \
+ --flake '../..#$(hostName)' \
--no-root-passwd \
--no-channel-copy \
--show-trace
boot/efi \
boot \
home \
- home/documents \
nix \
var/cache \
var/log \
var \
"" \
; do \
- ! sudo mountpoint /mnt/$(machine)/"$$p" || \
- sudo umount -v /mnt/$(machine)/"$$p" ; \
+ ! sudo mountpoint /mnt/$(hostName)/"$$p" || \
+ sudo umount -v /mnt/$(hostName)/"$$p" ; \
done
! sudo zpool list $(zpool) 2>/dev/null || \
zfs get -H encryption $(zpool) | \
#sudo zpool export bpool
! sudo zpool list $(zpool) 2>/dev/null || \
sudo zpool export $(zpool)
-
-unlock:
- pass machines/$(machine)/zfs/zpool | \
- NIXOPS_DEPLOYMENT="$${NIXOPS_DEPLOYMENT:-$(LOSURDO_DEPLOYMENT)}" \
- nixops ssh $(machine) -p 2222 'zfs load-key $(zpool) && pkill zfs'