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.

81 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");
openFirewall = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Open ports in the firewall for the bridge.
'';
};
user = mkOption {
type = types.str;
default = "roon-bridge";
description = lib.mdDoc ''
User to run the Roon bridge as.
'';
};
group = mkOption {
type = types.str;
default = "roon-bridge";
description = lib.mdDoc ''
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 = {
2023-01-30 00:57:59 +00:00
ExecStart = "${pkgs.roon-bridge}/bin/RoonBridge";
2021-02-13 06:45:02 +00:00
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} =
optionalAttrs (cfg.user == "roon-bridge") {
2021-02-13 06:45:02 +00:00
isSystemUser = true;
description = "Roon Bridge user";
group = cfg.group;
extraGroups = [ "audio" ];
};
2021-02-13 06:45:02 +00:00
};
}