From b30952a049f9b809cfc764260bbf00d87806afa1 Mon Sep 17 00:00:00 2001 From: c6ristian Date: Mon, 10 Jun 2024 15:38:48 +0200 Subject: [PATCH] Add mqtt server (mosquitto) The config was based on the exsisting mosquitto setup. --- config/hosts/mqtt/configuration.nix | 10 +++++++++ config/hosts/mqtt/default.nix | 9 ++++++++ config/hosts/mqtt/mosquitto.nix | 33 +++++++++++++++++++++++++++++ config/hosts/mqtt/networking.nix | 20 +++++++++++++++++ flake.nix | 9 ++++++++ 5 files changed, 81 insertions(+) create mode 100644 config/hosts/mqtt/configuration.nix create mode 100644 config/hosts/mqtt/default.nix create mode 100644 config/hosts/mqtt/mosquitto.nix create mode 100644 config/hosts/mqtt/networking.nix diff --git a/config/hosts/mqtt/configuration.nix b/config/hosts/mqtt/configuration.nix new file mode 100644 index 0000000..18d0184 --- /dev/null +++ b/config/hosts/mqtt/configuration.nix @@ -0,0 +1,10 @@ +{ ... }: + +{ + networking = { + hostName = "mqtt"; + domain = "z9.ccchh.net"; + }; + + system.stateVersion = "23.11"; +} \ No newline at end of file diff --git a/config/hosts/mqtt/default.nix b/config/hosts/mqtt/default.nix new file mode 100644 index 0000000..bb61c12 --- /dev/null +++ b/config/hosts/mqtt/default.nix @@ -0,0 +1,9 @@ +{ pkgs, ... }: + +{ + imports = [ + ./configuration.nix + ./networking.nix + ./mosquitto.nix + ]; +} \ No newline at end of file diff --git a/config/hosts/mqtt/mosquitto.nix b/config/hosts/mqtt/mosquitto.nix new file mode 100644 index 0000000..672c05d --- /dev/null +++ b/config/hosts/mqtt/mosquitto.nix @@ -0,0 +1,33 @@ +# Sources for this configuration: +# - https://search.nixos.org/options?sort=relevance&type=packages&query=services.mosquitto +# - https://mosquitto.org/man/mosquitto-conf-5.html +# - https://winkekatze24.de +{ ... }: + +{ + services.mosquitto = { + enable = true; + persistence = true; + + # set config for all listeners + listeners = [ { + settings.allow_anonymous = true; + omitPasswordAuth = true; + acl = ["topic readwrite #"]; + } ]; + + bridges.winkekatz = { + addresses = [ + { address = "mqtt.winkekatze24.de"; } + ]; + topics = [ + "winkekatze/allcats/eye/set in 2" + "winkekatze/allcats in 2" + "+/status out 2 winkekatze/ \"\"" + "+/connected out 2 winkekatze/ \"\"" + ]; + }; + }; + + networking.firewall.allowedTCPPorts = [ 1883 ]; +} \ No newline at end of file diff --git a/config/hosts/mqtt/networking.nix b/config/hosts/mqtt/networking.nix new file mode 100644 index 0000000..5bd6616 --- /dev/null +++ b/config/hosts/mqtt/networking.nix @@ -0,0 +1,20 @@ +{ ... }: + +{ + networking = { + interfaces.net0 = { + ipv4.addresses = [ { + address = "10.31.208.14"; + prefixLength = 23; + } ]; + }; + defaultGateway = "10.31.208.1"; + nameservers = [ + "10.31.210.1" + ]; + }; + systemd.network.links."10-net0" = { + matchConfig.MACAddress = "BC:24:11:48:85:73"; + linkConfig.Name = "net0"; + }; +} \ No newline at end of file diff --git a/flake.nix b/flake.nix index 8a8ebf7..22bcdd7 100644 --- a/flake.nix +++ b/flake.nix @@ -195,6 +195,15 @@ ./config/hosts/yate ]; }; + + mqtt = nixpkgs.lib.nixosSystem { + inherit system; + modules = [ + ./config/common + ./config/proxmox-vm + ./config/hosts/mqtt + ]; + }; }; packages.x86_64-linux = {