1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.shairport-sync;
8
9in
10
11{
12
13 ###### interface
14
15 options = {
16
17 services.shairport-sync = {
18
19 enable = mkOption {
20 type = types.bool;
21 default = false;
22 description = ''
23 Enable the shairport-sync daemon.
24
25 Running with a local system-wide or remote pulseaudio server
26 is recommended.
27 '';
28 };
29
30 arguments = mkOption {
31 type = types.str;
32 default = "-v -o pa";
33 description = ''
34 Arguments to pass to the daemon. Defaults to a local pulseaudio
35 server.
36 '';
37 };
38
39 user = mkOption {
40 type = types.str;
41 default = "shairport";
42 description = ''
43 User account name under which to run shairport-sync. The account
44 will be created.
45 '';
46 };
47
48 };
49
50 };
51
52
53 ###### implementation
54
55 config = mkIf config.services.shairport-sync.enable {
56
57 services.avahi.enable = true;
58 services.avahi.publish.enable = true;
59 services.avahi.publish.userServices = true;
60
61 users.users.${cfg.user} =
62 { description = "Shairport user";
63 isSystemUser = true;
64 createHome = true;
65 home = "/var/lib/shairport-sync";
66 extraGroups = [ "audio" ] ++ optional config.hardware.pulseaudio.enable "pulse";
67 };
68
69 systemd.services.shairport-sync =
70 {
71 description = "shairport-sync";
72 after = [ "network.target" "avahi-daemon.service" ];
73 wantedBy = [ "multi-user.target" ];
74 serviceConfig = {
75 User = cfg.user;
76 ExecStart = "${pkgs.shairport-sync}/bin/shairport-sync ${cfg.arguments}";
77 RuntimeDirectory = "shairport-sync";
78 };
79 };
80
81 environment.systemPackages = [ pkgs.shairport-sync ];
82
83 };
84
85}