2024-12-18 18:16:35 +01:00
|
|
|
{ lib, config, pkgs, mensa-tts-pkgs, ... }:
|
2024-12-18 17:32:24 +01:00
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
# Shorter name to access final settings a
|
|
|
|
# user of hello.nix module HAS ACTUALLY SET.
|
|
|
|
# cfg is a typical convention.
|
2024-12-18 18:16:35 +01:00
|
|
|
cfg = config.services.mensa-tts;
|
2024-12-18 17:32:24 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
|
2024-12-18 18:16:35 +01:00
|
|
|
options.services.mensa-tts = {
|
2024-12-18 17:32:24 +01:00
|
|
|
enable = mkEnableOption "mensa-tts service";
|
|
|
|
|
|
|
|
package = mkOption {
|
2024-12-18 18:16:35 +01:00
|
|
|
default = mensa-tts-pkgs.x86_64-linux.default;
|
2024-12-18 17:32:24 +01:00
|
|
|
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} - -"
|
|
|
|
];
|
|
|
|
|
2024-12-18 18:16:35 +01:00
|
|
|
systemd.services.mensa-tts = {
|
|
|
|
description = "mensa-tts service";
|
2024-12-18 17:32:24 +01:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
WorkingDirectory = cfg.cache-dir;
|
|
|
|
};
|
|
|
|
script = ''
|
2024-12-18 18:30:38 +01:00
|
|
|
${cfg.package}/bin/mensa_to_speech
|
2024-12-18 17:32:24 +01:00
|
|
|
${cfg.package}/bin/fm_feed_wav --local-addr ${cfg.local-address} \
|
|
|
|
--local-port ${cfg.local-port} \
|
2024-12-18 18:30:38 +01:00
|
|
|
--remote-addr ${cfg.remote-address} \
|
|
|
|
--remote-port ${cfg.remote-port} \
|
2024-12-18 17:32:24 +01:00
|
|
|
--wav mensa.wav
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-12-18 18:16:35 +01:00
|
|
|
systemd.timers.mensa-tts = {
|
2024-12-18 17:32:24 +01:00
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = cfg.time;
|
2024-12-18 18:16:35 +01:00
|
|
|
Unit = "mensa-tts.service";
|
2024-12-18 17:32:24 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|