nixos/zigbee2mqtt: convert to rfc42 style settings
This commit is contained in:
parent
7ee53c0c4f
commit
e0f1e1f7bf
@ -692,6 +692,12 @@ environment.systemPackages = [
|
|||||||
<literal>skip-kernel-setup true</literal> and takes care of setting forwarding and rp_filter sysctls by itself as well
|
<literal>skip-kernel-setup true</literal> and takes care of setting forwarding and rp_filter sysctls by itself as well
|
||||||
as for each interface in <varname>services.babeld.interfaces</varname>.
|
as for each interface in <varname>services.babeld.interfaces</varname>.
|
||||||
</para>
|
</para>
|
||||||
|
</listitem>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
The <option>services.zigbee2mqtt.config</option> option has been renamed to <option>services.zigbee2mqtt.settings</option> and
|
||||||
|
now follows <link xlink:href="https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md">RFC 0042</link>.
|
||||||
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
</section>
|
</section>
|
||||||
|
@ -5,26 +5,8 @@ with lib;
|
|||||||
let
|
let
|
||||||
cfg = config.services.zigbee2mqtt;
|
cfg = config.services.zigbee2mqtt;
|
||||||
|
|
||||||
configJSON = pkgs.writeText "configuration.json"
|
format = pkgs.formats.yaml { };
|
||||||
(builtins.toJSON (recursiveUpdate defaultConfig cfg.config));
|
configFile = format.generate "zigbee2mqtt.yaml" cfg.settings;
|
||||||
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
|
in
|
||||||
{
|
{
|
||||||
meta.maintainers = with maintainers; [ sweber ];
|
meta.maintainers = with maintainers; [ sweber ];
|
||||||
@ -37,7 +19,11 @@ in
|
|||||||
default = pkgs.zigbee2mqtt.override {
|
default = pkgs.zigbee2mqtt.override {
|
||||||
dataDir = cfg.dataDir;
|
dataDir = cfg.dataDir;
|
||||||
};
|
};
|
||||||
defaultText = "pkgs.zigbee2mqtt";
|
defaultText = literalExample ''
|
||||||
|
pkgs.zigbee2mqtt {
|
||||||
|
dataDir = services.zigbee2mqtt.dataDir
|
||||||
|
}
|
||||||
|
'';
|
||||||
type = types.package;
|
type = types.package;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -47,9 +33,9 @@ in
|
|||||||
type = types.path;
|
type = types.path;
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkOption {
|
settings = mkOption {
|
||||||
|
type = format.type;
|
||||||
default = {};
|
default = {};
|
||||||
type = with types; nullOr attrs;
|
|
||||||
example = literalExample ''
|
example = literalExample ''
|
||||||
{
|
{
|
||||||
homeassistant = config.services.home-assistant.enable;
|
homeassistant = config.services.home-assistant.enable;
|
||||||
@ -61,11 +47,28 @@ in
|
|||||||
'';
|
'';
|
||||||
description = ''
|
description = ''
|
||||||
Your <filename>configuration.yaml</filename> as a Nix attribute set.
|
Your <filename>configuration.yaml</filename> as a Nix attribute set.
|
||||||
|
Check the <link xlink:href="https://www.zigbee2mqtt.io/information/configuration.html">documentation</link>
|
||||||
|
for possible options.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf (cfg.enable) {
|
config = mkIf (cfg.enable) {
|
||||||
|
|
||||||
|
# preset config values
|
||||||
|
services.zigbee2mqtt.settings = {
|
||||||
|
homeassistant = mkDefault config.services.home-assistant.enable;
|
||||||
|
permit_join = mkDefault false;
|
||||||
|
mqtt = {
|
||||||
|
base_topic = mkDefault "zigbee2mqtt";
|
||||||
|
server = mkDefault "mqtt://localhost:1883";
|
||||||
|
};
|
||||||
|
serial.port = mkDefault "/dev/ttyACM0";
|
||||||
|
# reference device configuration, that is kept in a separate file
|
||||||
|
# to prevent it being overwritten in the units ExecStartPre script
|
||||||
|
devices = mkDefault "devices.yaml";
|
||||||
|
};
|
||||||
|
|
||||||
systemd.services.zigbee2mqtt = {
|
systemd.services.zigbee2mqtt = {
|
||||||
description = "Zigbee2mqtt Service";
|
description = "Zigbee2mqtt Service";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
Loading…
Reference in New Issue
Block a user