1{ config, lib, pkgs, ... }:
2
3let
4 inherit (lib) mkEnableOption mkIf mkOption optionalString types;
5
6 dataDir = "/var/lib/squeezelite";
7 cfg = config.services.squeezelite;
8 pkg = if cfg.pulseAudio then pkgs.squeezelite-pulse else pkgs.squeezelite;
9 bin = "${pkg}/bin/${pkg.pname}";
10
11in
12{
13
14 ###### interface
15
16 options.services.squeezelite = {
17 enable = mkEnableOption (lib.mdDoc "Squeezelite, a software Squeezebox emulator");
18
19 pulseAudio = mkEnableOption (lib.mdDoc "pulseaudio support");
20
21 extraArguments = mkOption {
22 default = "";
23 type = types.str;
24 description = lib.mdDoc ''
25 Additional command line arguments to pass to Squeezelite.
26 '';
27 };
28 };
29
30
31 ###### implementation
32
33 config = mkIf cfg.enable {
34 systemd.services.squeezelite = {
35 wantedBy = [ "multi-user.target" ];
36 after = [ "network.target" "sound.target" ];
37 description = "Software Squeezebox emulator";
38 serviceConfig = {
39 DynamicUser = true;
40 ExecStart = "${bin} -N ${dataDir}/player-name ${cfg.extraArguments}";
41 StateDirectory = builtins.baseNameOf dataDir;
42 SupplementaryGroups = "audio";
43 };
44 };
45 };
46}