nixpkgs/nixos/modules/services/audio/roon-bridge.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
2.2 KiB
Nix
Raw Normal View History

2021-02-13 06:45:02 +00:00
{ config, lib, pkgs, ... }:
with lib;
let
name = "roon-bridge";
cfg = config.services.roon-bridge;
in {
options = {
services.roon-bridge = {
enable = mkEnableOption (lib.mdDoc "Roon Bridge");
2021-02-13 06:45:02 +00:00
openFirewall = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
2021-02-13 06:45:02 +00:00
Open ports in the firewall for the bridge.
'';
};
user = mkOption {
type = types.str;
default = "roon-bridge";
description = lib.mdDoc ''
2021-02-13 06:45:02 +00:00
User to run the Roon bridge as.
'';
};
group = mkOption {
type = types.str;
default = "roon-bridge";
description = lib.mdDoc ''
2021-02-13 06:45:02 +00:00
Group to run the Roon Bridge as.
'';
};
};
};
config = mkIf cfg.enable {
systemd.services.roon-bridge = {
after = [ "network.target" ];
description = "Roon Bridge";
wantedBy = [ "multi-user.target" ];
environment.ROON_DATAROOT = "/var/lib/${name}";
serviceConfig = {
ExecStart = "${pkgs.roon-bridge}/start.sh";
LimitNOFILE = 8192;
User = cfg.user;
Group = cfg.group;
StateDirectory = name;
};
};
networking.firewall = mkIf cfg.openFirewall {
2021-08-31 08:21:07 +00:00
allowedTCPPortRanges = [{ from = 9100; to = 9200; }];
2021-02-13 06:45:02 +00:00
allowedUDPPorts = [ 9003 ];
extraCommands = optionalString (!config.networking.nftables.enable) ''
2021-08-31 08:21: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
'';
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
'';
2021-02-13 06:45:02 +00:00
};
users.groups.${cfg.group} = {};
users.users.${cfg.user} =
if cfg.user == "roon-bridge" then {
isSystemUser = true;
description = "Roon Bridge user";
group = cfg.group;
extraGroups = [ "audio" ];
}
else {};
};
}