Merge pull request #72320 from sweber83/sw-zigbee2mqtt

zigbee2mqtt package & module
This commit is contained in:
Lassulus 2020-07-21 05:23:43 +02:00 committed by GitHub
commit 72f66e7e42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 10786 additions and 0 deletions

View File

@ -345,6 +345,7 @@ in
zoneminder = 314; zoneminder = 314;
paperless = 315; paperless = 315;
#mailman = 316; # removed 2019-08-30 #mailman = 316; # removed 2019-08-30
zigbee2mqtt = 317;
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
@ -645,6 +646,7 @@ in
zoneminder = 314; zoneminder = 314;
paperless = 315; paperless = 315;
#mailman = 316; # removed 2019-08-30 #mailman = 316; # removed 2019-08-30
zigbee2mqtt = 317;
# When adding a gid, make sure it doesn't match an existing # When adding a gid, make sure it doesn't match an existing
# uid. Users and groups with the same name should have equal # uid. Users and groups with the same name should have equal

View File

@ -510,6 +510,7 @@
./services/misc/uhub.nix ./services/misc/uhub.nix
./services/misc/weechat.nix ./services/misc/weechat.nix
./services/misc/xmr-stak.nix ./services/misc/xmr-stak.nix
./services/misc/zigbee2mqtt.nix
./services/misc/zoneminder.nix ./services/misc/zoneminder.nix
./services/misc/zookeeper.nix ./services/misc/zookeeper.nix
./services/monitoring/alerta.nix ./services/monitoring/alerta.nix

View File

@ -0,0 +1,98 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.zigbee2mqtt;
configJSON = pkgs.writeText "configuration.json"
(builtins.toJSON (recursiveUpdate defaultConfig cfg.config));
configFile = pkgs.runCommand "configuration.yaml" { preferLocalBuild = true; } ''
${pkgs.remarshal}/bin/json2yaml -i ${configJSON} -o $out
'';
# the default config contains all required settings,
# so the service starts up without crashing.
defaultConfig = {
homeassistant = false;
permit_join = false;
mqtt = {
base_topic = "zigbee2mqtt";
server = "mqtt://localhost:1883";
};
serial.port = "/dev/ttyACM0";
# put device configuration into separate file because configuration.yaml
# is copied from the store on startup
devices = "devices.yaml";
};
in
{
meta.maintainers = with maintainers; [ sweber ];
options.services.zigbee2mqtt = {
enable = mkEnableOption "enable zigbee2mqtt service";
package = mkOption {
description = "Zigbee2mqtt package to use";
default = pkgs.zigbee2mqtt.override {
dataDir = cfg.dataDir;
};
defaultText = "pkgs.zigbee2mqtt";
type = types.package;
};
dataDir = mkOption {
description = "Zigbee2mqtt data directory";
default = "/var/lib/zigbee2mqtt";
type = types.path;
};
config = mkOption {
default = {};
type = with types; nullOr attrs;
example = literalExample ''
{
homeassistant = config.services.home-assistant.enable;
permit_join = true;
serial = {
port = "/dev/ttyACM1";
};
}
'';
description = ''
Your <filename>configuration.yaml</filename> as a Nix attribute set.
'';
};
};
config = mkIf (cfg.enable) {
systemd.services.zigbee2mqtt = {
description = "Zigbee2mqtt Service";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = "${cfg.package}/bin/zigbee2mqtt";
User = "zigbee2mqtt";
WorkingDirectory = cfg.dataDir;
Restart = "on-failure";
ProtectSystem = "strict";
ReadWritePaths = cfg.dataDir;
PrivateTmp = true;
RemoveIPC = true;
};
preStart = ''
cp --no-preserve=mode ${configFile} "${cfg.dataDir}/configuration.yaml"
'';
};
users.users.zigbee2mqtt = {
home = cfg.dataDir;
createHome = true;
group = "zigbee2mqtt";
extraGroups = [ "dialout" ];
uid = config.ids.uids.zigbee2mqtt;
};
users.groups.zigbee2mqtt.gid = config.ids.gids.zigbee2mqtt;
};
}

View File

@ -0,0 +1,19 @@
import ./make-test-python.nix ({ pkgs, ... }:
{
machine = { pkgs, ... }:
{
services.zigbee2mqtt = {
enable = true;
};
};
testScript = ''
machine.wait_for_unit("zigbee2mqtt.service")
machine.wait_until_fails("systemctl status zigbee2mqtt.service")
machine.succeed(
"journalctl -eu zigbee2mqtt | grep \"Error: Error while opening serialport 'Error: Error: No such file or directory, cannot open /dev/ttyACM0'\""
)
'';
}
)

View File

@ -0,0 +1,33 @@
{ pkgs, stdenv, system, dataDir ? "/opt/zigbee2mqtt/data" }:
let
package = (import ./node.nix { inherit pkgs system; }).package;
in
package.override rec {
version = "1.14.1";
reconstructLock = true;
postInstall = ''
sed -i '1s;^;#!/usr/bin/env node\n;' $out/lib/node_modules/zigbee2mqtt/index.js
chmod +x $out/lib/node_modules/zigbee2mqtt/index.js
mkdir $out/bin
ln -s $out/lib/node_modules/zigbee2mqtt/index.js $out/bin/zigbee2mqtt
rm -rf $out/lib/node_modules/zigbee2mqtt/data
ln -s ${dataDir} $out/lib/node_modules/zigbee2mqtt/data
'';
src = pkgs.fetchFromGitHub {
owner = "Koenkk";
repo = "zigbee2mqtt";
rev = version;
sha256 = "1g1j634474m6arr3qyvf2bzmjh4qs02rhnfh0dlm8qz8rh3xj2rk";
};
meta = with pkgs.stdenv.lib; {
description = "Zigbee to MQTT bridge using zigbee-shepherd";
license = licenses.gpl3;
homepage = https://github.com/Koenkk/zigbee2mqtt;
maintainers = with maintainers; [ sweber ];
platforms = platforms.linux;
};
}

View File

@ -0,0 +1,15 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p nodePackages.node2nix nodejs-12_x
VERSION=1.14.1
ZIGBEE2MQTT=https://raw.githubusercontent.com/Koenkk/zigbee2mqtt/$VERSION
wget $ZIGBEE2MQTT/package.json
wget $ZIGBEE2MQTT/npm-shrinkwrap.json
node2nix --nodejs-12 \
-l npm-shrinkwrap.json \
-c node.nix \
--bypass-cache \
--no-copy-node-env \
--node-env ../../development/node-packages/node-env.nix
rm package.json npm-shrinkwrap.json

10599
pkgs/servers/zigbee2mqtt/node-packages.nix generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,17 @@
# This file has been generated by node2nix 1.8.0. Do not edit!
{pkgs ? import <nixpkgs> {
inherit system;
}, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-12_x"}:
let
nodeEnv = import ../../development/node-packages/node-env.nix {
inherit (pkgs) stdenv python2 utillinux runCommand writeTextFile;
inherit nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
};
in
import ./node-packages.nix {
inherit (pkgs) fetchurl fetchgit;
inherit nodeEnv;
}

View File

@ -26865,6 +26865,8 @@ in
zap = callPackage ../tools/networking/zap { }; zap = callPackage ../tools/networking/zap { };
zigbee2mqtt = callPackage ../servers/zigbee2mqtt { };
zopfli = callPackage ../tools/compression/zopfli { }; zopfli = callPackage ../tools/compression/zopfli { };
myEnvFun = callPackage ../misc/my-env { myEnvFun = callPackage ../misc/my-env {