mirror of
https://github.com/nix-community/home-manager
synced 2024-11-10 07:04:17 +00:00
rbw: add module (#1998)
`rbw` is a stand-alone Bitwarden client, which makes use of a daemon to cache your password and manage state. Its configuration can be managed by `home-manager` or not, leaving the user free to configure it through `rbw config`.
This commit is contained in:
parent
5060262b79
commit
7591c8041d
10 changed files with 236 additions and 0 deletions
3
.github/CODEOWNERS
vendored
3
.github/CODEOWNERS
vendored
|
@ -150,6 +150,9 @@
|
||||||
|
|
||||||
/modules/programs/powerline-go.nix @DamienCassou
|
/modules/programs/powerline-go.nix @DamienCassou
|
||||||
|
|
||||||
|
/modules/programs/rbw.nix @ambroisie
|
||||||
|
/tests/modules/programs/rbw @ambroisie
|
||||||
|
|
||||||
/modules/programs/rofi.nix @thiagokokada
|
/modules/programs/rofi.nix @thiagokokada
|
||||||
/tests/modules/programs/rofi @thiagokokada
|
/tests/modules/programs/rofi @thiagokokada
|
||||||
|
|
||||||
|
|
|
@ -2047,6 +2047,13 @@ in
|
||||||
configuration file.
|
configuration file.
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
time = "2021-05-10T20:41:44+00:00";
|
||||||
|
message = ''
|
||||||
|
A new module is available: 'programs.rbw'.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,7 @@ let
|
||||||
(loadModule ./programs/pidgin.nix { })
|
(loadModule ./programs/pidgin.nix { })
|
||||||
(loadModule ./programs/powerline-go.nix { })
|
(loadModule ./programs/powerline-go.nix { })
|
||||||
(loadModule ./programs/qutebrowser.nix { })
|
(loadModule ./programs/qutebrowser.nix { })
|
||||||
|
(loadModule ./programs/rbw.nix { })
|
||||||
(loadModule ./programs/readline.nix { })
|
(loadModule ./programs/readline.nix { })
|
||||||
(loadModule ./programs/rofi.nix { })
|
(loadModule ./programs/rofi.nix { })
|
||||||
(loadModule ./programs/rofi-pass.nix { })
|
(loadModule ./programs/rofi-pass.nix { })
|
||||||
|
|
116
modules/programs/rbw.nix
Normal file
116
modules/programs/rbw.nix
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
{ 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";
|
||||||
|
description = "The email address for your bitwarden account.";
|
||||||
|
};
|
||||||
|
|
||||||
|
base_url = mkOption {
|
||||||
|
type = with types; nullOr str;
|
||||||
|
default = null;
|
||||||
|
example = "bitwarden.example.com";
|
||||||
|
description =
|
||||||
|
"The base-url for a self-hosted bitwarden installation.";
|
||||||
|
};
|
||||||
|
|
||||||
|
identity_url = mkOption {
|
||||||
|
type = with types; nullOr str;
|
||||||
|
default = null;
|
||||||
|
example = "identity.example.com";
|
||||||
|
description = "The identity url for your bitwarden installation.";
|
||||||
|
};
|
||||||
|
|
||||||
|
lock_timeout = mkOption {
|
||||||
|
type = types.ints.unsigned;
|
||||||
|
default = 3600;
|
||||||
|
example = 300;
|
||||||
|
description = ''
|
||||||
|
The amount of time that your login information should be cached.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
pinentry = mkOption {
|
||||||
|
type = with types; either package (enum pkgs.pinentry.flavors);
|
||||||
|
example = "gnome3";
|
||||||
|
default = "gtk2";
|
||||||
|
description = ''
|
||||||
|
Which pinentry interface to use. Beware that
|
||||||
|
<literal>pinentry-gnome3</literal> may not work on non-Gnome
|
||||||
|
systems. You can fix it by adding the following to your
|
||||||
|
system configuration:
|
||||||
|
<programlisting language="nix">
|
||||||
|
services.dbus.packages = [ pkgs.gcr ];
|
||||||
|
</programlisting>
|
||||||
|
For this reason, the default is <literal>gtk2</literal> for
|
||||||
|
now.
|
||||||
|
'';
|
||||||
|
# we want the program in the config
|
||||||
|
apply = val:
|
||||||
|
if builtins.isString val then
|
||||||
|
"${pkgs.pinentry.${val}}/bin/pinentry"
|
||||||
|
else
|
||||||
|
"${val}/bin/pinentry";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
meta.maintainers = with lib.hm.maintainers; [ ambroisie ];
|
||||||
|
|
||||||
|
options.programs.rbw = with lib; {
|
||||||
|
enable = mkEnableOption "rwb, a CLI Bitwarden client";
|
||||||
|
|
||||||
|
package = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
default = pkgs.rbw;
|
||||||
|
defaultText = literalExample "pkgs.rbw";
|
||||||
|
description = ''
|
||||||
|
Package providing the <command>rbw</command> tool and its
|
||||||
|
<command>rbw-agent</command> daemon.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
settings = mkOption {
|
||||||
|
type = types.nullOr settingsModule;
|
||||||
|
default = null;
|
||||||
|
example = literalExample ''
|
||||||
|
{
|
||||||
|
email = "name@example.com";
|
||||||
|
lock_timeout = 300;
|
||||||
|
pinentry = "gnome3";
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
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;
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
}
|
|
@ -102,6 +102,7 @@ import nmt {
|
||||||
./modules/programs/i3status-rust
|
./modules/programs/i3status-rust
|
||||||
./modules/programs/ncmpcpp-linux
|
./modules/programs/ncmpcpp-linux
|
||||||
./modules/programs/neovim # Broken package dependency on Darwin.
|
./modules/programs/neovim # Broken package dependency on Darwin.
|
||||||
|
./modules/programs/rbw
|
||||||
./modules/programs/rofi
|
./modules/programs/rofi
|
||||||
./modules/programs/rofi-pass
|
./modules/programs/rofi-pass
|
||||||
./modules/programs/waybar
|
./modules/programs/waybar
|
||||||
|
|
5
tests/modules/programs/rbw/default.nix
Normal file
5
tests/modules/programs/rbw/default.nix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
rbw-empty-settings = ./empty-settings.nix;
|
||||||
|
rbw-simple-settings = ./simple-settings.nix;
|
||||||
|
rbw-settings = ./settings.nix;
|
||||||
|
}
|
19
tests/modules/programs/rbw/empty-settings.nix
Normal file
19
tests/modules/programs/rbw/empty-settings.nix
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
let
|
||||||
|
inherit (pkgs.stdenv.hostPlatform) isDarwin;
|
||||||
|
|
||||||
|
path = if isDarwin then
|
||||||
|
"Library/Application Support/rbw/config.json"
|
||||||
|
else
|
||||||
|
".config/rbw/config.json";
|
||||||
|
in {
|
||||||
|
config = {
|
||||||
|
programs.rbw.enable = true;
|
||||||
|
|
||||||
|
nixpkgs.overlays = [ (import ./overlay.nix) ];
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertPathNotExists home-files/${path}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
12
tests/modules/programs/rbw/overlay.nix
Normal file
12
tests/modules/programs/rbw/overlay.nix
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
self: super: {
|
||||||
|
rbw = self.writeScriptBin "dummy-rbw" "";
|
||||||
|
pinentry = {
|
||||||
|
gnome3 = self.writeScriptBin "pinentry-gnome3" "" // {
|
||||||
|
outPath = "@pinentry-gnome3@";
|
||||||
|
};
|
||||||
|
gtk2 = self.writeScriptBin "pinentry-gtk2" "" // {
|
||||||
|
outPath = "@pinentry-gtk2@";
|
||||||
|
};
|
||||||
|
flavors = [ "gnome3" "gtk2" ];
|
||||||
|
};
|
||||||
|
}
|
39
tests/modules/programs/rbw/settings.nix
Normal file
39
tests/modules/programs/rbw/settings.nix
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
let
|
||||||
|
inherit (pkgs.stdenv.hostPlatform) isDarwin;
|
||||||
|
|
||||||
|
path = if isDarwin then
|
||||||
|
"Library/Application Support/rbw/config.json"
|
||||||
|
else
|
||||||
|
".config/rbw/config.json";
|
||||||
|
|
||||||
|
expected = pkgs.writeText "rbw-expected.json" ''
|
||||||
|
{
|
||||||
|
"base_url": "bitwarden.example.com",
|
||||||
|
"email": "name@example.com",
|
||||||
|
"identity_url": "identity.example.com",
|
||||||
|
"lock_timeout": 300,
|
||||||
|
"pinentry": "@pinentry-gnome3@/bin/pinentry"
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
in {
|
||||||
|
config = {
|
||||||
|
programs.rbw = {
|
||||||
|
enable = true;
|
||||||
|
settings = {
|
||||||
|
email = "name@example.com";
|
||||||
|
base_url = "bitwarden.example.com";
|
||||||
|
identity_url = "identity.example.com";
|
||||||
|
lock_timeout = 300;
|
||||||
|
pinentry = "gnome3";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
nixpkgs.overlays = [ (import ./overlay.nix) ];
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileExists home-files/${path}
|
||||||
|
assertFileContent home-files/${path} '${expected}'
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
33
tests/modules/programs/rbw/simple-settings.nix
Normal file
33
tests/modules/programs/rbw/simple-settings.nix
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
let
|
||||||
|
inherit (pkgs.stdenv.hostPlatform) isDarwin;
|
||||||
|
|
||||||
|
path = if isDarwin then
|
||||||
|
"Library/Application Support/rbw/config.json"
|
||||||
|
else
|
||||||
|
".config/rbw/config.json";
|
||||||
|
|
||||||
|
expected = pkgs.writeText "rbw-expected.json" ''
|
||||||
|
{
|
||||||
|
"base_url": null,
|
||||||
|
"email": "name@example.com",
|
||||||
|
"identity_url": null,
|
||||||
|
"lock_timeout": 3600,
|
||||||
|
"pinentry": "@pinentry-gtk2@/bin/pinentry"
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
in {
|
||||||
|
config = {
|
||||||
|
programs.rbw = {
|
||||||
|
enable = true;
|
||||||
|
settings = { email = "name@example.com"; };
|
||||||
|
};
|
||||||
|
|
||||||
|
nixpkgs.overlays = [ (import ./overlay.nix) ];
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileExists home-files/${path}
|
||||||
|
assertFileContent home-files/${path} '${expected}'
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue