fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
3.3 KiB116 linesraw
1{ config, lib, pkgs, ... }:
2let
3  cfg = config.programs.rbw;
4
5  jsonFormat = pkgs.formats.json { };
6
7  inherit (pkgs.stdenv.hostPlatform) isDarwin;
8
9  settingsModule = with lib;
10    types.submodule {
11      freeformType = jsonFormat.type;
12      options = {
13        email = mkOption {
14          type = types.str;
15          example = "name@example.com";
16          description = "The email address for your bitwarden account.";
17        };
18
19        base_url = mkOption {
20          type = with types; nullOr str;
21          default = null;
22          example = "bitwarden.example.com";
23          description =
24            "The base-url for a self-hosted bitwarden installation.";
25        };
26
27        identity_url = mkOption {
28          type = with types; nullOr str;
29          default = null;
30          example = "identity.example.com";
31          description = "The identity url for your bitwarden installation.";
32        };
33
34        lock_timeout = mkOption {
35          type = types.ints.unsigned;
36          default = 3600;
37          example = 300;
38          description = ''
39            The amount of time that your login information should be cached.
40          '';
41        };
42
43        pinentry = mkOption {
44          type = with types; either package (enum pkgs.pinentry.flavors);
45          example = "gnome3";
46          default = "gtk2";
47          description = ''
48            Which pinentry interface to use. Beware that
49            `pinentry-gnome3` may not work on non-Gnome
50            systems. You can fix it by adding the following to your
51            system configuration:
52            ```nix
53            services.dbus.packages = [ pkgs.gcr ];
54            ```
55            For this reason, the default is `gtk2` for
56            now.
57          '';
58          # we want the program in the config
59          apply = val:
60            if builtins.isString val then
61              "${pkgs.pinentry.${val}}/bin/pinentry"
62            else
63              "${val}/${val.binaryPath or "bin/pinentry"}";
64        };
65      };
66    };
67in {
68  meta.maintainers = with lib.hm.maintainers; [ ambroisie ];
69
70  options.programs.rbw = with lib; {
71    enable = mkEnableOption "rbw, a CLI Bitwarden client";
72
73    package = mkOption {
74      type = types.package;
75      default = pkgs.rbw;
76      defaultText = literalExpression "pkgs.rbw";
77      description = ''
78        Package providing the {command}`rbw` tool and its
79        {command}`rbw-agent` daemon.
80      '';
81    };
82
83    settings = mkOption {
84      type = types.nullOr settingsModule;
85      default = null;
86      example = literalExpression ''
87        {
88          email = "name@example.com";
89          lock_timeout = 300;
90          pinentry = "gnome3";
91        }
92      '';
93      description = ''
94        rbw configuration, if not defined the configuration will not be
95        managed by Home Manager.
96      '';
97    };
98  };
99
100  config = lib.mkIf cfg.enable (lib.mkMerge [
101    {
102      home.packages = [ cfg.package ];
103    }
104
105    # Only manage configuration if not empty
106    (lib.mkIf (cfg.settings != null && !isDarwin) {
107      xdg.configFile."rbw/config.json".source =
108        jsonFormat.generate "rbw-config.json" cfg.settings;
109    })
110
111    (lib.mkIf (cfg.settings != null && isDarwin) {
112      home.file."Library/Application Support/rbw/config.json".source =
113        jsonFormat.generate "rbw-config.json" cfg.settings;
114    })
115  ]);
116}