aboutsummaryrefslogtreecommitdiff
path: root/modules/home/gpg/default.nix
blob: af08ae34b428e2237834de54bbd4ebd532cc949e (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
{
  config,
  pkgs,
  lib,
  ...
}:

let
  inherit (lib)
    mkOption
    types
    mkIf
    ;
  cfg = config.nx.programs.gpg;
in
{

  options.nx.programs.gpg = {
    enable = mkOption {
      description = "GNU Privacy Guard";
      type = types.bool;
      default = config.nx.programs.git.enable;
    };

    gpgKey = mkOption {
      description = "default gpg key";
      type = types.nullOr types.str;
      default = "";
    };

    pinentry = mkOption {
      description = "pinentry flavor";
      type = types.enum [
        "curses"
        "gnome3"
        "qt"
        "mac"
      ];
      default = if pkgs.stdenv.isDarwin then "mac" else "curses";
    };
  };

  config = lib.mkIf cfg.enable {
    programs.gpg = {
      enable = true;
      #settings.default-key = mkIf (cfg.gpgKey != null) cfg.gpgKey;
    };

    services.gpg-agent = {
      enable = true;
      pinentry.package =
        if cfg.pinentry == "gnome3" then
          pkgs.pinentry-gnome3
        else if cfg.pinentry == "qt" then
          pkgs.pinentry-qt
        else if cfg.pinentry == "mac" then
          pkgs.pinentry_mac
        else
          pkgs.pinentry-curses;
    };
  };
}