summaryrefslogtreecommitdiff
path: root/modules/nixfiles/gnupg.nix
blob: 96c34ee368889e583f955d6c47036c39bf7fe5b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{
  config,
  lib,
  ...
}:
with lib; let
  cfg = config.nixfiles.modules.gnupg;
in {
  options.nixfiles.modules.gnupg = {
    enable = mkEnableOption "GnuPG";

    pinentry = mkOption {
      description = "Name of a pinentry implementation.";
      type = types.str;
      default = with config.nixfiles.modules;
        if kde.enable
        then "qt"
        else if gnome.enable
        then "gnome"
        else "curses";
    };
  };

  config = mkIf cfg.enable {
    hm = {
      programs.gpg = {
        enable = true;

        settings =
          {
            display-charset = "utf-8";
            enable-progress-filter = true;
            fixed-list-mode = true;
            keyid-format = "0xlong";
            no-comments = true;
            no-emit-version = true;
            no-greeting = true;
            with-fingerprint = true;
            throw-keyids = false;

            use-agent = true;

            armor = true;

            no-random-seed-file = true;

            list-options = "show-uid-validity";
            verify-options = "show-uid-validity";
          }
          // (let
            cipherAlgos = ["AES256" "AES192" "AES"];
            compressionAlgos = ["ZLIB" "BZIP2" "ZIP" "Uncompressed"];
            digestAlgos = ["SHA512" "SHA384" "SHA256" "SHA224"];

            cs = concatStringsSep " ";
          in {
            default-preference-list =
              cs (digestAlgos ++ cipherAlgos ++ compressionAlgos);

            personal-cipher-preferences = cs cipherAlgos;
            personal-compress-preferences = cs compressionAlgos;
            personal-digest-preferences = cs digestAlgos;

            s2k-cipher-algo = head cipherAlgos;
            s2k-digest-algo = head digestAlgos;

            digest-algo = head digestAlgos;
            cert-digest-algo = head digestAlgos;
          });
      };

      services.gpg-agent = {
        enable = true;

        enableSshSupport = true;
        enableScDaemon = false;

        defaultCacheTtl = 999999;
        defaultCacheTtlSsh = 999999;
        maxCacheTtl = 999999;
        maxCacheTtlSsh = 999999;

        grabKeyboardAndMouse = true;

        sshKeys = [my.pgp.grip];

        pinentryFlavor = cfg.pinentry;
      };
    };
  };
}