-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnara.nix
More file actions
107 lines (99 loc) · 3.39 KB
/
Copy pathnara.nix
File metadata and controls
107 lines (99 loc) · 3.39 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.nara;
in
{
options.services.nara = {
enable = lib.mkEnableOption "nara friendly network";
package = lib.mkOption {
type = lib.types.package;
default = (import ./default.nix).packages.${pkgs.stdenv.hostPlatform.system}.default;
description = "The nara package to use.";
};
instances = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule {
options = {
soul = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "The soul for this instance. Save this to preserve identity across hardware changes.";
};
httpAddr = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "HTTP server address (e.g. :8080 or 127.0.0.1:8080).";
};
publicUrl = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "Public URL for this nara's web UI.";
};
extraArgs = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "Extra arguments for this instance.";
};
};
});
default = { };
description = "Nara instances to run. Keys are instance names.";
example = lib.literalExpression ''
{
lily = { soul = "5Kd3NBqT..."; httpAddr = ":8080"; publicUrl = "https://lily.example.com"; };
rose = { }; # will generate new soul from hardware
}
'';
};
mqttHost = lib.mkOption {
type = lib.types.str;
default = "tcp://hass.eljojo.casa:1883";
description = "MQTT broker address.";
};
extraArgs = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "Extra arguments to pass to all nara instances.";
};
environmentFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = "Environment file containing MQTT_USER and MQTT_PASS.";
};
};
config = lib.mkIf cfg.enable {
users.users.nara = {
isSystemUser = true;
group = "nara";
};
users.groups.nara = { };
systemd.services =
let
makeService = name: instanceCfg: {
name = "nara-${name}";
value = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
description = "nara daemon ${name}";
serviceConfig = {
Type = "simple";
User = "nara";
ExecStart = "${cfg.package}/bin/nara -mqtt-host=${cfg.mqttHost}"
+ " -nara-id=${name}"
+ (lib.optionalString (instanceCfg.soul != null) " -soul=${instanceCfg.soul}")
+ (lib.optionalString (instanceCfg.httpAddr != null) " -http-addr=${instanceCfg.httpAddr}")
+ (lib.optionalString (instanceCfg.publicUrl != null) " -public-url=${instanceCfg.publicUrl}")
+ " " + (lib.concatStringsSep " " (cfg.extraArgs ++ instanceCfg.extraArgs));
Restart = "always";
RestartSec = 3;
EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile;
};
};
};
in lib.mapAttrs' makeService cfg.instances;
};
}