summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/sq/squeezelite/package.nix
blob: 31f83eefa3a27a9a22cb897cbf40607a2ca4af18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{
  lib,
  stdenv,
  fetchFromGitHub,
  flac,
  libgpiod,
  libmad,
  libpulseaudio,
  libvorbis,
  mpg123,
  audioBackend ? if stdenv.hostPlatform.isLinux then "alsa" else "portaudio",
  alsaSupport ? stdenv.hostPlatform.isLinux,
  alsa-lib,
  dsdSupport ? true,
  faad2Support ? true,
  faad2,
  ffmpegSupport ? true,
  ffmpeg,
  opusSupport ? true,
  opusfile,
  resampleSupport ? true,
  soxr,
  sslSupport ? true,
  openssl,
  portaudioSupport ? stdenv.hostPlatform.isDarwin,
  portaudio,
  slimserver,
}:

let
  inherit (lib) optional optionalString;

  pulseSupport = audioBackend == "pulse";

  binName = "squeezelite${optionalString pulseSupport "-pulse"}";
in
stdenv.mkDerivation {
  # the nixos module uses the pname as the binary name
  pname = binName;
  # versions are specified in `squeezelite.h`
  # see https://github.com/ralph-irving/squeezelite/issues/29
  version = "2.0.0.1595";

  src = fetchFromGitHub {
    owner = "ralph-irving";
    repo = "squeezelite";
    rev = "c7c4248ddd70e47dbfeba0bf4a8a7ec08d8a995c";
    hash = "sha256-XCYlD0NliyM+CQCB7SA2LA+XqBvmhgKIW/hVAWVLFCo=";
  };

  buildInputs = [
    flac
    libmad
    libvorbis
    mpg123
  ]
  ++ optional pulseSupport libpulseaudio
  ++ optional alsaSupport alsa-lib
  ++ optional portaudioSupport portaudio

  ++ optional faad2Support faad2
  ++ optional ffmpegSupport ffmpeg
  ++ optional opusSupport opusfile
  ++ optional resampleSupport soxr
  ++ optional sslSupport openssl
  ++ optional (stdenv.hostPlatform.isAarch32 or stdenv.hostPlatform.isAarch64) libgpiod;

  enableParallelBuilding = true;

  postPatch = ''
    substituteInPlace opus.c \
      --replace "<opusfile.h>" "<opus/opusfile.h>"
  '';

  env = {
    EXECUTABLE = binName;

    OPTS = toString (
      [
        "-DLINKALL"
        "-DGPIO"
      ]
      ++ optional dsdSupport "-DDSD"
      ++ optional (!faad2Support) "-DNO_FAAD"
      ++ optional ffmpegSupport "-DFFMPEG"
      ++ optional opusSupport "-DOPUS"
      ++ optional portaudioSupport "-DPORTAUDIO"
      ++ optional pulseSupport "-DPULSEAUDIO"
      ++ optional resampleSupport "-DRESAMPLE"
      ++ optional sslSupport "-DUSE_SSL"
      ++ optional (stdenv.hostPlatform.isAarch32 or stdenv.hostPlatform.isAarch64) "-DRPI"
    );
  }
  // lib.optionalAttrs stdenv.hostPlatform.isDarwin {
    LDADD = toString [
      "-lportaudio"
      "-lpthread"
    ];
  };

  installPhase = ''
    runHook preInstall

    install -Dm555 -t $out/bin                   ${binName}
    install -Dm444 -t $out/share/man/man1 doc/squeezelite.1

    runHook postInstall
  '';

  passthru = {
    inherit (slimserver) tests;
    updateScript = ./update.sh;
  };

  meta = {
    description = "Lightweight headless squeezebox client emulator";
    homepage = "https://github.com/ralph-irving/squeezelite";
    license = with lib.licenses; [ gpl3Plus ] ++ optional dsdSupport bsd2;
    mainProgram = binName;
    maintainers = with lib.maintainers; [ adamcstephens ];
    platforms =
      if (audioBackend == "pulse") then
        lib.platforms.linux
      else
        lib.platforms.linux ++ lib.platforms.darwin;
  };
}