1{ lib, pkgs, config, ... }:
2
3with lib;
4
5let
6 cfg = config.programs.yabar;
7
8 mapExtra = v: lib.concatStringsSep "\n" (mapAttrsToList (
9 key: val: "${key} = ${if (isString val) then "\"${val}\"" else "${builtins.toString val}"};"
10 ) v);
11
12 listKeys = r: concatStringsSep "," (map (n: "\"${n}\"") (attrNames r));
13
14 configFile = let
15 bars = mapAttrsToList (
16 name: cfg: ''
17 ${name}: {
18 font: "${cfg.font}";
19 position: "${cfg.position}";
20
21 ${mapExtra cfg.extra}
22
23 block-list: [${listKeys cfg.indicators}]
24
25 ${concatStringsSep "\n" (mapAttrsToList (
26 name: cfg: ''
27 ${name}: {
28 exec: "${cfg.exec}";
29 align: "${cfg.align}";
30 ${mapExtra cfg.extra}
31 };
32 ''
33 ) cfg.indicators)}
34 };
35 ''
36 ) cfg.bars;
37 in pkgs.writeText "yabar.conf" ''
38 bar-list = [${listKeys cfg.bars}];
39 ${concatStringsSep "\n" bars}
40 '';
41in
42 {
43 options.programs.yabar = {
44 enable = mkEnableOption "yabar";
45
46 package = mkOption {
47 default = pkgs.yabar;
48 example = literalExample "pkgs.yabar-unstable";
49 type = types.package;
50
51 description = ''
52 The package which contains the `yabar` binary.
53
54 Nixpkgs provides the `yabar` and `yabar-unstable`
55 derivations since 18.03, so it's possible to choose.
56 '';
57 };
58
59 bars = mkOption {
60 default = {};
61 type = types.attrsOf(types.submodule {
62 options = {
63 font = mkOption {
64 default = "sans bold 9";
65 example = "Droid Sans, FontAwesome Bold 9";
66 type = types.string;
67
68 description = ''
69 The font that will be used to draw the status bar.
70 '';
71 };
72
73 position = mkOption {
74 default = "top";
75 example = "bottom";
76 type = types.enum [ "top" "bottom" ];
77
78 description = ''
79 The position where the bar will be rendered.
80 '';
81 };
82
83 extra = mkOption {
84 default = {};
85 type = types.attrsOf types.string;
86
87 description = ''
88 An attribute set which contains further attributes of a bar.
89 '';
90 };
91
92 indicators = mkOption {
93 default = {};
94 type = types.attrsOf(types.submodule {
95 options.exec = mkOption {
96 example = "YABAR_DATE";
97 type = types.string;
98 description = ''
99 The type of the indicator to be executed.
100 '';
101 };
102
103 options.align = mkOption {
104 default = "left";
105 example = "right";
106 type = types.enum [ "left" "center" "right" ];
107
108 description = ''
109 Whether to align the indicator at the left or right of the bar.
110 '';
111 };
112
113 options.extra = mkOption {
114 default = {};
115 type = types.attrsOf (types.either types.string types.int);
116
117 description = ''
118 An attribute set which contains further attributes of a indicator.
119 '';
120 };
121 });
122
123 description = ''
124 Indicators that should be rendered by yabar.
125 '';
126 };
127 };
128 });
129
130 description = ''
131 List of bars that should be rendered by yabar.
132 '';
133 };
134 };
135
136 config = mkIf cfg.enable {
137 systemd.user.services.yabar = {
138 description = "yabar service";
139 wantedBy = [ "graphical-session.target" ];
140 partOf = [ "graphical-session.target" ];
141
142 script = ''
143 ${cfg.package}/bin/yabar -c ${configFile}
144 '';
145
146 serviceConfig.Restart = "always";
147 };
148 };
149 }