blob: a56dac5371147cf0d6ad22d16a2372ecd685a2b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.spacebar;
toSpacebarConfig = opts:
concatStringsSep "\n" (mapAttrsToList
(p: v: "spacebar -m config ${p} ${toString v}") opts);
configFile = mkIf (cfg.config != {} || cfg.extraConfig != "")
"${pkgs.writeScript "spacebarrc" (
(if (cfg.config != {})
then "${toSpacebarConfig cfg.config}"
else "")
+ optionalString (cfg.extraConfig != "") cfg.extraConfig)}";
in
{
options = with types; {
services.spacebar.enable = mkOption {
type = bool;
default = false;
description = "Whether to enable the spacebar spacebar.";
};
services.spacebar.package = mkOption {
type = path;
description = "The spacebar package to use.";
};
services.spacebar.config = mkOption {
type = attrs;
default = {};
example = literalExpression ''
{
clock_format = "%R";
background_color = "0xff202020";
foreground_color = "0xffa8a8a8";
}
'';
description = ''
Key/Value pairs to pass to spacebar's 'config' domain, via the configuration file.
'';
};
services.spacebar.extraConfig = mkOption {
type = str;
default = "";
example = literalExpression ''
echo "spacebar config loaded..."
'';
description = ''
Extra arbitrary configuration to append to the configuration file.
'';
};
};
config = mkIf (cfg.enable) {
environment.systemPackages = [ cfg.package ];
launchd.user.agents.spacebar = {
serviceConfig.ProgramArguments = [ "${cfg.package}/bin/spacebar" ]
++ optionals (cfg.config != {} || cfg.extraConfig != "") [ "-c" configFile ];
serviceConfig.KeepAlive = true;
serviceConfig.RunAtLoad = true;
serviceConfig.EnvironmentVariables = {
PATH = "${cfg.package}/bin:${config.environment.systemPath}";
};
};
};
}
|