Here's an updated disko configuration that incorporates TPM2 for LUKS encryption:
{
disko.devices = {
disk = {
main = {
type = "disk";
device = "/dev/sda"; # Change this to your actual disk device
content = {
type = "gpt";
partitions = {
boot = {
size = "1M";
type = "EF02"; # BIOS boot partition for GRUB
};
ESP = {
size = "2G";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "defaults" ];
};
};
luks = {
size = "100%";
content = {
type = "luks";
name = "cryptroot";
settings = {
allowDiscards = true;
# TPM2 specific configuration
tpm2 = {
enable = true;
# PCR banks to seal the key to
pcrs = [ 0 1 2 3 7 ];
};
};
# Remove passwordFile if using pure TPM2
# passwordFile = "/tmp/secret.key";
content = {
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"@" = {
mountpoint = "/";
mountOptions = [ "compress=zstd" "noatime" ];
};
"@home" = {
mountpoint = "/home";
mountOptions = [ "compress=zstd" "noatime" ];
};
"@nix" = {
mountpoint = "/nix";
mountOptions = [ "compress=zstd" "noatime" ];
};
"@swap" = {
mountpoint = "/.swapvol";
swap.swapfile.size = "8G";
};
"@snapshots" = {
mountpoint = "/.snapshots";
mountOptions = [ "compress=zstd" "noatime" ];
};
};
};
};
};
};
};
};
};
};
}
Key changes for TPM2 support:
-
Added tpm2 configuration under settings:
enable = true; activates TPM2 support
pcrs = [ 0 1 2 3 7 ]; specifies which Platform Configuration Registers (PCRs) to use for sealing the key
-
Commented out passwordFile (optional - you can keep it as a fallback)
To fully implement this, you'll need to ensure:
- Your system has a TPM 2.0 module
- In your NixOS configuration, include:
{
security = {
tpm2 = {
enable = true;
pkcs11.enable = true; # Optional, for PKCS#11 support
tctiEnvironment.enable = true;
};
};
}
Considerations:
- TPM2 provides hardware-based encryption key protection
- PCRs help ensure the key is only unsealed in a trusted boot environment
- PCR selection (0,1,2,3,7) covers boot configuration, but you might adjust based on your specific security requirements
Note: This approach provides stronger security by binding the encryption key to the TPM and system state, making it harder to extract the key even if the drive is removed.