118 lines
2.9 KiB
Nix
118 lines
2.9 KiB
Nix
{ lib, config, pkgs, mensa-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.mensa-tts;
|
|
in
|
|
{
|
|
|
|
options.services.mensa-tts = {
|
|
enable = mkEnableOption "mensa-tts service";
|
|
|
|
package = mkOption {
|
|
default = mensa-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.mensa-tts = {
|
|
description = "mensa-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.mensa-tts = {
|
|
wantedBy = [ "timers.target" ];
|
|
timerConfig = {
|
|
OnCalendar = cfg.time;
|
|
Unit = "mensa-tts.service";
|
|
};
|
|
};
|
|
};
|
|
}
|