fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
1.8 KiB68 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.pam;
8
9in {
10  meta.maintainers = with maintainers; [ rycee veehaitch ];
11
12  options = {
13    pam.sessionVariables = mkOption {
14      default = { };
15      type = types.attrs;
16      example = { EDITOR = "vim"; };
17      description = ''
18        Environment variables that will be set for the PAM session.
19        The variable values must be as described in
20        {manpage}`pam_env.conf(5)`.
21
22        Note, this option will become deprecated in the future and its use is
23        therefore discouraged.
24      '';
25    };
26
27    pam.yubico.authorizedYubiKeys = {
28      ids = mkOption {
29        type = with types;
30          let
31            yubiKeyId = addCheck str (s: stringLength s == 12) // {
32              name = "yubiKeyId";
33              description = "string of length 12";
34            };
35          in listOf yubiKeyId;
36        default = [ ];
37        description = ''
38          List of authorized YubiKey token IDs. Refer to
39          <https://developers.yubico.com/yubico-pam>
40          for details on how to obtain the token ID of a YubiKey.
41        '';
42      };
43
44      path = mkOption {
45        type = types.str;
46        default = ".yubico/authorized_yubikeys";
47        description = ''
48          File path to write the authorized YubiKeys,
49          relative to {env}`HOME`.
50        '';
51      };
52    };
53  };
54
55  config = mkMerge [
56    (mkIf (cfg.sessionVariables != { }) {
57      home.file.".pam_environment".text = concatStringsSep "\n"
58        (mapAttrsToList (n: v: ''${n} OVERRIDE="${toString v}"'')
59          cfg.sessionVariables) + "\n";
60    })
61
62    (mkIf (cfg.yubico.authorizedYubiKeys.ids != [ ]) {
63      home.file.${cfg.yubico.authorizedYubiKeys.path}.text =
64        concatStringsSep ":"
65        ([ config.home.username ] ++ cfg.yubico.authorizedYubiKeys.ids);
66    })
67  ];
68}