-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.nix
79 lines (79 loc) · 1.91 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
77
78
79
{ lib, pkgs, config, ... }:
let
cfg = config.services.aprs2mqtt;
settingsFormat = pkgs.formats.yaml {};
consumerOpts = { name, ... }: with lib; {
options = {
filter = mkOption {
type = types.str;
description = "User defined filter";
example = "t/m";
};
topic = mkOption {
type = types.str;
description = "MQTT topic";
example = "aprs/message";
};
};
};
configFile = settingsFormat.generate "aprs2mqtt-config.yml" cfg;
in
{
options.services.aprs2mqtt = with lib; {
enable = mkEnableOption "aprs2mqtt";
aprs = {
host = mkOption {
type = types.str;
description = "APRS-IS host";
default = "rotate.aprs2.net";
};
port = mkOption {
type = types.int;
description = "APRS-IS port number";
default = 14580;
};
login = mkOption {
type = types.str;
description = "APRS-IS login";
};
};
mqtt = {
host = mkOption {
type = types.str;
description = "MQTT hostname";
default = "localhost";
};
port = mkOption {
type = types.int;
description = "MQTT port";
default = 1883;
};
user = mkOption {
type = types.str;
description = "MQTT username";
};
pass = mkOption {
type = types.str;
description = "MQTT password";
};
};
consumers = mkOption {
default = [ ];
type = with types; listOf (submodule consumerOpts);
example = [
{ filter = "t/m"; topic = "aprs/message"; }
];
};
};
config = lib.mkIf cfg.enable {
systemd.services.aprs2mqtt = {
description = "aprs2mqtt";
enable = true;
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = "${pkgs.aprs2mqtt}/bin/aprs2mqtt ${configFile}";
};
};
};
}