aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2022-12-30 21:13:56 +0100
committerKarel Kočí <cynerd@email.cz>2022-12-30 21:13:56 +0100
commitef25d69c4d273765afd2ef86783e42bc98ca4b3d (patch)
tree13882154c7bdb305473aa7e9191917d31ec1c9f6 /nixos/modules
parente09a2f8a23161e52859754e5cf874ec4099a2008 (diff)
downloadnixos-personal-ef25d69c4d273765afd2ef86783e42bc98ca4b3d.tar.gz
nixos-personal-ef25d69c4d273765afd2ef86783e42bc98ca4b3d.tar.bz2
nixos-personal-ef25d69c4d273765afd2ef86783e42bc98ca4b3d.zip
nixos: move home assistant around
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/default.nix5
-rw-r--r--nixos/modules/develop.nix2
-rw-r--r--nixos/modules/gaming.nix1
-rw-r--r--nixos/modules/home-assistant.nix175
-rw-r--r--nixos/modules/home-assistant/light.nix13
-rw-r--r--nixos/modules/home-assistant/sensors.nix19
-rw-r--r--nixos/modules/monitoring.nix4
7 files changed, 214 insertions, 5 deletions
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/modules/home-assistant/light.nix b/nixos/modules/home-assistant/light.nix
new file mode 100644
index 0000000..a9d158b
--- /dev/null
+++ b/nixos/modules/home-assistant/light.nix
@@ -0,0 +1,13 @@
+[
+ {
+ name = "RGB Osvětlení";
+ command_topic = "homeassistant/led-strip";
+ brightness_scale = 100;
+ brightness_command_topic = "bigclown/node/power-controller:0/led-strip/-/brightness/set";
+ #brightness_state_topic = "bigclown/node/power-controller:0/led-strip/-/brightness/set";
+ rgb_command_template = ''"#{{"%02x" % red}}{{"%02x" % green}}{{"%02x" % blue}}"'';
+ rgb_command_topic = "bigclown/node/power-controller:0/led-strip/-/color/set";
+ #rgb_value_template = ''{{int(value[2:4],16)}},{{int(value[5:7],16)}},{{int(value[8:10],16)}}'';
+ #rgb_state_topic = "bigclown/node/power-controller:0/led-strip/-/color/set";
+ }
+]
diff --git a/nixos/modules/home-assistant/sensors.nix b/nixos/modules/home-assistant/sensors.nix
new file mode 100644
index 0000000..fadd4eb
--- /dev/null
+++ b/nixos/modules/home-assistant/sensors.nix
@@ -0,0 +1,19 @@
+[
+ {
+ name = "Teplota";
+ state_class = "measurement";
+ state_topic = "bigclown/node/climate-monitor:0/thermometer/0:0/temperature";
+ unit_of_measurement = "°C";
+ }
+ {
+ name = "Vlhkost";
+ state_class = "measurement";
+ state_topic = "bigclown/node/climate-monitor:0/hygrometer/0:4/relative-humidity";
+ unit_of_measurement = "%";
+ }
+ {
+ name = "Osvětlení";
+ state_class = "measurement";
+ state_topic = "bigclown/node/climate-monitor:0/lux-meter/0:0/illuminance";
+ }
+]
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";