From a1cddab829c901d9411e8658dcb801978fc1396d Mon Sep 17 00:00:00 2001 From: niten Date: Tue, 9 May 2023 11:48:55 -0700 Subject: [PATCH] Add flake & module --- flake.nix | 43 ++++++++++++++++++++++++++++++++++++ module.nix | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 flake.nix create mode 100644 module.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1cadd42 --- /dev/null +++ b/flake.nix @@ -0,0 +1,43 @@ +{ + description = "Tattler Notification Listener"; + + inputs = { + nixpkgs.url = "nixpkgs/nixos-22.05"; + utils.url = "github:numtide/flake-utils"; + helpers = { + url = "git+https://git.fudo.org/fudo-public/nix-helpers.git"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, utils, helpers, ... }: + utils.lib.eachDefaultSystem (system: + let pkgs = nixpkgs.legacyPackages."${system}"; + in { + packages = rec { + default = tattler; + tattler = helpers.packages."${system}".mkClojureBin { + name = "org.fudo/tattler"; + primaryNamespace = "tattler.cli"; + src = ./.; + }; + }; + + devShells = rec { + default = updateDeps; + updateDeps = pkgs.mkShell { + buildInputs = with helpers.packages."${system}"; + [ updateClojureDeps ]; + }; + tattler = pkgs.mkShell { + buildInputs = with self.packages."${system}"; [ tattler-server ]; + }; + }; + }) // { + nixosModules = rec { + default = tattler; + tattler = import ./module.nix self.packages; + }; + }; + +} diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..cae4837 --- /dev/null +++ b/module.nix @@ -0,0 +1,65 @@ +packages: + +{ config, lib, pkgs, ... }: + +with lib; +let + tattler = packages."${pkgs.system}".tattler; + cfg = config.services.tattler; + +in { + options.services.tattler = with types; { + enable = mkEnableOption "Enable Tattler notification listener."; + + verbose = mkEnableOption "Generate verbose logs and output."; + + notification-topic = mkOption { + type = str; + description = "MQTT topic on which to send notifications."; + }; + + mqtt = { + host = mkOption { + type = str; + description = "Hostname of the MQTT server."; + }; + + port = mkOption { + type = port; + description = "Port on which the MQTT server is listening."; + default = 1883; + }; + + user = mkOption { + type = nullOr str; + description = "User as which to connect to the MQTT server."; + default = null; + }; + + password-file = mkOption { + type = nullOr str; + description = + "User password file with which to connect to the MQTT server."; + default = null; + }; + }; + }; + + config = mkIf enable { + systemd.user.services.tattler = { + path = [ tattler ]; + wantedBy = [ "default.target" ]; + serviceConfig = { + ExecStart = pkgs.writeShellScript "tattler.sh" (concatStringsSep " " ([ + "tattler" + "--mqtt-host=${cfg.mqtt.host}" + "--mqtt-port=${cfg.mqtt.port}" + "--notification-topic=${cfg.notification-topic}" + ] ++ (optional cfg.verbose "--verbose") + ++ (optional cfg.mqtt.user "--mqtt-user=${cfg.mqtt.user}") + ++ (optional cfg.mqtt.password-file + "--mqtt-user=${cfg.mqtt.password-file}"))); + }; + }; + }; +}