summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/catbus-observer-networkpresence.nix95
-rw-r--r--pkgs/default.nix15
3 files changed, 106 insertions, 5 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 4f8e072..dddb83d 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -6,6 +6,7 @@
./programs/dwm.nix
./services/catbus-actuator-wakeonlan.nix
./services/catbus-bridge-snapcast.nix
+ ./services/catbus-observer-networkpresence.nix
./services/dlnatoad.nix
./services/helix-directory-jackalope.nix
./services/helix-directory.nix
diff --git a/nixos/modules/services/catbus-observer-networkpresence.nix b/nixos/modules/services/catbus-observer-networkpresence.nix
new file mode 100644
index 0000000..be48e27
--- /dev/null
+++ b/nixos/modules/services/catbus-observer-networkpresence.nix
@@ -0,0 +1,95 @@
+{ config, lib, pkgs, ... }:
+with lib;
+
+let
+
+ cfg = config.eth.services.catbus-observer-networkpresence;
+
+ configJSON = pkgs.writeText "config.json" ''
+ {
+ "mqttBroker": "tcp://${cfg.mqttBroker.host}:${toString cfg.mqttBroker.port}",
+
+ "devices": {
+ "TV": {
+ "mac": "${cfg.devices.tv.mac}",
+ "topic": "${cfg.devices.tv.topic}"
+ }
+ }
+ }
+ '';
+
+in {
+
+ options.eth.services.catbus-observer-networkpresence = {
+
+ enable = mkEnableOption "Whether to enable the Catbus network-presence observer";
+
+ interface = mkOption {
+ type = types.str;
+ description = "interface to scan";
+ default = "";
+ example = "enp2s0";
+ };
+
+ mqttBroker = {
+ host = mkOption {
+ type = types.str;
+ description = "Host of the MQTT broker.";
+ example = "localhost";
+ };
+ port = mkOption {
+ type = types.int;
+ description = "Port of the MQTT broker.";
+ default = 1883;
+ };
+ };
+
+ # TODO: replace this with a proper set of option sets.
+ devices = {
+ tv = {
+ mac = mkOption {
+ type = types.str;
+ description = "The device's MAC address";
+ example = "aa:bb:cc:dd:ee:ff";
+ };
+ topic = mkOption {
+ type = types.str;
+ description = "MQTT topic for controlling the device";
+ example = "home/house/speakers/power";
+ };
+ };
+ };
+ };
+
+
+ config = mkIf cfg.enable {
+ assertions = [
+ {
+ assertion = cfg.interface != "";
+ message = "must set config.eth.services.catbus-observer-networkpresence.interface";
+ }
+ ];
+
+ systemd.services.catbus-observer-networkpresence = {
+ enable = true;
+ description = "Detect devices on the network to publish to Catbus";
+ wants = [ "network.target" ];
+ after = [ "network.target" ];
+ wantedBy = [ "multi-user.target" ];
+ serviceConfig = {
+ DynamicUser = true;
+ AmbientCapabilities = "CAP_NET_RAW CAP_NET_ADMIN";
+
+ ExecStart = "${pkgs.eth.catbus-networkpresence}/bin/catbus-observer-networkpresence --config-path ${configJSON} --interface ${cfg.interface}";
+
+ NoNewPrivileges = true;
+ ProtectKernelTunables = true;
+ ProtectControlGroups = true;
+ ProtectKernelModules = true;
+ RestrictNamespaces = true;
+ };
+ };
+ };
+
+}
+
diff --git a/pkgs/default.nix b/pkgs/default.nix
index f8f60cc..915c6ea 100644
--- a/pkgs/default.nix
+++ b/pkgs/default.nix
@@ -3,13 +3,17 @@ let
url = "https://github.com/ethulhu/catbus-lifx";
# TODO: rev = "...";
};
+ catbus-networkpresence = builtins.fetchGit {
+ url = "https://github.com/ethulhu/catbus-networkpresence";
+ rev = "da8002ab10174ccdbbd1718069b7de36afe2dc46";
+ };
catbus-snapcast = builtins.fetchGit {
url = "https://github.com/ethulhu/catbus-snapcast";
# TODO: rev = "...";
};
catbus-wakeonlan = builtins.fetchGit {
url = "https://github.com/ethulhu/catbus-wakeonlan";
- rev = "d5b2961bd2cc474d763d72ad1c180e7358e5fd6d";
+ rev = "54d24cbc56c012f30de902c2746899ffbf9154eb";
};
catbus-web-ui = builtins.fetchGit {
url = "https://github.com/ethulhu/catbus-web-ui";
@@ -36,10 +40,11 @@ in
dwm = pkgs.callPackage ./dwm {};
- catbus-lifx = pkgs.callPackage catbus-lifx {};
- catbus-snapcast = pkgs.callPackage catbus-snapcast {};
- catbus-wakeonlan = pkgs.callPackage catbus-wakeonlan {};
- catbus-web-ui = pkgs.callPackage catbus-web-ui {};
+ catbus-lifx = pkgs.callPackage catbus-lifx {};
+ catbus-networkpresence = pkgs.callPackage catbus-networkpresence {};
+ catbus-snapcast = pkgs.callPackage catbus-snapcast {};
+ catbus-wakeonlan = pkgs.callPackage catbus-wakeonlan {};
+ catbus-web-ui = pkgs.callPackage catbus-web-ui {};
dlnatoad = pkgs.callPackage ./dlnatoad {};