@@ -0,0 +1,74 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ name = "roon-bridge";
7+ cfg = config.services.roon-bridge;
8+in {
9+ options = {
10+ services.roon-bridge = {
11+ enable = mkEnableOption "Roon Bridge";
12+ openFirewall = mkOption {
13+ type = types.bool;
14+ default = false;
15+ description = ''
16+ Open ports in the firewall for the bridge.
17+
18+ UDP: 9003
19+ TCP: 9100 - 9200
20+ '';
21+ };
22+ user = mkOption {
23+ type = types.str;
24+ default = "roon-bridge";
25+ description = ''
26+ User to run the Roon bridge as.
27+ '';
28+ };
29+ group = mkOption {
30+ type = types.str;
31+ default = "roon-bridge";
32+ description = ''
33+ Group to run the Roon Bridge as.
34+ '';
35+ };
36+ };
37+ };
38+
39+ config = mkIf cfg.enable {
40+ systemd.services.roon-bridge = {
41+ after = [ "network.target" ];
42+ description = "Roon Bridge";
43+ wantedBy = [ "multi-user.target" ];
44+
45+ environment.ROON_DATAROOT = "/var/lib/${name}";
46+
47+ serviceConfig = {
48+ ExecStart = "${pkgs.roon-bridge}/start.sh";
49+ LimitNOFILE = 8192;
50+ User = cfg.user;
51+ Group = cfg.group;
52+ StateDirectory = name;
53+ };
54+ };
55+
56+ networking.firewall = mkIf cfg.openFirewall {
57+ allowedTCPPortRanges = [
58+ { from = 9100; to = 9200; }
59+ ];
60+ allowedUDPPorts = [ 9003 ];
61+ };
62+
63+
64+ users.groups.${cfg.group} = {};
65+ users.users.${cfg.user} =
66+ if cfg.user == "roon-bridge" then {
67+ isSystemUser = true;
68+ description = "Roon Bridge user";
69+ group = cfg.group;
70+ extraGroups = [ "audio" ];
71+ }
72+ else {};
73+ };
74+}