fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
3.3 KiB156 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  boolTrue = {
8    type = types.bool;
9    default = true;
10  };
11
12  number0 = {
13    type = types.int;
14    default = 0;
15  };
16
17  knownSettings = {
18    edge = {
19      type = types.enum [ "left" "right" "top" "bottom" "none" ];
20      default = "bottom";
21    };
22
23    align = {
24      type = types.enum [ "left" "right" "center" ];
25      default = "center";
26    };
27
28    margin = number0;
29    widthtype = {
30      type = types.enum [ "request" "pixel" "percent" ];
31      default = "percent";
32    };
33
34    width = {
35      type = types.int;
36      default = 100;
37    };
38
39    heighttype = {
40      type = types.enum [ "request" "pixel" ];
41      default = "pixel";
42    };
43
44    height = {
45      type = types.int;
46      default = 26;
47    };
48
49    SetDockType = boolTrue;
50
51    SetPartialStrut = boolTrue;
52
53    transparent = {
54      type = types.bool;
55      default = false;
56    };
57
58    alpha = {
59      type = types.int;
60      default = 127;
61    };
62
63    tint = {
64      type = types.str;
65      default = "0xFFFFFFFF";
66    };
67
68    distance = number0;
69
70    distancefrom = {
71      type = types.enum [ "left" "right" "top" "bottom" ];
72      default = "top";
73    };
74
75    expand = boolTrue;
76
77    padding = number0;
78
79    monitor = {
80      type = types.either types.ints.unsigned (types.enum [ "primary" ]);
81      default = 0;
82    };
83
84    iconspacing = number0;
85  };
86
87  cfg = config.services.trayer;
88
89in {
90  meta.maintainers = [ hm.maintainers.mager ];
91
92  options = {
93    services.trayer = {
94      enable = mkEnableOption
95        "trayer, the lightweight GTK2+ systray for UNIX desktops";
96
97      package = mkOption {
98        default = pkgs.trayer;
99        defaultText = literalExpression "pkgs.trayer";
100        type = types.package;
101        example = literalExpression "pkgs.trayer";
102        description = "The package to use for the trayer binary.";
103      };
104
105      settings = mkOption {
106        type = with types; attrsOf (nullOr (either str (either bool int)));
107        description = ''
108          Trayer configuration as a set of attributes. Further details can be
109          found in [trayer's README](https://github.com/sargon/trayer-srg/blob/master/README).
110
111          ${concatStringsSep "\n" (mapAttrsToList (n: v: ''
112            {var}`${n}`
113            : ${v.type.description} (default: `${builtins.toJSON v.default}`)
114          '') knownSettings)}
115        '';
116        default = { };
117        example = literalExpression ''
118          {
119            edge = "top";
120            padding = 6;
121            SetDockType = true;
122            tint = "0x282c34";
123          }
124        '';
125      };
126    };
127  };
128
129  config = mkIf cfg.enable ({
130    assertions = [
131      (lib.hm.assertions.assertPlatform "services.trayer" pkgs
132        lib.platforms.linux)
133    ];
134
135    home.packages = [ cfg.package ];
136
137    systemd.user.services.trayer = let
138      valueToString = v:
139        if isBool v then (if v then "true" else "false") else "${toString v}";
140      parameter = k: v: "--${k} ${valueToString v}";
141      parameters = concatStringsSep " " (mapAttrsToList parameter cfg.settings);
142    in {
143      Unit = {
144        Description = "trayer -- lightweight GTK2+ systray for UNIX desktops";
145        PartOf = [ "tray.target" ];
146      };
147
148      Install.WantedBy = [ "tray.target" ];
149
150      Service = {
151        ExecStart = "${cfg.package}/bin/trayer ${parameters}";
152        Restart = "on-failure";
153      };
154    };
155  });
156}