diff options
author | Karel Kočí <cynerd@email.cz> | 2022-12-30 21:13:56 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2022-12-30 21:13:56 +0100 |
commit | ef25d69c4d273765afd2ef86783e42bc98ca4b3d (patch) | |
tree | 13882154c7bdb305473aa7e9191917d31ec1c9f6 | |
parent | e09a2f8a23161e52859754e5cf874ec4099a2008 (diff) | |
download | nixos-personal-ef25d69c4d273765afd2ef86783e42bc98ca4b3d.tar.gz nixos-personal-ef25d69c4d273765afd2ef86783e42bc98ca4b3d.tar.bz2 nixos-personal-ef25d69c4d273765afd2ef86783e42bc98ca4b3d.zip |
nixos: move home assistant around
-rw-r--r-- | flake.lock | 34 | ||||
-rw-r--r-- | nixos/default.nix | 2 | ||||
-rw-r--r-- | nixos/machine/errol.nix | 9 | ||||
-rw-r--r-- | nixos/machine/spt-mox.nix | 155 | ||||
-rw-r--r-- | nixos/modules/default.nix | 5 | ||||
-rw-r--r-- | nixos/modules/develop.nix | 2 | ||||
-rw-r--r-- | nixos/modules/gaming.nix | 1 | ||||
-rw-r--r-- | nixos/modules/home-assistant.nix | 175 | ||||
-rw-r--r-- | nixos/modules/home-assistant/light.nix (renamed from nixos/machine/hass/light.nix) | 0 | ||||
-rw-r--r-- | nixos/modules/home-assistant/sensors.nix (renamed from nixos/machine/hass/sensors.nix) | 0 | ||||
-rw-r--r-- | nixos/modules/monitoring.nix | 4 |
11 files changed, 208 insertions, 179 deletions
@@ -93,11 +93,11 @@ "nixpkgs-regression": "nixpkgs-regression" }, "locked": { - "lastModified": 1671550172, - "narHash": "sha256-0xD40yOXDXYderRoihjFfVQ3IH3jqH1uDa3+S5Gkz3A=", + "lastModified": 1671834048, + "narHash": "sha256-Ki7mDUnSkJ+aRjYwpyf1IRv4YXQWj9YpPHLjYDZnJtQ=", "owner": "NixOS", "repo": "nix", - "rev": "1437582ccd3c4af51f34e43a77df5c8622e24d6c", + "rev": "3dbf9b5af5950b615ec685c1f4155b1c8698bb78", "type": "github" }, "original": { @@ -126,11 +126,11 @@ }, "nixos-hardware": { "locked": { - "lastModified": 1671467847, - "narHash": "sha256-eIeZIQbbW0QYDW0nhDaieokw6VakPO3TyJ3RmxqGHOs=", + "lastModified": 1671631481, + "narHash": "sha256-LP6NvQQNKdqDpXngECo6oCiWfYRb0KPGM5+D5lu7mPw=", "owner": "NixOS", "repo": "nixos-hardware", - "rev": "25010a042c23695ae457a97aad60e9b1d49f2ecc", + "rev": "9577ab1eaf01a738b015a7a7ab2a4616e158b6cd", "type": "github" }, "original": { @@ -140,16 +140,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1657693803, - "narHash": "sha256-G++2CJ9u0E7NNTAi9n5G8TdDmGJXcIjkJ3NF8cetQB8=", + "lastModified": 1670461440, + "narHash": "sha256-jy1LB8HOMKGJEGXgzFRLDU1CBGL0/LlkolgnqIsF0D8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "365e1b3a859281cf11b94f87231adeabbdd878a2", + "rev": "04a75b2eecc0acf6239acf9dd04485ff8d14f425", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-22.05-small", + "ref": "nixos-22.11-small", "repo": "nixpkgs", "type": "github" } @@ -186,11 +186,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1671442489, - "narHash": "sha256-pSCuSrG+XxWCs5IZ90eKIxDIZy4rM22YSFMRZ/fiixc=", + "lastModified": 1671997655, + "narHash": "sha256-8zUwvnJrBwiFIdw9VgARj1PIQsto5Spn9J5v34b0O7A=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ff07b107adeda2164b29f8feb4a86ed012854dfb", + "rev": "aac1f0b25e6b04afad8e05dec5828f5c02398bd1", "type": "github" }, "original": { @@ -300,11 +300,11 @@ "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1671111931, - "narHash": "sha256-CJfty8oZGdEkZZX3qo7gPRsI/72tBotUow/bTsfWHpY=", + "lastModified": 1671629135, + "narHash": "sha256-kxxe1vq50kBLK9BiqHytSHUBKhDnX0QFD08t1MIY1ew=", "ref": "refs/heads/master", - "rev": "2959b9f9c1006a42dba4ed6316275c9538f87a62", - "revCount": 85, + "rev": "3ec7f745b41b709816f936eb2c400626bb6f7d86", + "revCount": 87, "type": "git", "url": "https://git.cynerd.cz/shellrc" }, diff --git a/nixos/default.nix b/nixos/default.nix index 939d438..790ea40 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -1,6 +1,6 @@ self: let - modules = import ./modules self.inputs.nixpkgs; + modules = import ./modules; machines = import ./machine self; in modules // machines // { diff --git a/nixos/machine/errol.nix b/nixos/machine/errol.nix index 835999a..70bc8cf 100644 --- a/nixos/machine/errol.nix +++ b/nixos/machine/errol.nix @@ -79,13 +79,18 @@ with lib; port = 1883; username = "homeassistant"; password = "!secret mqtt_password"; - sensor = import ./hass/sensors.nix; - light = import ./hass/light.nix; + sensor = import ../modules/home-assistant/sensors.nix; + light = import ../modules/home-assistant/light.nix; }; met = {}; default_config = {}; }; extraComponents = []; + package = pkgs.home-assistant.override { + extraPackages = pkgs: with pkgs; [ + securetar + ]; + }; }; }; diff --git a/nixos/machine/spt-mox.nix b/nixos/machine/spt-mox.nix index 87d720f..57573ef 100644 --- a/nixos/machine/spt-mox.nix +++ b/nixos/machine/spt-mox.nix @@ -6,6 +6,7 @@ with lib; { config = { + cynerd.home-assistant = true; environment.systemPackages = with pkgs; [ mosquitto @@ -62,160 +63,6 @@ with lib; dhcpcd.allowInterfaces = [ "brlan" ]; }; - services.mosquitto = { - enable = true; - listeners = [ - { - users = { - cynerd = { - acl = ["readwrite #"]; - passwordFile = "/run/secrets/mosquitto.cynerd.pass"; - }; - bigclown = { - acl = ["readwrite bigclown/#"]; - passwordFile = "/run/secrets/mosquitto.bigclown.pass"; - }; - homeassistant = { - acl = [ - "readwrite bigclown/#" - "readwrite homeassistant/#" - ]; - passwordFile = "/run/secrets/mosquitto.homeassistant.pass"; - }; - }; - } - ]; - }; - networking.firewall.allowedTCPPorts = [1883]; - - services.bigclown = { - gateway = { - enable = true; - device = "/dev/ttyUSB0"; - environmentFile = "/run/secrets/bigclown.env"; - baseTopicPrefix = "bigclown/"; - mqtt = { - username = "bigclown"; - password = "@PASS_MQTT@"; - }; - }; - mqtt2influxdb = { - enable = true; - environmentFile = "/run/secrets/bigclown.env"; - mqtt = { - username = "bigclown"; - password = "@PASS_MQTT@"; - }; - influxdb = { - host = "cynerd.cz"; - database = "bigclown"; - username = "bigclown"; - password = "@PASS_INFLUXDB@"; - ssl = true; - verify_ssl = false; - }; - points = [ - { - measurement = "temperature"; - topic = "bigclown/node/+/thermometer/+/temperature"; - fields.value = "$.payload"; - tags = { - id = "$.topic[2]"; - channel = "$.topic[4]"; - }; - } - { - measurement = "relative-humidity"; - topic = "bigclown/node/+/hygrometer/+/relative-humidity"; - fields.value = "$.payload"; - tags = { - id = "$.topic[2]"; - channel = "$.topic[4]"; - }; - } - { - measurement = "illuminance"; - topic = "bigclown/node/+/lux-meter/0:0/illuminance"; - fields.value = "$.payload"; - tags = { - id = "$.topic[2]"; - }; - } - { - measurement = "pressure"; - topic = "bigclown/node/+/barometer/0:0/pressure"; - fields.value = "$.payload"; - tags = { - id = "$.topic[2]"; - }; - } - { - measurement = "voltage"; - topic = "bigclown/node/+/battery/+/voltage"; - fields.value = "$.payload"; - tags = { - id = "$.topic[2]"; - }; - } - { - measurement = "button"; - topic = "bigclown/node/+/push-button/+/event-count"; - fields.value = "$.payload"; - tags = { - id = "$.topic[2]"; - channel = "$.topic[4]"; - }; - } - ]; - }; - }; - - systemd.services.bigclown-leds = { - description = "Bigclown LEDs control"; - wantedBy = ["multi-user.target"]; - wants = ["mosquitto.service"]; - serviceConfig.ExecStart = "${pkgs.bigclown-leds}/bin/bigclown-leds /run/secrets/bigclown-leds.ini"; - }; - - services.home-assistant = { - enable = false; - openFirewall = true; - configDir = "/var/lib/hass"; - config = { - homeassistant = { - name = "SPT"; - latitude = "!secret latitude"; - longitude = "!secret longitude"; - elevation = "!secret elevation"; - time_zone = "Europe/Prague"; - country = "CZ"; - }; - http.server_port = 8808; - mqtt = { - broker = config.cynerd.hosts.spt.mox; - port = 1883; - username = "homeassistant"; - password = "!secret mqtt_password"; - sensor = import ./hass/sensors.nix; - light = import ./hass/light.nix; - }; - met = {}; - default_config = {}; - }; - extraComponents = []; - package = pkgs.home-assistant.override { - packageOverrides = (self: super: { - scapy = super.scapy.override { - withPlottingSupport = false; - }; - s3transfer = super.s3transfer.overridePythonAttrs (oldAttrs: { - dontUsePytestCheck = true; - dontUseSetuptoolsCheck = true; - }); - }); - }; - }; - }; } diff --git a/nixos/modules/default.nix b/nixos/modules/default.nix index 8bf6a31..72221d8 100644 --- a/nixos/modules/default.nix +++ b/nixos/modules/default.nix @@ -1,10 +1,11 @@ -nixpkgs: { +{ cynerd-autounlock = import ./autounlock.nix; cynerd-compile = import ./compile.nix; cynerd-desktop = import ./desktop.nix; - cynerd-develop = import ./develop.nix nixpkgs; + cynerd-develop = import ./develop.nix; cynerd-gaming = import ./gaming.nix; cynerd-generic = import ./generic.nix; + cynerd-home-assistant = import ./home-assistant.nix; cynerd-hosts = import ./hosts.nix; cynerd-monitoring = import ./monitoring.nix; cynerd-openvpn = import ./openvpn.nix; diff --git a/nixos/modules/develop.nix b/nixos/modules/develop.nix index fa91d02..b978d3f 100644 --- a/nixos/modules/develop.nix +++ b/nixos/modules/develop.nix @@ -1,4 +1,4 @@ -nixpkgs: { config, lib, pkgs, ... }: +{ config, lib, pkgs, ... }: with lib; diff --git a/nixos/modules/gaming.nix b/nixos/modules/gaming.nix index e71397e..f61f85e 100644 --- a/nixos/modules/gaming.nix +++ b/nixos/modules/gaming.nix @@ -19,6 +19,7 @@ in { cynerd.desktop.enable = true; environment.systemPackages = with pkgs; [ + dwarf-fortress ]; programs.steam = { diff --git a/nixos/modules/home-assistant.nix b/nixos/modules/home-assistant.nix new file mode 100644 index 0000000..80c76b3 --- /dev/null +++ b/nixos/modules/home-assistant.nix @@ -0,0 +1,175 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cnf = config.cynerd.home-assistant; + +in { + options = { + cynerd.home-assistant = mkEnableOption "Enable Home Assistant and Bigclown"; + }; + + config = mkIf cnf { + + services.mosquitto = { + enable = true; + listeners = [ + { + users = { + cynerd = { + acl = ["readwrite #"]; + passwordFile = "/run/secrets/mosquitto.cynerd.pass"; + }; + bigclown = { + acl = ["readwrite bigclown/#"]; + passwordFile = "/run/secrets/mosquitto.bigclown.pass"; + }; + homeassistant = { + acl = [ + "readwrite bigclown/#" + "readwrite homeassistant/#" + ]; + passwordFile = "/run/secrets/mosquitto.homeassistant.pass"; + }; + }; + } + ]; + }; + networking.firewall.allowedTCPPorts = [1883]; + + services.bigclown = { + gateway = { + enable = true; + device = "/dev/ttyUSB0"; + environmentFile = "/run/secrets/bigclown.env"; + baseTopicPrefix = "bigclown/"; + mqtt = { + username = "bigclown"; + password = "@PASS_MQTT@"; + }; + }; + mqtt2influxdb = { + enable = true; + environmentFile = "/run/secrets/bigclown.env"; + mqtt = { + username = "bigclown"; + password = "@PASS_MQTT@"; + }; + influxdb = { + host = "cynerd.cz"; + database = "bigclown"; + username = "bigclown"; + password = "@PASS_INFLUXDB@"; + ssl = true; + verify_ssl = false; + }; + points = [ + { + measurement = "temperature"; + topic = "bigclown/node/+/thermometer/+/temperature"; + fields.value = "$.payload"; + tags = { + id = "$.topic[2]"; + channel = "$.topic[4]"; + }; + } + { + measurement = "relative-humidity"; + topic = "bigclown/node/+/hygrometer/+/relative-humidity"; + fields.value = "$.payload"; + tags = { + id = "$.topic[2]"; + channel = "$.topic[4]"; + }; + } + { + measurement = "illuminance"; + topic = "bigclown/node/+/lux-meter/0:0/illuminance"; + fields.value = "$.payload"; + tags = { + id = "$.topic[2]"; + }; + } + { + measurement = "pressure"; + topic = "bigclown/node/+/barometer/0:0/pressure"; + fields.value = "$.payload"; + tags = { + id = "$.topic[2]"; + }; + } + { + measurement = "voltage"; + topic = "bigclown/node/+/battery/+/voltage"; + fields.value = "$.payload"; + tags = { + id = "$.topic[2]"; + }; + } + { + measurement = "button"; + topic = "bigclown/node/+/push-button/+/event-count"; + fields.value = "$.payload"; + tags = { + id = "$.topic[2]"; + channel = "$.topic[4]"; + }; + } + ]; + }; + }; + + systemd.services.bigclown-leds = { + description = "Bigclown LEDs control"; + wantedBy = ["multi-user.target"]; + wants = ["mosquitto.service"]; + serviceConfig.ExecStart = "${pkgs.bigclown-leds}/bin/bigclown-leds /run/secrets/bigclown-leds.ini"; + }; + + services.home-assistant = { + enable = false; + openFirewall = true; + configDir = "/var/lib/hass"; + config = { + homeassistant = { + name = "SPT"; + latitude = "!secret latitude"; + longitude = "!secret longitude"; + elevation = "!secret elevation"; + time_zone = "Europe/Prague"; + country = "CZ"; + }; + http.server_port = 8808; + mqtt = { + broker = "localhost"; + port = 1883; + username = "homeassistant"; + password = "!secret mqtt_password"; + sensor = import ./home-assistant/sensors.nix; + light = import ./home-assistant/light.nix; + }; + met = {}; + default_config = {}; + }; + extraComponents = []; + package = pkgs.home-assistant.override { + extraPackages = pkgs: with pkgs; [ + securetar + ]; + packageOverrides = (self: super: { + scapy = super.scapy.override { + withPlottingSupport = false; + }; + s3transfer = super.s3transfer.overridePythonAttrs (oldAttrs: { + dontUsePytestCheck = true; + dontUseSetuptoolsCheck = true; + }); + }); + }; + }; + + }; + +} diff --git a/nixos/machine/hass/light.nix b/nixos/modules/home-assistant/light.nix index a9d158b..a9d158b 100644 --- a/nixos/machine/hass/light.nix +++ b/nixos/modules/home-assistant/light.nix diff --git a/nixos/machine/hass/sensors.nix b/nixos/modules/home-assistant/sensors.nix index fadd4eb..fadd4eb 100644 --- a/nixos/machine/hass/sensors.nix +++ b/nixos/modules/home-assistant/sensors.nix diff --git a/nixos/modules/monitoring.nix b/nixos/modules/monitoring.nix index 247253e..1f011dd 100644 --- a/nixos/modules/monitoring.nix +++ b/nixos/modules/monitoring.nix @@ -29,7 +29,7 @@ in { }; config = mkMerge [ - { cynerd.monitoring.host = "ridcully"; } + { cynerd.monitoring.host = "errol"; } (mkIf cnf.enable { # Telegraf configuration services.telegraf = { @@ -38,7 +38,7 @@ in { extraConfig = { agent = {}; outputs.influxdb_v2 = { - urls = ["http://${cnf.host}:8086"]; + urls = ["http://errol:8086"]; token = "$INFLUX_TOKEN"; organization = "personal"; bucket = "monitoring"; |