blob: 75684eea3ad1880180a07f1c2b92cb1d8a2d2e43 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.shairport-sync;
in
{
###### interface
options = {
services.shairport-sync = {
enable = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Enable the shairport-sync daemon.
Running with a local system-wide or remote pulseaudio server
is recommended.
'';
};
arguments = mkOption {
type = types.str;
default = "-v -o pa";
description = lib.mdDoc ''
Arguments to pass to the daemon. Defaults to a local pulseaudio
server.
'';
};
openFirewall = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to automatically open ports in the firewall.
'';
};
user = mkOption {
type = types.str;
default = "shairport";
description = lib.mdDoc ''
User account name under which to run shairport-sync. The account
will be created.
'';
};
group = mkOption {
type = types.str;
default = "shairport";
description = lib.mdDoc ''
Group account name under which to run shairport-sync. The account
will be created.
'';
};
};
};
###### implementation
config = mkIf config.services.shairport-sync.enable {
services.avahi.enable = true;
services.avahi.publish.enable = true;
services.avahi.publish.userServices = true;
users = {
users.${cfg.user} = {
description = "Shairport user";
isSystemUser = true;
createHome = true;
home = "/var/lib/shairport-sync";
group = cfg.group;
extraGroups = [ "audio" ] ++ optional config.hardware.pulseaudio.enable "pulse";
};
groups.${cfg.group} = {};
};
networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [ 5000 ];
allowedUDPPortRanges = [ { from = 6001; to = 6011; } ];
};
systemd.services.shairport-sync =
{
description = "shairport-sync";
after = [ "network.target" "avahi-daemon.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = cfg.user;
Group = cfg.group;
ExecStart = "${pkgs.shairport-sync}/bin/shairport-sync ${cfg.arguments}";
RuntimeDirectory = "shairport-sync";
};
};
environment.systemPackages = [ pkgs.shairport-sync ];
};
}
|