diff --git a/services/deconz.nix b/services/deconz.nix index 8047ac9..cb79350 100644 --- a/services/deconz.nix +++ b/services/deconz.nix @@ -10,8 +10,7 @@ let cfg = config.local.services.deconz; name = "deconz"; stateDir = "/var/lib/${name}"; -in -{ +in { options.local.services.deconz = { enable = mkEnableOption "deCONZ, a ZigBee gateway"; @@ -54,10 +53,7 @@ in extraOpts = mkOption { type = types.listOf types.str; - default = [ - "--auto-connect=1" - "--dbg-info=1" - ]; + default = [ "--auto-connect=1" "--dbg-info=1" ]; description = '' Extra command line options for deCONZ. These options seem undocumented, but some examples can be found here: @@ -68,10 +64,8 @@ in config = mkIf cfg.enable { - networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ - cfg.httpPort - cfg.wsPort - ]; + networking.firewall.allowedTCPPorts = + lib.mkIf cfg.openFirewall [ cfg.httpPort cfg.wsPort ]; systemd.services.deconz = { description = "deCONZ ZigBee gateway"; @@ -83,23 +77,20 @@ in rm -f ${stateDir}/.local/share/dresden-elektronik/deCONZ/zcldb.txt ''; serviceConfig = { - ExecStart = - "${cfg.package}/bin/deCONZ" - + " -platform minimal" + ExecStart = "${cfg.package}/bin/deCONZ" + " -platform minimal" + " --http-port=${toString cfg.httpPort}" + " --ws-port=${toString cfg.wsPort}" - + (if cfg.device != "" then " --dev=${cfg.device}" else "") - + " " + (lib.concatStringsSep " " cfg.extraOpts); + + (if cfg.device != "" then " --dev=${cfg.device}" else "") + " " + + (lib.concatStringsSep " " cfg.extraOpts); Restart = "on-failure"; - AmbientCapabilities = - let - # ref. upstream deconz.service - caps = lib.optionals (cfg.httpPort < 1024 || cfg.wsPort < 1024) [ "CAP_NET_BIND_SERVICE" ] - ++ lib.optionals (cfg.allowRebootSystem) [ "CAP_SYS_BOOT" ] - ++ lib.optionals (cfg.allowRestartService) [ "CAP_KILL" ] - ++ lib.optionals (cfg.allowSetSystemTime) [ "CAP_SYS_TIME" ]; - in - lib.concatStringsSep " " caps; + AmbientCapabilities = let + # ref. upstream deconz.service + caps = lib.optionals (cfg.httpPort < 1024 || cfg.wsPort < 1024) + [ "CAP_NET_BIND_SERVICE" ] + ++ lib.optionals (cfg.allowRebootSystem) [ "CAP_SYS_BOOT" ] + ++ lib.optionals (cfg.allowRestartService) [ "CAP_KILL" ] + ++ lib.optionals (cfg.allowSetSystemTime) [ "CAP_SYS_TIME" ]; + in lib.concatStringsSep " " caps; UMask = "0027"; User = name; StateDirectory = name; @@ -115,9 +106,9 @@ in group = name; isSystemUser = true; home = stateDir; - extraGroups = [ "dialout" ]; # for access to /dev/ttyACM0 (ConBee) + extraGroups = [ "dialout" ]; # for access to /dev/ttyACM0 (ConBee) }; - users.groups.deconz = {}; + users.groups.deconz = { }; }; } diff --git a/services/home-assistant.nix b/services/home-assistant.nix index aba2868..8923145 100644 --- a/services/home-assistant.nix +++ b/services/home-assistant.nix @@ -1,12 +1,11 @@ { config, pkgs, ... }: -with pkgs; +with pkgs; let mqttDomain = "mqtt.${config.networking.domain}"; mqttWSPort = "9001"; -in -{ +in { environment.systemPackages = with pkgs; [ deconz ]; local.services.deconz = { @@ -18,7 +17,7 @@ in services.nginx = { virtualHosts = { - ${ mqttDomain } = { + ${mqttDomain} = { enableACME = true; forceSSL = true; locations."/" = { @@ -29,9 +28,7 @@ in }; }; - networking.firewall.allowedTCPPorts = [ - config.services.mosquitto.port - ]; + networking.firewall.allowedTCPPorts = [ config.services.mosquitto.port ]; services.mosquitto = { enable = true; @@ -51,30 +48,19 @@ in hashedPasswordFile = "/etc/nixos/secrets/mqtt/hass"; }; "tasmota" = { - acl = [ - "topic readwrite tasmota/#" - "topic readwrite homeassistant/#" - ]; + acl = [ "topic readwrite tasmota/#" "topic readwrite homeassistant/#" ]; hashedPasswordFile = "/etc/nixos/secrets/mqtt/tasmota"; }; "owntracks" = { - acl = [ - "topic readwrite owntracks/#" - ]; + acl = [ "topic readwrite owntracks/#" ]; hashedPasswordFile = "/etc/nixos/secrets/mqtt/owntracks"; }; "felix" = { - acl = [ - "topic read owntracks/#" - "topic readwrite owntracks/felix/#" - ]; + acl = [ "topic read owntracks/#" "topic readwrite owntracks/felix/#" ]; hashedPasswordFile = "/etc/nixos/secrets/mqtt/felix"; }; "birgit" = { - acl = [ - "topic read owntracks/#" - "topic readwrite owntracks/birgit/#" - ]; + acl = [ "topic read owntracks/#" "topic readwrite owntracks/birgit/#" ]; hashedPasswordFile = "/etc/nixos/secrets/mqtt/birgit"; }; }; @@ -83,9 +69,7 @@ in services.home-assistant = { enable = true; package = home-assistant.override { - extraPackages = ps: with ps; [ - (callPackage pydeconz { }) - ]; + extraPackages = ps: with ps; [ (callPackage pydeconz { }) ]; }; openFirewall = true; config = { @@ -120,9 +104,7 @@ in discovery = true; discovery_prefix = "homeassistant"; }; - owntracks = { - mqtt_topic = "owntracks/#"; - }; + owntracks = { mqtt_topic = "owntracks/#"; }; }; # configWritable = true; # doesn't work atm };