Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zwave-js: module init, zwave-js-server: init at 1.33.0 #230380

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nixos/doc/manual/release-notes/rl-2311.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@

- hardware/infiniband.nix adds infiniband subnet manager support using an [opensm](https://github.com/linux-rdma/opensm) systemd-template service, instantiated on card guids. The module also adds kernel modules and cli tooling to help administrators debug and measure performance. Available as [hardware.infiniband.enable](#opt-hardware.infiniband.enable).

- [zwave-js](https://github.com/zwave-js/zwave-js-server), a small server wrapper around Z-Wave JS to access it via a WebSocket. Available as [services.zwave-js](#opt-services.zwave-js.enable).

- [Honk](https://humungus.tedunangst.com/r/honk), a complete ActivityPub server with minimal setup and support costs.
Available as [services.honk](#opt-services.honk.enable).

Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@
./services/home-automation/home-assistant.nix
./services/home-automation/homeassistant-satellite.nix
./services/home-automation/zigbee2mqtt.nix
./services/home-automation/zwave-js.nix
./services/logging/SystemdJournal2Gelf.nix
./services/logging/awstats.nix
./services/logging/filebeat.nix
Expand Down
152 changes: 152 additions & 0 deletions nixos/modules/services/home-automation/zwave-js.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{config, pkgs, lib, ...}:

with lib;

let
cfg = config.services.zwave-js;
mergedConfigFile = "/run/zwave-js/config.json";
settingsFormat = pkgs.formats.json {};
in {
options.services.zwave-js = {
enable = mkEnableOption (mdDoc "the zwave-js server on boot");

package = mkPackageOptionMD pkgs "zwave-js-server" { };

port = mkOption {
type = types.port;
default = 3000;
description = mdDoc ''
Port for the server to listen on.
'';
};

serialPort = mkOption {
type = types.path;
description = mdDoc ''
Serial port device path for Z-Wave controller.
'';
example = "/dev/ttyUSB0";
};

secretsConfigFile = mkOption {
type = types.path;
description = mdDoc ''
JSON file containing secret keys. A dummy example:

```
{
"securityKeys": {
"S0_Legacy": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"S2_Unauthenticated": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"S2_Authenticated": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
"S2_AccessControl": "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
}
}
```

See
<https://zwave-js.github.io/node-zwave-js/#/getting-started/security-s2>
for details. This file will be merged with the module-generated config
file (taking precedence).

Z-Wave keys can be generated with:

{command}`< /dev/urandom tr -dc A-F0-9 | head -c32 ;echo`


::: {.warning}
A file in the nix store should not be used since it will be readable to
all users.
:::
'';
example = "/secrets/zwave-js-keys.json";
};

settings = mkOption {
type = lib.types.submodule {
freeformType = settingsFormat.type;

options = {
storage = {
cacheDir = mkOption {
type = types.path;
default = "/var/cache/zwave-js";
graham33 marked this conversation as resolved.
Show resolved Hide resolved
readOnly = true;
description = lib.mdDoc "Cache directory";
};
};
};
};
default = {};
description = mdDoc ''
Configuration settings for the generated config
file.
'';
};

extraFlags = lib.mkOption {
type = with lib.types; listOf str;
default = [ ];
example = [ "--mock-driver" ];
description = lib.mdDoc ''
Extra flags to pass to command
'';
};
};

config = mkIf cfg.enable {
systemd.services.zwave-js = let
configFile = settingsFormat.generate "zwave-js-config.json" cfg.settings;
in {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
description = "Z-Wave JS Server";
serviceConfig = {
ExecStartPre = ''
/bin/sh -c "${pkgs.jq}/bin/jq -s '.[0] * .[1]' ${configFile} ${cfg.secretsConfigFile} > ${mergedConfigFile}"
'';
ExecStart = lib.concatStringsSep " " [
"${cfg.package}/bin/zwave-server"
"--config ${mergedConfigFile}"
"--port ${toString cfg.port}"
cfg.serialPort
(escapeShellArgs cfg.extraFlags)
];
Restart = "on-failure";
User = "zwave-js";
mweinelt marked this conversation as resolved.
Show resolved Hide resolved
SupplementaryGroups = [ "dialout" ];
CacheDirectory = "zwave-js";
RuntimeDirectory = "zwave-js";

# Hardening
CapabilityBoundingSet = "";
DeviceAllow = [cfg.serialPort];
DevicePolicy = "closed";
DynamicUser = true;
LockPersonality = true;
MemoryDenyWriteExecute = false;
NoNewPrivileges = true;
PrivateUsers = true;
PrivateTmp = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
RemoveIPC = true;
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
SystemCallFilter = [
"@system-service @pkey"
"~@privileged @resources"
];
UMask = "0077";
};
};
};

meta.maintainers = with lib.maintainers; [ graham33 ];
}
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -932,4 +932,5 @@ in {
zram-generator = handleTest ./zram-generator.nix {};
zrepl = handleTest ./zrepl.nix {};
zsh-history = handleTest ./zsh-history.nix {};
zwave-js = handleTest ./zwave-js.nix {};
}
31 changes: 31 additions & 0 deletions nixos/tests/zwave-js.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import ./make-test-python.nix ({ pkgs, lib, ...} :

let
secretsConfigFile = pkgs.writeText "secrets.json" (builtins.toJSON {
securityKeys = {
"S0_Legacy" = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
};
});
in {
name = "zwave-js";
meta.maintainers = with lib.maintainers; [ graham33 ];

nodes = {
machine = { config, ... }: {
services.zwave-js = {
enable = true;
serialPort = "/dev/null";
extraFlags = ["--mock-driver"];
inherit secretsConfigFile;
};
};
};

testScript = ''
start_all()

machine.wait_for_unit("zwave-js.service")
machine.wait_for_open_port(3000)
graham33 marked this conversation as resolved.
Show resolved Hide resolved
machine.wait_until_succeeds("journalctl --since -1m --unit zwave-js --grep 'ZwaveJS server listening'")
'';
})
36 changes: 36 additions & 0 deletions pkgs/by-name/zw/zwave-js-server/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ lib
, buildNpmPackage
, fetchFromGitHub
, nixosTests
}:

buildNpmPackage rec {
pname = "zwave-js-server";
version = "1.33.0";

src = fetchFromGitHub {
owner = "zwave-js";
repo = pname;
rev = version;
hash = "sha256-Lll3yE1v4ybJTjKO8dhPXMD/3VCn+9+fpnN7XczqaE4=";
};

npmDepsHash = "sha256-Re9fo+9+Z/+UGyDPlNWelH/4tLxcITPYXOCddQE9YDY=";

# For some reason the zwave-js dependency is in devDependencies
npmFlags = [ "--include=dev" ];

passthru = {
tests = {
inherit (nixosTests) zwave-js;
};
};

meta = {
changelog = "https://github.com/zwave-js/zwave-js-server/releases/tag/${version}";
description = "Small server wrapper around Z-Wave JS to access it via a WebSocket";
license = lib.licenses.asl20;
homepage = "https://github.com/zwave-js/zwave-js-server";
maintainers = with lib.maintainers; [ graham33 ];
};
}
1 change: 1 addition & 0 deletions pkgs/development/node-packages/aliases.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ mapAliases {
"@mermaid-js/mermaid-cli" = pkgs.mermaid-cli; # added 2023-10-01
"@nerdwallet/shepherd" = pkgs.shepherd; # added 2023-09-30
"@nestjs/cli" = pkgs.nest-cli; # Added 2023-05-06
"@zwave-js/server" = pkgs.zwave-js-server; # Added 2023-09-09
alloy = pkgs.titanium-alloy; # added 2023-08-17
antennas = pkgs.antennas; # added 2023-07-30
inherit (pkgs) asar; # added 2023-08-26
Expand Down
1 change: 0 additions & 1 deletion pkgs/development/node-packages/main-programs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,4 @@
vscode-html-languageserver-bin = "html-languageserver";
vscode-json-languageserver-bin = "json-languageserver";
webtorrent-cli = "webtorrent";
"@zwave-js/server" = "zwave-server";
}
1 change: 0 additions & 1 deletion pkgs/development/node-packages/node-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,4 @@
, "@yaegassy/coc-nginx"
, "yalc"
, "yarn"
, "@zwave-js/server"
graham33 marked this conversation as resolved.
Show resolved Hide resolved
]
Loading