2024-12-03 19:55:58 +01:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
namespace,
|
|
|
|
...
|
|
|
|
}: with lib; with lib.${namespace};
|
|
|
|
let
|
|
|
|
cfg = config.${namespace}.security.yubikey;
|
2024-12-23 18:33:51 +01:00
|
|
|
in
|
2024-12-03 19:55:58 +01:00
|
|
|
{
|
|
|
|
options.${namespace}.security.yubikey = with types; {
|
|
|
|
enable = mkEnableOption "Enable the Yubikey as a security device.";
|
|
|
|
key-id = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
default = [ "30650551" ];
|
|
|
|
example = [ "123456" "1234567" ];
|
|
|
|
description = "Register additional Yubikey IDs.";
|
|
|
|
};
|
2024-12-23 18:33:51 +01:00
|
|
|
enable-agent = mkEnableOption "Enable the Yubikey agent";
|
2024-12-03 19:55:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = with pkgs; [ yubikey-manager yubioath-flutter ];
|
2024-12-14 00:45:35 +01:00
|
|
|
|
2024-12-03 19:55:58 +01:00
|
|
|
services.udev.packages = [ pkgs.yubikey-personalization ];
|
|
|
|
services.pcscd.enable = true;
|
|
|
|
|
|
|
|
programs.gnupg.agent = {
|
|
|
|
enable = true;
|
|
|
|
enableSSHSupport = true;
|
|
|
|
};
|
|
|
|
|
2024-12-14 00:45:35 +01:00
|
|
|
security.pam.services = {
|
|
|
|
login.u2fAuth = true;
|
|
|
|
sudo.u2fAuth = true;
|
2024-12-03 19:55:58 +01:00
|
|
|
};
|
2024-12-23 18:33:51 +01:00
|
|
|
|
|
|
|
services.yubikey-agent.enable = cfg.enable-agent;
|
|
|
|
|
|
|
|
programs.ssh.extraConfig = mkIf cfg.enable-agent ''
|
|
|
|
Host *
|
|
|
|
IdentityAgent /usr/local/var/run/yubikey-agent.sock
|
|
|
|
'';
|
|
|
|
|
|
|
|
environment.sessionVariables = mkIf cfg.enable-agent {
|
|
|
|
SSH_AUTH_SOCK = "/usr/local/var/run/yubikey-agent.sock";
|
|
|
|
};
|
2024-12-03 19:55:58 +01:00
|
|
|
};
|
2024-12-23 18:33:51 +01:00
|
|
|
}
|