From 658f5c74a3203f231dde5bd04e24ea3a56547db1 Mon Sep 17 00:00:00 2001
From: makefu <github@syntax-fehler.de>
Date: Wed, 24 Apr 2024 23:46:57 +0200
Subject: [PATCH] puyak: manage zigbee via home-assistant

---
 flake.lock                              | 6 +++---
 krebs/1systems/puyak/config.nix         | 3 ++-
 krebs/1systems/puyak/net.nix            | 2 +-
 krebs/2configs/news-host.nix            | 3 ++-
 krebs/2configs/shack/glados/default.nix | 7 +++----
 krebs/2configs/shack/glados/zigbee.nix  | 5 +++++
 6 files changed, 16 insertions(+), 10 deletions(-)
 create mode 100644 krebs/2configs/shack/glados/zigbee.nix

diff --git a/flake.lock b/flake.lock
index 9a05f5a3c..509ef218b 100644
--- a/flake.lock
+++ b/flake.lock
@@ -18,11 +18,11 @@
     },
     "nixpkgs": {
       "locked": {
-        "lastModified": 1707956935,
-        "narHash": "sha256-ZL2TrjVsiFNKOYwYQozpbvQSwvtV/3Me7Zwhmdsfyu4=",
+        "lastModified": 1710272261,
+        "narHash": "sha256-g0bDwXFmTE7uGDOs9HcJsfLFhH7fOsASbAuOzDC+fhQ=",
         "owner": "NixOS",
         "repo": "nixpkgs",
-        "rev": "a4d4fe8c5002202493e87ec8dbc91335ff55552c",
+        "rev": "0ad13a6833440b8e238947e47bea7f11071dc2b2",
         "type": "github"
       },
       "original": {
diff --git a/krebs/1systems/puyak/config.nix b/krebs/1systems/puyak/config.nix
index 60c1c941a..d3c6cbeba 100644
--- a/krebs/1systems/puyak/config.nix
+++ b/krebs/1systems/puyak/config.nix
@@ -1,4 +1,4 @@
-{ config, pkgs, ... }:
+{ config, pkgs, lib, ... }:
 {
   imports = [
     ./net.nix
@@ -170,4 +170,5 @@
     isNormalUser = true;
     shell = "/run/current-system/sw/bin/zsh";
   };
+  system.stateVersion = lib.mkForce "24.05";
 }
diff --git a/krebs/1systems/puyak/net.nix b/krebs/1systems/puyak/net.nix
index 59b22b380..fe2fd238e 100644
--- a/krebs/1systems/puyak/net.nix
+++ b/krebs/1systems/puyak/net.nix
@@ -14,7 +14,7 @@ in {
     interfaces."${ext-if}".ipv4.addresses = [
       {
         address = shack-ip;
-        prefixLength = 22;
+        prefixLength = 20;
       }
     ];
 
diff --git a/krebs/2configs/news-host.nix b/krebs/2configs/news-host.nix
index 81922ef87..9b8627d61 100644
--- a/krebs/2configs/news-host.nix
+++ b/krebs/2configs/news-host.nix
@@ -1,5 +1,6 @@
-{ config, ... }:
+{ config,lib, ... }:
 {
+  nixpkgs.config.allowUnfree = true; #  "consul-1.18.0" 
   krebs.sync-containers3.containers.news = {
     sshKey = "${config.krebs.secret.directory}/news.sync.key";
   };
diff --git a/krebs/2configs/shack/glados/default.nix b/krebs/2configs/shack/glados/default.nix
index 236b5000d..23921c23e 100644
--- a/krebs/2configs/shack/glados/default.nix
+++ b/krebs/2configs/shack/glados/default.nix
@@ -3,10 +3,9 @@ let
   kodi-host = "192.168.8.11";
   confdir = "/var/lib/homeassistant-docker";
 in {
-  imports = [
-  ];
+  imports = [ ./zigbee.nix ];
 
-  # networking.firewall.allowedTCPPorts = [ 8123 ];
+  networking.firewall.allowedTCPPorts = [ 8123 ];
   virtualisation.oci-containers.containers.hass = {
     image = "homeassistant/home-assistant:latest";
     environment = {
@@ -16,7 +15,7 @@ in {
       PGID = toString config.users.groups.news_container.gid;
       UMASK = "007";
     };
-    extraOptions = ["--net=host" ];
+    extraOptions = ["--net=host" "--device=/dev/zigbee" ];
     volumes = [
       "${confdir}:/config"
       #"${confdir}/docker-run:/etc/services.d/home-assistant/run:"
diff --git a/krebs/2configs/shack/glados/zigbee.nix b/krebs/2configs/shack/glados/zigbee.nix
new file mode 100644
index 000000000..a8967cc37
--- /dev/null
+++ b/krebs/2configs/shack/glados/zigbee.nix
@@ -0,0 +1,5 @@
+{
+  services.udev.extraRules = ''
+    SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="zigbee", MODE="0666"
+  '';
+}