Created
June 2, 2024 15:39
-
-
Save clangley/00487e5ea07fc072788cb09d6af265e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Define disk | |
| DISK="/dev/sda" | |
| DISK_BOOT_PARTITION="/dev/sda1" | |
| DISK_NIX_PARTITION="/dev/sda2" | |
| # Undo any previous changes if applicable | |
| set +e | |
| umount -R /mnt | |
| cryptsetup close cryptroot | |
| set -e | |
| # Partitioning disk | |
| parted $DISK -- mklabel gpt | |
| parted $DISK -- mkpart ESP fat32 1MiB 512MiB | |
| parted $DISK -- set 1 boot on | |
| parted $DISK -- mkpart Nix 512MiB 100% | |
| # Setting up encryption | |
| cryptsetup -q -v luksFormat $DISK_NIX_PARTITION | |
| cryptsetup -q -v open $DISK_NIX_PARTITION cryptroot | |
| # Creating filesystems | |
| mkfs.fat -F32 -n boot $DISK_BOOT_PARTITION | |
| mkfs.ext4 -F -L nix -m 0 /dev/mapper/cryptroot | |
| # Let mkfs catch its breath | |
| sleep 2 | |
| # Mounting filesystems | |
| mount -t tmpfs none /mnt | |
| mkdir -pv /mnt/{boot,nix,etc/ssh,var/{lib,log}} | |
| mount /dev/disk/by-label/boot /mnt/boot | |
| mount /dev/disk/by-label/nix /mnt/nix | |
| mkdir -pv /mnt/nix/{secret/initrd,persist/{etc/ssh,var/{lib,log}}} | |
| chmod 0700 /mnt/nix/secret | |
| mount -o bind /mnt/nix/persist/var/log /mnt/var/log | |
| # Generating initrd SSH host key | |
| ssh-keygen -t ed25519 -N "" -C "" -f /mnt/nix/secret/initrd/ssh_host_ed25519_key | |
| # Creating public age key for sops-nix | |
| sudo nix-shell --extra-experimental-features flakes -p ssh-to-age --run 'cat /mnt/nix/secret/initrd/ssh_host_ed25519_key.pub | ssh-to-age' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment