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 default = false;
21 description = ''
22 Enable the shairport-sync daemon.
23
24 Running with a local system-wide or remote pulseaudio server
25 is recommended.
26 '';
27 };
28
29 arguments = mkOption {
30 default = "-v -o pulse";
31 description = ''
32 Arguments to pass to the daemon. Defaults to a local pulseaudio
33 server.
34 '';
35 };
36
37 user = mkOption {
38 default = "shairport";
39 description = ''
40 User account name under which to run shairport-sync. The account
41 will be created.
42 '';
43 };
44
45 };
46
47 };
48
49
50 ###### implementation
51
52 config = mkIf config.services.shairport-sync.enable {
53
54 services.avahi.enable = true;
55 services.avahi.publish.enable = true;
56 services.avahi.publish.userServices = true;
57
58 users.extraUsers = singleton
59 { name = cfg.user;
60 description = "Shairport user";
61 isSystemUser = true;
62 createHome = true;
63 home = "/var/lib/shairport-sync";
64 extraGroups = [ "audio" ] ++ optional config.hardware.pulseaudio.enable "pulse";
65 };
66
67 systemd.services.shairport-sync =
68 {
69 description = "shairport-sync";
70 after = [ "network.target" "avahi-daemon.service" ];
71 wantedBy = [ "multi-user.target" ];
72 serviceConfig = {
73 User = cfg.user;
74 ExecStart = "${pkgs.shairport-sync}/bin/shairport-sync ${cfg.arguments}";
75 };
76 };
77
78 environment.systemPackages = [ pkgs.shairport-sync ];
79
80 };
81
82}