-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword-manager.nix
More file actions
70 lines (60 loc) · 1.77 KB
/
password-manager.nix
File metadata and controls
70 lines (60 loc) · 1.77 KB
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
{ config, lib, pkgs, userConfig ? {}, ... }:
with lib;
let
cfg = config.services.passwordManager;
normalUsers = builtins.attrNames (lib.filterAttrs
(name: user: user.isNormalUser)
config.users.users);
in
{
options.services.passwordManager = {
enable = mkEnableOption "password manager";
provider = mkOption {
type = types.enum [ "1password" "bitwarden" ];
default = "bitwarden";
description = "Which password manager to use";
};
email = mkOption {
type = types.str;
default = userConfig.email_address or "";
description = "Email address for password manager account";
};
gui = mkOption {
type = types.bool;
default = true;
description = "Whether to enable GUI applications";
};
cli = mkOption {
type = types.bool;
default = true;
description = "Whether to enable CLI tools";
};
};
config = mkIf cfg.enable (mkMerge [
# 1Password configuration
(mkIf (cfg.provider == "1password") {
programs._1password = mkIf cfg.cli {
enable = true;
};
programs._1password-gui = mkIf cfg.gui {
enable = true;
polkitPolicyOwners = normalUsers;
};
})
# Bitwarden configuration
(mkIf (cfg.provider == "bitwarden") {
environment.systemPackages = with pkgs;
(optional cfg.cli rbw) ++
(optional cfg.gui bitwarden-desktop);
# Optional: Configure rbw for CLI usage
environment.etc."rbw/config.json" = mkIf cfg.cli {
text = builtins.toJSON {
email = cfg.email;
base_url = "https://vault.bitwarden.com/";
identity_url = "https://identity.bitwarden.com/";
notifications_url = "https://notifications.bitwarden.com/";
};
};
})
]);
}