diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-06-06 23:35:03 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-06-06 23:35:03 +0200 |
| commit | 64c9728e0c73e35787b2e69393a69c9d2815f936 (patch) | |
| tree | 05440a89e9d84e14f7e35d0a3044afa7bd605530 /modules/usbauth/default.nix | |
| parent | 32be6013555754aab30080e70792eea0a936c2a9 (diff) | |
update to 26.05
Diffstat (limited to 'modules/usbauth/default.nix')
| -rw-r--r-- | modules/usbauth/default.nix | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/modules/usbauth/default.nix b/modules/usbauth/default.nix index 1784221..7054efa 100644 --- a/modules/usbauth/default.nix +++ b/modules/usbauth/default.nix @@ -1,37 +1,41 @@ { - config, - lib, - modulesPath, - pkgs, - ... + config, + lib, + modulesPath, + pkgs, + ... }: { - imports = [ (modulesPath + "/profiles/all-hardware.nix") ]; + imports = [ (modulesPath + "/profiles/all-hardware.nix") ]; - options.usbauth = lib.mkOption { - description = "USB Auth"; - type = lib.types.submodule { - options = { - enable = lib.mkOption { type = lib.types.bool; }; - device = lib.mkOption { type = lib.types.str; }; - keyname = lib.mkOption { type = lib.types.str; }; - uuid = lib.mkOption { type = lib.types.str; }; - }; - }; - }; + options.usbauth = lib.mkOption { + description = "USB Auth"; + type = lib.types.submodule { + options = { + enable = lib.mkOption { type = lib.types.bool; default = false; }; + device = lib.mkOption { type = lib.types.str; }; + keyname = lib.mkOption { type = lib.types.str; }; + uuid = lib.mkOption { type = lib.types.str; }; + }; + }; + }; - config = lib.mkIf config.usbauth.enable { - boot.initrd.postDeviceCommands = pkgs.lib.mkBefore '' - mkdir -m 0755 -p /key - while ! findfs UUID=${config.usbauth.uuid} 2> /dev/null; do sleep 0.1; done > /dev/null - cryptsetup open $(findfs UUID=${config.usbauth.uuid}) _key - mount -o ro "/dev/mapper/_key" /key - ''; + config = lib.mkIf config.usbauth.enable { + boot.initrd.systemd.services.usb-auth-setup = { + description = "USBAuth Setup"; + before = [ "cryptsetup-pre.target" ]; - boot.initrd.luks.devices."${config.usbauth.device}" = { - keyFile = "/key/.keys/${config.usbauth.keyname}"; - preLVM = false; - }; - }; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.bash}/bin/bash ${./usbauth.sh} ${config.usbauth.uuid}"; + }; + + wantedBy = [ "sysinit.target" ]; + }; + + boot.initrd.luks.devices."${config.usbauth.device}" = { + keyFile = "/key/.keys/${config.usbauth.keyname}"; + }; + }; } |