fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . papis ; 8 9defaultLibraries = remove null 10( mapAttrsToList ( n :v :if v . isDefault then n else null ) cfg . libraries ); 11 12settingsIni = ( lib . mapAttrs ( n :v :v . settings ) cfg . libraries ) // { 13settings = cfg . settings // { "default-library" = head defaultLibraries ; }; 14}; 15 16in { 17meta . maintainers = [ ]; 18 19options . programs . papis = { 20enable = mkEnableOption "papis" ; 21 22settings = mkOption { 23type = with types ; attrsOf ( oneOf [ bool int str ]); 24default = { }; 25example = literalExpression '' 26{ 27editor = "nvim"; 28file-browser = "ranger" 29add-edit = true; 30} 31'' ; 32description = '' 33Configuration written to 34{file}`$XDG_CONFIG_HOME/papis/config`. See 35<https://papis.readthedocs.io/en/latest/configuration.html> 36for supported values. 37'' ; 38}; 39 40libraries = mkOption { 41type = types . attrsOf ( types . submodule ({ config , name , ...} :{ 42options = { 43name = mkOption { 44type = types . str ; 45default = name ; 46readOnly = true ; 47description = "This library's name." ; 48}; 49 50isDefault = mkOption { 51type = types . bool ; 52default = false ; 53example = true ; 54description = '' 55Whether this is a default library. There must be exactly one 56default library. 57'' ; 58}; 59 60settings = mkOption { 61type = with types ; attrsOf ( oneOf [ bool int str ]); 62default = { }; 63example = literalExpression '' 64{ 65dir = "~/papers/"; 66} 67'' ; 68description = '' 69Configuration for this library. 70'' ; 71}; 72}; 73})); 74description = "Attribute set of papis libraries." ; 75}; 76}; 77 78config = mkIf cfg . enable { 79assertions = [{ 80assertion = cfg . libraries == { } || length defaultLibraries == 1 ; 81message = "Must have exactly one default papis library, but found " 82+ toString ( length defaultLibraries ) 83+ optionalString ( length defaultLibraries > 1 ) 84( ", namely " + concatStringsSep "," defaultLibraries ); 85}]; 86 87home . packages = [ pkgs . papis ]; 88 89xdg . configFile . "papis/config" = 90mkIf ( cfg . libraries != { }) { text = generators . toINI { } settingsIni ; }; 91}; 92}