2019-06-21 18:58:20 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
name = "roon-server";
|
|
|
|
cfg = config.services.roon-server;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.roon-server = {
|
|
|
|
enable = mkEnableOption (lib.mdDoc "Roon Server");
|
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Open ports in the firewall for the server.
|
|
|
|
'';
|
|
|
|
};
|
2019-08-07 19:27:52 +00:00
|
|
|
user = mkOption {
|
2019-08-09 20:02:46 +00:00
|
|
|
type = types.str;
|
2019-08-07 19:27:52 +00:00
|
|
|
default = "roon-server";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
User to run the Roon Server as.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
group = mkOption {
|
2019-08-09 20:02:46 +00:00
|
|
|
type = types.str;
|
2019-08-07 19:27:52 +00:00
|
|
|
default = "roon-server";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Group to run the Roon Server as.
|
|
|
|
'';
|
|
|
|
};
|
2019-06-21 18:58:20 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.roon-server = {
|
|
|
|
after = [ "network.target" ];
|
|
|
|
description = "Roon Server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
environment.ROON_DATAROOT = "/var/lib/${name}";
|
2022-12-01 05:51:00 +00:00
|
|
|
environment.ROON_ID_DIR = "/var/lib/${name}";
|
2019-06-21 18:58:20 +00:00
|
|
|
|
|
|
|
serviceConfig = {
|
2021-11-04 16:37:07 +00:00
|
|
|
ExecStart = "${pkgs.roon-server}/bin/RoonServer";
|
2019-06-21 18:58:20 +00:00
|
|
|
LimitNOFILE = 8192;
|
2019-08-07 19:27:52 +00:00
|
|
|
User = cfg.user;
|
2019-08-07 20:23:36 +00:00
|
|
|
Group = cfg.group;
|
2019-08-10 05:21:46 +00:00
|
|
|
StateDirectory = name;
|
2019-06-21 18:58:20 +00:00
|
|
|
};
|
|
|
|
};
|
2020-07-23 18:38:13 +00:00
|
|
|
|
2019-06-21 18:58:20 +00:00
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
2022-01-09 19:40:24 +00:00
|
|
|
allowedTCPPortRanges = [
|
|
|
|
{ from = 9100; to = 9200; }
|
2022-07-23 04:20:50 +00:00
|
|
|
{ from = 9330; to = 9339; }
|
|
|
|
{ from = 30000; to = 30010; }
|
2022-01-09 19:40:24 +00:00
|
|
|
];
|
2019-06-21 18:58:20 +00:00
|
|
|
allowedUDPPorts = [ 9003 ];
|
2022-12-22 16:23:23 +00:00
|
|
|
extraCommands = optionalString (!config.networking.nftables.enable) ''
|
2022-07-23 04:20:50 +00:00
|
|
|
## IGMP / Broadcast ##
|
2021-08-31 08:20:07 +00:00
|
|
|
iptables -A INPUT -s 224.0.0.0/4 -j ACCEPT
|
|
|
|
iptables -A INPUT -d 224.0.0.0/4 -j ACCEPT
|
|
|
|
iptables -A INPUT -s 240.0.0.0/5 -j ACCEPT
|
|
|
|
iptables -A INPUT -m pkttype --pkt-type multicast -j ACCEPT
|
|
|
|
iptables -A INPUT -m pkttype --pkt-type broadcast -j ACCEPT
|
|
|
|
'';
|
2022-12-22 16:23:23 +00:00
|
|
|
extraInputRules = optionalString config.networking.nftables.enable ''
|
|
|
|
ip saddr { 224.0.0.0/4, 240.0.0.0/5 } accept
|
|
|
|
ip daddr 224.0.0.0/4 accept
|
|
|
|
pkttype { multicast, broadcast } accept
|
|
|
|
'';
|
2019-06-21 18:58:20 +00:00
|
|
|
};
|
2019-08-07 19:27:52 +00:00
|
|
|
|
2020-07-23 18:38:13 +00:00
|
|
|
|
2019-09-08 23:38:31 +00:00
|
|
|
users.groups.${cfg.group} = {};
|
|
|
|
users.users.${cfg.user} =
|
2023-06-25 10:25:42 +00:00
|
|
|
optionalAttrs (cfg.user == "roon-server") {
|
2019-08-07 20:23:36 +00:00
|
|
|
isSystemUser = true;
|
|
|
|
description = "Roon Server user";
|
2019-11-29 22:50:10 +00:00
|
|
|
group = cfg.group;
|
|
|
|
extraGroups = [ "audio" ];
|
2023-06-25 10:25:42 +00:00
|
|
|
};
|
2019-06-21 18:58:20 +00:00
|
|
|
};
|
|
|
|
}
|