fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

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