forked from pinpox/home-assistant-grafana-relay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
76 lines (64 loc) · 1.94 KB
/
module.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
71
72
73
74
75
76
{ lib, pkgs, config, inputs, ... }:
with lib;
let cfg = config.pinpox.services.home-assistant-grafana-relay;
in {
options.pinpox.services.home-assistant-grafana-relay = {
enable = mkEnableOption "home-assistant-grafana-relay service";
listenHost = mkOption {
type = types.str;
default = "localhost";
example = "127.0.0.1";
description = "Host to listen on";
};
listenPort = mkOption {
type = types.str;
default = "12000";
example = "1300";
description = "Port to listen on";
};
haUri = mkOption {
type = types.str;
default = null;
example = "http://home.domain.tld/api/services/notify/notify";
description = "URI of Home Assistant notification service";
};
envFile = mkOption {
type = types.str;
default = null;
example = "/var/secrets/ha-envfile";
description = ''
Additional environment file to pass to the service.
e.g. containing the long-lived access token as:
AUTH_TOKEN="LONG_LIVED_ACCESS_TOKEN"
'';
};
};
config = mkIf cfg.enable {
# User and group
users.users.ha-relay = {
isSystemUser = true;
description = "ha-relay system user";
extraGroups = [ "ha-relay" ];
group = "ha-relay";
};
users.groups.ha-relay = { name = "ha-relay"; };
# Service
systemd.services.ha-relay = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
description = "Start ha-relay";
serviceConfig = {
EnvironmentFile = [ cfg.envFile ];
Environment = [
"HM_SERVICE_URI='${cfg.haUri}'"
"LISTEN_PORT='${cfg.listenPort}'"
"LISTEN_HOST='${cfg.listenHost}'"
];
User = "ha-relay";
ExecStart = "${inputs.ha-relay.packages."${config.nixpkgs.system}".ha-relay}/bin/home-assistant-grafana-relay";
Restart = "on-failure";
RestartSec = "5s";
};
};
};
}