# modules/hosts/laptop/ssd.nix## The spare SSD (LUKS2, btrfs) at /mnt/ssd, unlocked at boot from a key file# restored by hand once into /etc/secrets (root-only). `nofail`: the laptop# boots normally while the key or the drive is missing; the unit just fails.# Swap the key path for `none` to type the passphrase at boot instead.## `secure-vault` manages a further private container; its script is a# system secret (secrets/system/secure-vault.sh, host key + offline admin key# only, not the user's: see modules/hosts/laptop/sops.nix). Edit with# sudo env SOPS_AGE_KEY_FILE=/var/lib/sops-nix/key.txt TMPDIR=/dev/shm sops secrets/system/secure-vault.sh{ ... }:
{
flake.nixosModules.laptop-ssd= { config, pkgs, user, ... }:
let# The vault tool's script is a sops secret (secrets/system/secure-vault.sh),# decrypted root-only to /run/secrets at activation; this is its command.script= config.sops.secrets."secure-vault".path;
vault= pkgs.writeShellApplication {
name="secure-vault";
runtimeInputs=with pkgs; [ bash cryptsetup util-linux coreutils e2fsprogs psmisc gawk sops ];
text='' if (( EUID != 0 )); then exec /run/wrappers/bin/sudo "$0" "$@" fi export VAULT_OWNER=${user} SOPS_CONFIG=${../../../.sops.yaml} exec bash -o errexit -o nounset -o pipefail ${script} "$@" '';
};
in {
environment.systemPackages=with pkgs; [ cryptsetup btrfs-progs e2fsprogs keepassxc age restic vault ];
environment.etc.crypttab.text='' ssd UUID=8cd17d0f-adf3-430f-9d95-d17ef42df9b0 /etc/secrets/ssd.key luks,nofail '';
sops.secrets."secure-vault"= {
sopsFile=../../../secrets/system/secure-vault.sh;
format="binary";
mode="0500"; # root only: the wrapper runs it under sudo };
fileSystems."/mnt/ssd"= {
device="/dev/mapper/ssd";
fsType="btrfs";
options= [
"compress=zstd:3""noatime""nofail""x-systemd.device-timeout=10s" ];
};
}
;
}