From e74a392d7673aa563af197e7c38d34ce07c327d7 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 21 Dec 2020 22:38:49 -0500 Subject: [PATCH] Add modules/shell/bitwarden module For bitwarden-cli --- hosts/personal.nix | 3 +++ modules/shell/bitwarden.nix | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 modules/shell/bitwarden.nix diff --git a/hosts/personal.nix b/hosts/personal.nix index f8696285..7f7673dc 100644 --- a/hosts/personal.nix +++ b/hosts/personal.nix @@ -25,4 +25,7 @@ with lib; latitude = 55.88; longitude = 12.5; } else {}); + + ## + modules.shell.bitwarden.config.server = "p.v0.io"; } diff --git a/modules/shell/bitwarden.nix b/modules/shell/bitwarden.nix new file mode 100644 index 00000000..dfbaba81 --- /dev/null +++ b/modules/shell/bitwarden.nix @@ -0,0 +1,25 @@ +{ config, options, pkgs, lib, ... }: + +with lib; +with lib.my; +let cfg = config.modules.shell.bitwarden; +in { + options.modules.shell.bitwarden = with types; { + enable = mkBoolOpt false; + config = mkOpt attrs {}; + }; + + config = mkIf cfg.enable { + user.packages = with pkgs; [ + bitwarden-cli + ]; + + modules.shell.zsh.rcInit = "_cache bw completion --shell zsh; compdef _bw bw;"; + + system.userActivationScripts = mkIf (cfg.config != {}) { + initBitwarden = '' + ${concatStringsSep "\n" (mapAttrsToList (n: v: "bw config ${n} ${v}") cfg.config)} + ''; + }; + }; +}