2015-11-27 01:44:56 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.shairport-sync;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.shairport-sync = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2020-04-20 18:05:26 +00:00
|
|
|
type = types.bool;
|
2015-11-27 01:44:56 +00:00
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-11-27 01:44:56 +00:00
|
|
|
Enable the shairport-sync daemon.
|
|
|
|
|
|
|
|
Running with a local system-wide or remote pulseaudio server
|
|
|
|
is recommended.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
arguments = mkOption {
|
2021-01-31 11:14:01 +00:00
|
|
|
type = types.str;
|
2019-01-02 18:07:33 +00:00
|
|
|
default = "-v -o pa";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-11-27 01:44:56 +00:00
|
|
|
Arguments to pass to the daemon. Defaults to a local pulseaudio
|
|
|
|
server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-11-30 19:16:08 +00:00
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-11-30 19:16:08 +00:00
|
|
|
Whether to automatically open ports in the firewall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-11-27 01:44:56 +00:00
|
|
|
user = mkOption {
|
2021-01-31 11:14:01 +00:00
|
|
|
type = types.str;
|
2015-11-27 01:44:56 +00:00
|
|
|
default = "shairport";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-11-27 01:44:56 +00:00
|
|
|
User account name under which to run shairport-sync. The account
|
|
|
|
will be created.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-12-03 06:19:07 +00:00
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "shairport";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-12-03 06:19:07 +00:00
|
|
|
Group account name under which to run shairport-sync. The account
|
|
|
|
will be created.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-11-27 01:44:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.shairport-sync.enable {
|
|
|
|
|
|
|
|
services.avahi.enable = true;
|
2016-07-08 14:01:35 +00:00
|
|
|
services.avahi.publish.enable = true;
|
|
|
|
services.avahi.publish.userServices = true;
|
2015-11-27 01:44:56 +00:00
|
|
|
|
2021-12-03 06:19:07 +00:00
|
|
|
users = {
|
|
|
|
users.${cfg.user} = {
|
|
|
|
description = "Shairport user";
|
2015-11-27 01:44:56 +00:00
|
|
|
isSystemUser = true;
|
|
|
|
createHome = true;
|
|
|
|
home = "/var/lib/shairport-sync";
|
2021-12-03 06:19:07 +00:00
|
|
|
group = cfg.group;
|
2015-11-27 01:44:56 +00:00
|
|
|
extraGroups = [ "audio" ] ++ optional config.hardware.pulseaudio.enable "pulse";
|
|
|
|
};
|
2021-12-03 06:19:07 +00:00
|
|
|
groups.${cfg.group} = {};
|
|
|
|
};
|
2021-11-30 19:16:08 +00:00
|
|
|
|
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ 5000 ];
|
|
|
|
allowedUDPPortRanges = [ { from = 6001; to = 6011; } ];
|
|
|
|
};
|
|
|
|
|
2015-11-27 01:44:56 +00:00
|
|
|
systemd.services.shairport-sync =
|
|
|
|
{
|
|
|
|
description = "shairport-sync";
|
|
|
|
after = [ "network.target" "avahi-daemon.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
2021-12-03 06:19:07 +00:00
|
|
|
Group = cfg.group;
|
2015-11-27 01:44:56 +00:00
|
|
|
ExecStart = "${pkgs.shairport-sync}/bin/shairport-sync ${cfg.arguments}";
|
2018-09-26 16:07:06 +00:00
|
|
|
RuntimeDirectory = "shairport-sync";
|
2015-11-27 01:44:56 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.shairport-sync ];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|