2021-06-06 02:09:02 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.programs.rbw;
|
|
|
|
|
|
|
|
jsonFormat = pkgs.formats.json { };
|
|
|
|
|
|
|
|
inherit (pkgs.stdenv.hostPlatform) isDarwin;
|
|
|
|
|
|
|
|
settingsModule = with lib;
|
|
|
|
types.submodule {
|
|
|
|
freeformType = jsonFormat.type;
|
|
|
|
options = {
|
|
|
|
email = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "name@example.com";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The email address for your bitwarden account.";
|
2021-06-06 02:09:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
base_url = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
example = "bitwarden.example.com";
|
|
|
|
description =
|
2023-07-02 01:45:18 +02:00
|
|
|
"The base-url for a self-hosted bitwarden installation.";
|
2021-06-06 02:09:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
identity_url = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
example = "identity.example.com";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The identity url for your bitwarden installation.";
|
2021-06-06 02:09:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
lock_timeout = mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 3600;
|
|
|
|
example = 300;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-06-06 02:09:02 +02:00
|
|
|
The amount of time that your login information should be cached.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
pinentry = mkOption {
|
2024-03-10 11:24:45 +01:00
|
|
|
type = types.nullOr types.package;
|
|
|
|
example = literalExpression "pkgs.pinentry-gnome3";
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-06-06 02:09:02 +02:00
|
|
|
Which pinentry interface to use. Beware that
|
2023-07-01 01:30:13 +02:00
|
|
|
`pinentry-gnome3` may not work on non-Gnome
|
2021-06-06 02:09:02 +02:00
|
|
|
systems. You can fix it by adding the following to your
|
|
|
|
system configuration:
|
2023-07-01 01:30:13 +02:00
|
|
|
```nix
|
2021-06-06 02:09:02 +02:00
|
|
|
services.dbus.packages = [ pkgs.gcr ];
|
2023-07-01 01:30:13 +02:00
|
|
|
```
|
2021-06-06 02:09:02 +02:00
|
|
|
'';
|
|
|
|
# we want the program in the config
|
2024-03-10 11:24:45 +01:00
|
|
|
apply = val: if val == null then val else lib.getExe val;
|
2021-06-06 02:09:02 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
meta.maintainers = with lib.hm.maintainers; [ ambroisie ];
|
|
|
|
|
|
|
|
options.programs.rbw = with lib; {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "rbw, a CLI Bitwarden client";
|
2021-06-06 02:09:02 +02:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.rbw;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.rbw";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Package providing the {command}`rbw` tool and its
|
|
|
|
{command}`rbw-agent` daemon.
|
2021-06-06 02:09:02 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.nullOr settingsModule;
|
|
|
|
default = null;
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-06-06 02:09:02 +02:00
|
|
|
{
|
|
|
|
email = "name@example.com";
|
|
|
|
lock_timeout = 300;
|
2024-03-10 11:24:45 +01:00
|
|
|
pinentry = pkgs.pinentry-gnome3;
|
2021-06-06 02:09:02 +02:00
|
|
|
}
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-06-06 02:09:02 +02:00
|
|
|
rbw configuration, if not defined the configuration will not be
|
|
|
|
managed by Home Manager.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable (lib.mkMerge [
|
|
|
|
{
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
}
|
|
|
|
|
|
|
|
# Only manage configuration if not empty
|
|
|
|
(lib.mkIf (cfg.settings != null && !isDarwin) {
|
|
|
|
xdg.configFile."rbw/config.json".source =
|
|
|
|
jsonFormat.generate "rbw-config.json" cfg.settings;
|
|
|
|
})
|
|
|
|
|
|
|
|
(lib.mkIf (cfg.settings != null && isDarwin) {
|
|
|
|
home.file."Library/Application Support/rbw/config.json".source =
|
|
|
|
jsonFormat.generate "rbw-config.json" cfg.settings;
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|