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 56 users.extraUsers = singleton 57 { name = cfg.user; 58 description = "Shairport user"; 59 isSystemUser = true; 60 createHome = true; 61 home = "/var/lib/shairport-sync"; 62 extraGroups = [ "audio" ] ++ optional config.hardware.pulseaudio.enable "pulse"; 63 }; 64 65 systemd.services.shairport-sync = 66 { 67 description = "shairport-sync"; 68 after = [ "network.target" "avahi-daemon.service" ]; 69 wantedBy = [ "multi-user.target" ]; 70 serviceConfig = { 71 User = cfg.user; 72 ExecStart = "${pkgs.shairport-sync}/bin/shairport-sync ${cfg.arguments}"; 73 }; 74 }; 75 76 environment.systemPackages = [ pkgs.shairport-sync ]; 77 78 }; 79 80}