ctucx.git: nixfiles

ctucx' nixfiles

commit ff62bafb789c6aa57d680fe3fe6da2551ba22bbb
parent 6e3ea0c54f85f271de1157023110b87e5c5f014b
Author: Leah (ctucx) <git@ctu.cx>
Date: Fri, 9 Dec 2022 22:28:03 +0100

machines/lollo/smarthome: add lacrosse2mqtt
5 files changed, 71 insertions(+), 0 deletions(-)
M
flake.lock
|
25
+++++++++++++++++++++++++
M
flake.nix
|
8
++++++++
M
machines/lollo/smarthome/default.nix
|
2
++
A
machines/lollo/smarthome/lacrosse2mqtt.nix
|
35
+++++++++++++++++++++++++++++++++++
M
pkgs/default.nix
|
1
+
diff --git a/flake.lock b/flake.lock
@@ -189,6 +189,30 @@
         "type": "github"
       }
     },
+    "lacrosse2mqtt": {
+      "inputs": {
+        "flake-utils": [
+          "flake-utils"
+        ],
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1670519904,
+        "narHash": "sha256-Tyk0JyhrCzaTC6IPmeuTkteDmjytXp6F/xPZvz1Rodw=",
+        "ref": "master",
+        "rev": "593582ae209f904a18e6e4b1d90713c23f5dc00f",
+        "revCount": 2,
+        "type": "git",
+        "url": "https://git.ctu.cx/lacrosse2mqtt"
+      },
+      "original": {
+        "ref": "master",
+        "type": "git",
+        "url": "https://git.ctu.cx/lacrosse2mqtt"
+      }
+    },
     "local-secrets": {
       "locked": {
         "lastModified": 0,

@@ -298,6 +322,7 @@
         "dns": "dns",
         "flake-utils": "flake-utils_3",
         "home-manager": "home-manager",
+        "lacrosse2mqtt": "lacrosse2mqtt",
         "local-secrets": "local-secrets",
         "nix-std": "nix-std",
         "nixpkgs": "nixpkgs",
diff --git a/flake.nix b/flake.nix
@@ -86,6 +86,14 @@
       inputs.flake-utils.follows = "flake-utils";
     };
 
+    lacrosse2mqtt = {
+      type  = "git";
+      url   = "https://git.ctu.cx/lacrosse2mqtt";
+      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
@@ -8,6 +8,8 @@
 
     ./zigbee2mqtt.nix
     ./sdm2mqtt.nix
+    ./lacrosse2mqtt.nix
+
     ./influxdb2.nix
   ];
 
diff --git a/machines/lollo/smarthome/lacrosse2mqtt.nix b/machines/lollo/smarthome/lacrosse2mqtt.nix
@@ -0,0 +1,35 @@
+{ inputs, config, pkgs, ... }:
+
+let
+  sdm2mqttConfig = {
+    mqtt.host    = "10.0.0.1";
+    mqtt.port    = 1883;
+    serialDevice = "/dev/jeelink0";
+  };
+
+  configFile = pkgs.writeText "lacrosse2mqtt-config.json" (builtins.toJSON sdm2mqttConfig);
+
+in {
+
+  services.udev.extraRules = ''SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{serial}=="AL006SR4", SYMLINK+="jeelink0"'';
+
+  systemd.services.lacrosse2mqtt = {
+    wantedBy  = [ "multi-user.target" ];
+    requires  = [ "network-online.target" "mosquitto.service" "dev-jeelink0.device" ];
+    wants     = [ "network-online.target" "mosquitto.service" "dev-jeelink0.device" ];
+    after     = [ "network-online.target" "mosquitto.service" "dev-jeelink0.device" ];
+    onFailure = [ "email-notify@%i.service" ];
+
+    serviceConfig = {
+      ExecStartPre = "${pkgs.coreutils}/bin/stty -F /dev/jeelink0 raw -echo -echoe -echok speed 9600";
+      ExecStart    = "${pkgs.lacrosse2mqtt}/bin/lacrosse2mqtt";
+      Restart      = "on-failure";
+      RestartSec   = "5";
+    };
+
+    environment = {
+      CONFIG_PATH = configFile;
+    };
+  };
+
+}
diff --git a/pkgs/default.nix b/pkgs/default.nix
@@ -12,6 +12,7 @@
       agenix                 = inputs.agenix.defaultPackage."${currentSystem}";
 
       sdm2mqtt               = inputs.sdm2mqtt.packages."${currentSystem}".default;
+      lacrosse2mqtt          = inputs.lacrosse2mqtt.packages."${currentSystem}".default;
       pleroma                = prev.pleroma.overrideAttrs (old: {
         patches = [
          ./0001-PATCH-Separate-webfinger-domain-from-host-domain.patch