Created
November 13, 2022 07:07
-
-
Save NickCao/4fa2f532a3ec71ba9a8ff9e3ef9ef1e4 to your computer and use it in GitHub Desktop.
LUKS and udevadm cleanup
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
{ | |
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small"; | |
outputs = { self, nixpkgs }: with nixpkgs.legacyPackages.x86_64-linux;{ | |
packages.x86_64-linux.default = nixosTest { | |
name = "luks-udev"; | |
nodes.machine = { pkgs, lib, ... }: { | |
virtualisation = { | |
emptyDiskImages = [ 512 ]; | |
useBootLoader = true; | |
useEFIBoot = true; | |
}; | |
environment.systemPackages = with pkgs; [ cryptsetup ]; | |
boot.loader.systemd-boot.enable = true; | |
boot.initrd.systemd.enable = true; | |
specialisation.luks.configuration = { | |
boot.initrd.systemd.additionalUpstreamUnits = [ "initrd-udevadm-cleanup-db.service" ]; | |
boot.initrd.luks.devices = lib.mkVMOverride { | |
crypt.device = "/dev/vdc"; | |
}; | |
virtualisation.fileSystems."/crypt".device = "/dev/mapper/crypt"; | |
}; | |
}; | |
testScript = '' | |
machine.wait_for_unit("multi-user.target") | |
machine.succeed("echo -n supersecret | cryptsetup luksFormat -q --iter-time=1 /dev/vdc -") | |
machine.succeed("echo -n supersecret | cryptsetup open /dev/vdc crypt") | |
machine.succeed("mkfs.ext4 /dev/mapper/crypt") | |
machine.succeed("bootctl set-default nixos-generation-1-specialisation-luks.conf") | |
machine.succeed("sync") | |
machine.crash() | |
machine.start() | |
machine.wait_for_console_text("Please enter passphrase for disk crypt") | |
machine.send_console("supersecret\n") | |
machine.wait_for_unit("multi-user.target") | |
assert "/dev/mapper/crypt on /crypt type ext4" in machine.succeed("mount") | |
''; | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment