commit 6e3ea0c54f85f271de1157023110b87e5c5f014b
parent 87166fc541edd6f0e8d371a9d64c5a15f5e81cdc
Author: Leah (ctucx) <git@ctu.cx>
Date: Fri, 9 Dec 2022 22:27:07 +0100
parent 87166fc541edd6f0e8d371a9d64c5a15f5e81cdc
Author: Leah (ctucx) <git@ctu.cx>
Date: Fri, 9 Dec 2022 22:27:07 +0100
machines/lollo/smarthome: add sdm2mqtt
5 files changed, 100 insertions(+), 7 deletions(-)
diff --git a/flake.lock b/flake.lock @@ -151,6 +151,22 @@ "type": "github" } }, + "flake-utils_3": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "ref": "master", + "repo": "flake-utils", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -280,14 +296,40 @@ "colmena": "colmena", "darwin": "darwin", "dns": "dns", + "flake-utils": "flake-utils_3", "home-manager": "home-manager", "local-secrets": "local-secrets", "nix-std": "nix-std", "nixpkgs": "nixpkgs", "nixpkgsUnstable": "nixpkgsUnstable", + "sdm2mqtt": "sdm2mqtt", "simple-nixos-mailserver": "simple-nixos-mailserver" } }, + "sdm2mqtt": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1670615041, + "narHash": "sha256-5dxclqXbpyxWffQECKRK435ChPCpY+KPw+Ym/Eq1CH8=", + "ref": "master", + "rev": "5c537271fea363e0a381fa8cbd55fafd1a756e6d", + "revCount": 1, + "type": "git", + "url": "https://git.ctu.cx/sdm2mqtt" + }, + "original": { + "ref": "master", + "type": "git", + "url": "https://git.ctu.cx/sdm2mqtt" + } + }, "simple-nixos-mailserver": { "inputs": { "blobs": "blobs",
diff --git a/flake.nix b/flake.nix @@ -48,13 +48,6 @@ ref = "master"; }; - dns = { - type = "git"; - url = "https://git.ctu.cx/dns-nix"; - ref = "master"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - agenix = { type = "github"; owner = "ryantm"; @@ -71,6 +64,28 @@ inputs.nixpkgs.follows = "nixpkgs"; }; + flake-utils = { + type = "github"; + owner = "numtide"; + repo = "flake-utils"; + ref = "master"; + }; + + dns = { + type = "git"; + url = "https://git.ctu.cx/dns-nix"; + ref = "master"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + sdm2mqtt = { + type = "git"; + url = "https://git.ctu.cx/sdm2mqtt"; + ref = "master"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + }; + local-secrets.url = "/tmp/nix-secrets"; };
diff --git a/machines/lollo/smarthome/default.nix b/machines/lollo/smarthome/default.nix @@ -7,6 +7,7 @@ ./mbusd.nix ./zigbee2mqtt.nix + ./sdm2mqtt.nix ./influxdb2.nix ];
diff --git a/machines/lollo/smarthome/sdm2mqtt.nix b/machines/lollo/smarthome/sdm2mqtt.nix @@ -0,0 +1,34 @@ +{ inputs, config, pkgs, ... }: + +let + sdm2mqttConfig = { + devices."leah" = 50; + modbus.host = "10.0.0.1"; + modbus.port = 502; + mqtt.host = "10.0.0.1"; + mqtt.port = 1883; + updateInterval = 10; + }; + + configFile = pkgs.writeText "sdm2mqtt-config.json" (builtins.toJSON sdm2mqttConfig); + +in { + + systemd.services.sdm2mqtt = { + wantedBy = [ "multi-user.target" ]; + requires = [ "network-online.target" "mbusd.service" "mosquitto.service" ]; + after = [ "network-online.target" "mbusd.service" "mosquitto.service" ]; + onFailure = [ "email-notify@%i.service" ]; + + serviceConfig = { + ExecStart = "${pkgs.sdm2mqtt}/bin/sdm2mqtt"; + Restart = "on-failure"; + RestartSec = "5"; + }; + + environment = { + CONFIG_PATH = configFile; + }; + }; + +}
diff --git a/pkgs/default.nix b/pkgs/default.nix @@ -11,6 +11,7 @@ agenix = inputs.agenix.defaultPackage."${currentSystem}"; + sdm2mqtt = inputs.sdm2mqtt.packages."${currentSystem}".default; pleroma = prev.pleroma.overrideAttrs (old: { patches = [ ./0001-PATCH-Separate-webfinger-domain-from-host-domain.patch