-
Notifications
You must be signed in to change notification settings - Fork 3
/
lightmeter.nix
70 lines (58 loc) · 1.51 KB
/
lightmeter.nix
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
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.lightmeter;
flags = concatStringsSep " " (mapAttrsToList
(flag: v: "-${flag}${optionalString (v != null) " ${toString v}"}")
cfg.flags);
in
{
options.services.lightmeter = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable the Lightmeter monitoring service
'';
};
port = mkOption {
type = types.int;
default = 8080;
description = ''
Port for Lightmeter to listen on
'';
};
flags = mkOption {
type = with types; attrsOf (nullOr (oneOf [ bool int float str path ]));
default = { };
description = ''
Command line options to pass to lightmeter
'';
};
};
config = mkIf cfg.enable {
services.lightmeter.flags = mapAttrs (_: mkDefault)
{
listen = ":${toString cfg.port}";
workspace = "/var/lib/lightmeter_workspace";
};
systemd.services.lightmeter = {
wantedBy = [ "multi-user.target" ];
description = "Lightmeter Monitoring Service";
serviceConfig = {
User = "lightmeter";
Group = "lightmeter";
StateDirectory = "lightmeter_workspace";
StateDirectoryMode = "0750";
ExecStart = "${pkgs.lightmeter}/bin/lightmeter ${flags}";
};
};
users = {
users.lightmeter = {
group = "lightmeter";
description = "Lightmeter user";
};
groups.lightmeter = { };
};
};
}