fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
3.1 KiB104 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.xresources;
8
9  formatLine = n: v:
10    let
11      formatList = x:
12        if isList x then
13          throw "can not convert 2-dimensional lists to Xresources format"
14        else
15          formatValue x;
16
17      formatValue = v:
18        if isBool v then
19          (if v then "true" else "false")
20        else if isList v then
21          concatMapStringsSep ", " formatList v
22        else
23          toString v;
24    in "${n}: ${formatValue v}";
25
26  xrdbMerge = "${pkgs.xorg.xrdb}/bin/xrdb -merge ${cfg.path}";
27
28in {
29  meta.maintainers = [ maintainers.rycee ];
30
31  options = {
32    xresources.properties = mkOption {
33      type = with types;
34        let
35          prim = either bool (either int str);
36          entry = either prim (listOf prim);
37        in nullOr (attrsOf entry);
38      default = null;
39      example = literalExpression ''
40        {
41          "Emacs*toolBar" = 0;
42          "XTerm*faceName" = "dejavu sans mono";
43          "XTerm*charClass" = [ "37:48" "45-47:48" "58:48" "64:48" "126:48" ];
44        }
45      '';
46      description = ''
47        X server resources that should be set.
48        Booleans are formatted as "true" or "false" respectively.
49        List elements are recursively formatted as a string and joined by commas.
50        All other values are directly formatted using builtins.toString.
51        Note, that 2-dimensional lists are not supported and specifying one will throw an exception.
52        If this and all other xresources options are
53        `null`, then this feature is disabled and no
54        {file}`~/.Xresources` link is produced.
55      '';
56    };
57
58    xresources.extraConfig = mkOption {
59      type = types.lines;
60      default = "";
61      example = literalExpression ''
62        builtins.readFile (
63            pkgs.fetchFromGitHub {
64                owner = "solarized";
65                repo = "xresources";
66                rev = "025ceddbddf55f2eb4ab40b05889148aab9699fc";
67                sha256 = "0lxv37gmh38y9d3l8nbnsm1mskcv10g3i83j0kac0a2qmypv1k9f";
68            } + "/Xresources.dark"
69        )
70      '';
71      description = ''
72        Additional X server resources contents.
73        If this and all other xresources options are
74        `null`, then this feature is disabled and no
75        {file}`~/.Xresources` link is produced.
76      '';
77    };
78
79    xresources.path = mkOption {
80      type = types.str;
81      default = "${config.home.homeDirectory}/.Xresources";
82      defaultText = "$HOME/.Xresources";
83      description =
84        "Path where Home Manager should link the {file}`.Xresources` file.";
85    };
86  };
87
88  config = mkIf ((cfg.properties != null && cfg.properties != { })
89    || cfg.extraConfig != "") {
90      home.file.${cfg.path} = {
91        text = concatStringsSep "\n" ([ ]
92          ++ optional (cfg.extraConfig != "") cfg.extraConfig
93          ++ optionals (cfg.properties != null)
94          (mapAttrsToList formatLine cfg.properties)) + "\n";
95        onChange = ''
96          if [[ -v DISPLAY ]]; then
97            ${xrdbMerge}
98          fi
99        '';
100      };
101
102      xsession.initExtra = xrdbMerge;
103    };
104}