nixfiles/presets/nixos/serverEncryptedDrive.nix

81 lines
1.7 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) optional;
system = pkgs.system;
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"
]
++ (lib.optionals (system == "x86_64_linux") ["aesni_intel"]);
2023-09-20 15:46:20 +01:00
secrets = {
# This will need to be generated before install or installed with secrets-init
# To keep it same across reinstalls add the ssh key and pubkey to secrets module
2023-09-20 15:59:18 +01:00
"/ssh_host_ed25519_key" = "/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}";
};
};
}