nixfiles/presets/nixos/serverEncryptedDrive.nix

79 lines
1.6 KiB
Nix
Raw Normal View History

{
2023-09-20 15:46:20 +01:00
self,
config,
2023-02-13 11:33:33 +00:00
tree,
2023-09-20 15:46:20 +01:00
lib,
pkgs,
...
2023-09-20 15:46:20 +01:00
}: let
inherit (lib.modules) mkForce;
inherit (lib.lists) optionals;
2023-09-20 15:46:20 +01:00
2024-03-10 17:26:18 +00:00
inherit (pkgs) system;
2023-09-20 15:46:20 +01:00
driveData = import "${self}/data/drives/encryptedDrive.nix";
in {
2023-09-18 03:56:58 +01:00
imports = with tree; [
profiles.sshd
];
2023-02-13 11:33:33 +00:00
2023-09-18 03:56:58 +01:00
boot = {
2023-09-20 15:46:20 +01:00
loader.supportsInitrdSecrets = true;
initrd = {
availableKernelModules =
[
"nvme"
"ahci"
"ehci_pci"
"xhci_pci"
"sd_mod"
"sr_mod"
"usbhid"
"dm_crypt"
"dm_mod"
"cryptd"
]
++ (optionals (system == "x86_64_linux") ["aesni_intel"]);
2023-09-20 15:46:20 +01:00
secrets = {
"/ssh_host_ed25519_key" = mkForce "/initrd_ssh_host_ed25519_key";
2023-09-20 15:46:20 +01:00
};
2023-09-20 15:46:20 +01:00
luks = {
forceLuksSupportInInitrd = true;
devices = {
"${driveData.mapperName}" = {
device = "${driveData.encryptedPath}";
preLVM = false;
allowDiscards = true;
};
};
};
};
initrd.network = {
enable = true;
ssh = {
enable = true;
port = 22;
authorizedKeys = config.users.users.root.openssh.authorizedKeys.keys;
hostKeys = ["/ssh_host_ed25519_key"];
};
postCommands = ''
echo 'cryptsetup-askpass' >> /root/.profile
'';
};
};
2023-09-18 03:56:58 +01:00
fileSystems = {
"/" = {
2023-09-20 15:46:20 +01:00
device = "${driveData.decryptedPath}";
fsType = "${driveData.unencryptedFSType}";
};
"/boot" = {
2023-09-20 15:46:20 +01:00
device = "${driveData.bootPath}";
fsType = "${driveData.bootFSType}";
};
};
}