
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:
nix-build ci -A fmt.check
This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).
This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).
Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase
).
If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
172 lines
4.0 KiB
Nix
172 lines
4.0 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.shairport-sync;
|
|
configFormat = pkgs.formats.libconfig { };
|
|
configFile = configFormat.generate "shairport-sync.conf" cfg.settings;
|
|
in
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.shairport-sync = {
|
|
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = ''
|
|
Enable the shairport-sync daemon.
|
|
|
|
Running with a local system-wide or remote pulseaudio server
|
|
is recommended.
|
|
'';
|
|
};
|
|
|
|
package = lib.options.mkPackageOption pkgs "shairport-sync" { };
|
|
|
|
settings = mkOption {
|
|
type = configFormat.type;
|
|
default = {
|
|
general.output_backend = "pa";
|
|
diagnostics.log_verbosity = 1;
|
|
};
|
|
example = {
|
|
general = {
|
|
name = "NixOS Shairport";
|
|
output_backend = "pw";
|
|
};
|
|
metadata = {
|
|
enabled = "yes";
|
|
include_cover_art = "yes";
|
|
cover_art_cache_directory = "/tmp/shairport-sync/.cache/coverart";
|
|
pipe_name = "/tmp/shairport-sync-metadata";
|
|
pipe_timeout = 5000;
|
|
};
|
|
mqtt = {
|
|
enabled = "yes";
|
|
hostname = "mqtt.server.domain.example";
|
|
port = 1883;
|
|
publish_parsed = "yes";
|
|
publish_cover = "yes";
|
|
};
|
|
};
|
|
description = ''
|
|
Configuration options for Shairport-Sync.
|
|
|
|
See the example [shairport-sync.conf][example-file] for possible options.
|
|
|
|
[example-file]: https://github.com/mikebrady/shairport-sync/blob/master/scripts/shairport-sync.conf
|
|
'';
|
|
};
|
|
|
|
arguments = mkOption {
|
|
type = types.str;
|
|
default = "";
|
|
description = ''
|
|
Arguments to pass to the daemon. Defaults to a local pulseaudio
|
|
server.
|
|
'';
|
|
};
|
|
|
|
openFirewall = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = ''
|
|
Whether to automatically open ports in the firewall.
|
|
'';
|
|
};
|
|
|
|
user = mkOption {
|
|
type = types.str;
|
|
default = "shairport";
|
|
description = ''
|
|
User account name under which to run shairport-sync. The account
|
|
will be created.
|
|
'';
|
|
};
|
|
|
|
group = mkOption {
|
|
type = types.str;
|
|
default = "shairport";
|
|
description = ''
|
|
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;
|
|
|
|
services.shairport-sync.settings = {
|
|
general.output_backend = lib.mkDefault "pa";
|
|
diagnostics.log_verbosity = lib.mkDefault 1;
|
|
};
|
|
|
|
users = {
|
|
users.${cfg.user} = {
|
|
description = "Shairport user";
|
|
isSystemUser = true;
|
|
createHome = true;
|
|
home = "/var/lib/shairport-sync";
|
|
group = cfg.group;
|
|
extraGroups = [
|
|
"audio"
|
|
] ++ optional (config.services.pulseaudio.enable || config.services.pipewire.pulse.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 = "${lib.getExe cfg.package} ${cfg.arguments}";
|
|
Restart = "on-failure";
|
|
RuntimeDirectory = "shairport-sync";
|
|
};
|
|
};
|
|
|
|
environment = {
|
|
systemPackages = [ cfg.package ];
|
|
etc."shairport-sync.conf".source = configFile;
|
|
};
|
|
};
|
|
|
|
}
|