fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
2.1 KiB84 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.zathura;
8
9  formatLine = n: v:
10    let
11      formatValue = v:
12        if isBool v then (if v then "true" else "false") else toString v;
13    in ''set ${n}	"${formatValue v}"'';
14
15  formatMapLine = n: v: "map ${n}   ${toString v}";
16
17in {
18  meta.maintainers = [ maintainers.rprospero ];
19
20  options.programs.zathura = {
21    enable = mkEnableOption ''
22      Zathura, a highly customizable and functional document viewer
23      focused on keyboard interaction'';
24
25    package = mkOption {
26      type = types.package;
27      default = pkgs.zathura;
28      defaultText = "pkgs.zathura";
29      description = "The Zathura package to use";
30    };
31
32    options = mkOption {
33      default = { };
34      type = with types; attrsOf (either str (either bool int));
35      description = ''
36        Add {option}`:set` command options to zathura and make
37        them permanent. See
38        {manpage}`zathurarc(5)`
39        for the full list of options.
40      '';
41      example = {
42        default-bg = "#000000";
43        default-fg = "#FFFFFF";
44      };
45    };
46
47    mappings = mkOption {
48      default = { };
49      type = with types; attrsOf str;
50      description = ''
51        Add {option}`:map` mappings to zathura and make
52        them permanent. See
53        {manpage}`zathurarc(5)`
54        for the full list of possible mappings.
55
56        You can create a mode-specific mapping by specifying the mode before the key:
57        `"[normal] <C-b>" = "scroll left";`
58      '';
59      example = {
60        D = "toggle_page_mode";
61        "<Right>" = "navigate next";
62        "[fullscreen] <C-i>" = "zoom in";
63      };
64    };
65
66    extraConfig = mkOption {
67      type = types.lines;
68      default = "";
69      description = ''
70        Additional commands for zathura that will be added to the
71        {file}`zathurarc` file.
72      '';
73    };
74  };
75
76  config = mkIf cfg.enable {
77    home.packages = [ cfg.package ];
78
79    xdg.configFile."zathura/zathurarc".text = concatStringsSep "\n" ([ ]
80      ++ optional (cfg.extraConfig != "") cfg.extraConfig
81      ++ mapAttrsToList formatLine cfg.options
82      ++ mapAttrsToList formatMapLine cfg.mappings) + "\n";
83  };
84}