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