{ lib, config, pkgs, mesa-tts-pkgs, ... }: with lib; let # Shorter name to access final settings a # user of hello.nix module HAS ACTUALLY SET. # cfg is a typical convention. cfg = config.services.mesa-tts; in { options.services.mesa-tts = { enable = mkEnableOption "mensa-tts service"; package = mkOption { default = mesa-tts-pkgs.x86_64-linux.default; type = types.package; description = "mensa-tts packages to use. Needed to fix crosscompilation issues."; }; user = mkOption { type = types.str; default = "mensa-tts"; description = mdDoc "User to run the mensa-tts script."; }; group = mkOption { type = types.str; default = "mensa-tts"; description = mdDoc "Group for the mensa-tts user."; }; time = mkOption { type = types.str; default = "Mon..Fri 11:10:00 Europe/Berlin"; description = mdDoc "Time to trigger the mensa-tts service. Uses systemd OnCalendar format."; }; local-address = mkOption { type = types.str; default = "127.0.0.1"; description = mdDoc "Local address to send the UDP frames from"; }; local-port = mkOption { type = types.str; default = "4810"; description = mdDoc "Local port to send the UDP frames from"; }; remote-address = mkOption { type = types.str; default = "127.0.0.1"; description = mdDoc "Remote address to send the UDP frames to"; }; remote-port = mkOption { type = types.str; default = "3810"; description = mdDoc "Remote port to send the UDP frames to"; }; cache-dir = mkOption { type = types.str; default = "/var/cache/mensa-tts"; description = mdDoc "Directory to store temporary data"; }; }; config = mkIf cfg.enable { environment.systemPackages = with pkgs; [ cfg.package ]; users.users = mkIf (cfg.user == "mensa-tts") { mensa-tts = { group = cfg.group; isNormalUser = true; }; }; users.groups = mkIf (cfg.group == "mensa-tts") { mensa-tts = { }; }; systemd.tmpfiles.rules = [ "d '${cfg.cache-dir}' 0750 ${cfg.user} ${cfg.group} - -" ]; systemd.services.mesa-tts = { description = "mesa-tts service"; serviceConfig = { Type = "oneshot"; User = cfg.user; Group = cfg.group; WorkingDirectory = cfg.cache-dir; }; script = '' ${cfg.package}/bin/mena-tts ${cfg.package}/bin/fm_feed_wav --local-addr ${cfg.local-address} \ --local-port ${cfg.local-port} \ --local-addr ${cfg.local-address} \ --local-port ${cfg.local-port} \ --wav mensa.wav ''; }; systemd.timers.mesa-tts = { wantedBy = [ "timers.target" ]; timerConfig = { OnCalendar = cfg.time; Unit = "mesa-tts.service"; }; }; }; }