-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provides systemd service and allows configuration of data directory
- Loading branch information
1 parent
a322c92
commit d0af082
Showing
5 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
inherit (lib) | ||
mkIf | ||
mkEnableOption | ||
mkOption | ||
mkPackageOption | ||
types | ||
; | ||
cfg = config.services.zwave-js-ui; | ||
in | ||
{ | ||
options.services.zwave-js-ui = { | ||
enable = mkEnableOption "zwave-js-ui"; | ||
|
||
package = mkPackageOption pkgs "zwave-js-ui" { }; | ||
|
||
serialPort = mkOption { | ||
type = types.path; | ||
description = '' | ||
Serial port for the Z-Wave controller. | ||
Only used to grant permissions to the device; must be additionally configured in the application | ||
''; | ||
example = "/dev/serial/by-id/usb-example"; | ||
}; | ||
|
||
settings = mkOption { | ||
type = with types; attrsOf (nullOr (oneOf [ str path package ])); | ||
description = '' | ||
Extra environment entries for the zwave-js-ui process. | ||
Check https://zwave-js.github.io/zwave-js-ui/#/guide/env-vars for more information | ||
''; | ||
example = { HOST = "::"; PORT = "8091"; }; | ||
}; | ||
}; | ||
config = mkIf cfg.enable { | ||
systemd.services.zwave-js-ui = { | ||
environment = { | ||
STORE_DIR = "%S/zwave-js-ui"; | ||
ZWAVEJS_EXTERNAL_CONFIG = "%S/zwave-js-ui/.config-db"; | ||
} | ||
// cfg.settings; | ||
wantedBy = [ "multi-user.target" ]; | ||
serviceConfig = { | ||
ExecStart = "${cfg.package}/bin/zwave-js-ui"; | ||
RuntimeDirectory = "zwave-js-ui"; | ||
StateDirectory = "zwave-js-ui"; | ||
RootDirectory = "/run/zwave-js-ui"; | ||
BindReadOnlyPaths = [ | ||
"/etc" | ||
"/nix/store" | ||
]; | ||
BindPaths = [ "/var/lib/zwave-js-ui" ]; | ||
DeviceAllow = [ cfg.serialPort ]; | ||
DynamicUser = true; | ||
SupplementaryGroups = [ "dialout" ]; | ||
CapabilityBoundingSet = [ "" ]; | ||
RestrictAddressFamilies = "AF_INET AF_INET6"; | ||
DevicePolicy = "closed"; | ||
LockPersonality = true; | ||
MemoryDenyWriteExecute = false; | ||
NoNewPrivileges = true; | ||
PrivateUsers = true; | ||
PrivateTmp = true; | ||
ProtectClock = true; | ||
ProtectControlGroups = true; | ||
ProtectHome = true; | ||
ProtectHostname = true; | ||
ProtectKernelLogs = true; | ||
ProtectKernelModules = true; | ||
ProtectKernalTunables = true; | ||
ProtectProc = "invisible"; | ||
ProcSubset = "pid"; | ||
RemoveIPC = true; | ||
RestrictNamespaces = true; | ||
RestrictRealtime = true; | ||
RestrictSUIDSGID = true; | ||
SystemCallArchitectures = "native"; | ||
SystemCallFilter = [ | ||
"@system-service @pkey" | ||
"~@privileged @resources" | ||
]; | ||
UMask = "0077"; | ||
}; | ||
}; | ||
}; | ||
meta.maintainers = with lib.maintainers; [ cdombroski ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import ./make-test-python.nix ( | ||
{ lib, ... }: | ||
{ | ||
name = "zwave-js-ui"; | ||
meta.maintainers = with lib.maintainers; [ cdombroski ]; | ||
|
||
nodes = { | ||
machine = | ||
{ ... }: | ||
{ | ||
services.zwave-js-ui = { | ||
enable = true; | ||
serialPort = "/dev/null"; | ||
settings = { | ||
HOST = "::"; | ||
PORT = "9999"; | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
testScript = '' | ||
start_all() | ||
machine.wait_for_unit("zwave-js-ui.service") | ||
machine.wait_for_open_port(9999) | ||
machine.wait_until_succeeds("journalctl --since -1m --unit zwave-js-ui --grep 'Listening on port 9999host :: protocol HTTP'") | ||
machine.wait_for_file("/var/lib/zwave-js-ui/nodes.json") | ||
''; | ||
} | ||
) |