summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/au/audacity/package.nix
blob: eaefd81c7c550d156a46e78b863d2e04fe379963 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
{
  lib,
  stdenv,
  fetchurl,

  # nativeBuildInputs
  cmake,
  git,
  linuxHeaders,
  ninja,
  pkg-config,
  python3,
  qt6,
  wrapGAppsHook3,

  # buildInputs
  alsa-lib,
  expat,
  ffmpeg,
  flac,
  freetype,
  harfbuzz,
  lame,
  libjack2,
  libogg,
  libopus,
  libsndfile,
  libvorbis,
  mpg123,
  opusfile,
  portaudio,
  pugixml,
  utf8cpp,
  wavpack,
  wxwidgets_3_2,
  zlib,
}:
let
  wxwidgets = wxwidgets_3_2.override { withWebKit = false; };
in
stdenv.mkDerivation (finalAttrs: {
  pname = "audacity";
  version = "4.0.0";

  src = fetchurl {
    url = "https://github.com/audacity/audacity/releases/download/Audacity-${finalAttrs.version}/audacity-sources-${finalAttrs.version}.tar.xz";
    hash = "sha256-spB2+Z+l0vUi0AHbRyqJbbgfnv/v0VlIyUBXF1OFgFg=";
  };

  patches = [
    # https://github.com/musescore/muse_deps/pull/47
    ./muse-deps-wxwidgets-frameworks.patch
    # https://github.com/audacity/audacity/pull/12021
    ./audacity-deployment-target.patch
    # https://github.com/musescore/muse_framework/pull/278
    ./muse-framework-deployment-target.patch
  ]
  ++ lib.optionals stdenv.hostPlatform.isDarwin [
    # https://github.com/audacity/audacity/pull/12056
    ./macdeployqt-extra-options.patch
  ];

  postPatch = lib.optionalString stdenv.hostPlatform.isLinux ''
    substituteInPlace au3/libraries/au3-files/FileNames.cpp \
      --replace-fail /usr/include/linux/magic.h ${linuxHeaders}/include/linux/magic.h
  '';

  nativeBuildInputs = [
    cmake
    git
    ninja
    pkg-config
    python3
    qt6.qttools
    qt6.wrapQtAppsHook
    wxwidgets
  ]
  ++ lib.optionals stdenv.hostPlatform.isLinux [
    linuxHeaders
    wrapGAppsHook3
  ];

  buildInputs = [
    expat
    ffmpeg
    flac
    freetype
    harfbuzz
    lame
    libjack2
    libogg
    libopus
    libsndfile
    libvorbis
    mpg123
    opusfile
    portaudio
    pugixml
    qt6.qt5compat
    qt6.qtbase
    qt6.qtdeclarative
    qt6.qtnetworkauth
    qt6.qtshadertools
    qt6.qtsvg
    utf8cpp
    wavpack
    wxwidgets
    zlib
  ]
  ++ lib.optionals stdenv.hostPlatform.isLinux [
    alsa-lib
    qt6.qtwayland
  ];

  cmakeFlags = [
    (lib.cmakeFeature "AU4_BUILD_MODE" "release")
    (lib.cmakeFeature "EXTDEPS_OVERRIDE_ALL" "SYSTEM")
    (lib.cmakeBool "MUSE_COMPILE_USE_CCACHE" false)
    (lib.cmakeBool "MUSE_ENABLE_UNIT_TESTS" finalAttrs.finalPackage.doCheck)
    (lib.cmakeBool "MUSE_MODULE_DIAGNOSTICS_CRASHPAD_CLIENT" false)
  ]
  ++ lib.optionals stdenv.hostPlatform.isDarwin [
    (lib.cmakeFeature "CMAKE_OSX_ARCHITECTURES" stdenv.hostPlatform.darwinArch)
    (lib.cmakeFeature "CMAKE_OSX_DEPLOYMENT_TARGET" stdenv.hostPlatform.darwinMinVersion)
    # Nix performs stripping after deployment.
    (lib.cmakeFeature "AU4_MACDEPLOYQT_EXTRA_OPTIONS" "-no-strip")
  ];

  preConfigure = ''
    cmakeFlagsArray+=("-DEXTDEPS_CACHE=$PWD/offline-deps")
  '';

  preInstall = lib.optionalString stdenv.hostPlatform.isDarwin ''
    export NIX_QMLIMPORTSCANNER=${lib.getBin qt6.qtdeclarative}/libexec/qmlimportscanner
    export QML2_IMPORT_PATH=
    for input in ${lib.escapeShellArgs finalAttrs.buildInputs}; do
      addToSearchPath QML2_IMPORT_PATH "$input/${qt6.qtbase.qtQmlPrefix}"
    done
  '';

  postInstall = lib.optionalString stdenv.hostPlatform.isDarwin ''
    mkdir -p "$out/Applications"
    mv "$out/audacity.app" "$out/Applications/"
  '';

  qtWrapperArgs = [
    "--prefix"
    "${lib.optionalString stdenv.hostPlatform.isDarwin "DY"}LD_LIBRARY_PATH"
    ":"
    (lib.makeLibraryPath [
      ffmpeg
      libjack2
    ])
  ];

  preFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
    qtWrapperArgs+=("''${gappsWrapperArgs[@]}")
  '';

  postFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
    # Use bundled Qt plugins, not a second Qt installation from the store.
    wrapProgram "$out/Applications/audacity.app/Contents/MacOS/audacity" \
      ${lib.escapeShellArgs finalAttrs.qtWrapperArgs} \
      --unset QT_PLUGIN_PATH \
      --unset NIXPKGS_QT6_QML_IMPORT_PATH \
      --unset QML2_IMPORT_PATH \
      --unset QML_IMPORT_PATH
    mkdir -p "$out/bin"
    makeWrapper "$out/Applications/audacity.app/Contents/MacOS/audacity" "$out/bin/audacity"
  '';

  dontWrapGApps = true;
  # Automatic scanning would wrap bundled framework libraries as executables.
  dontWrapQtApps = stdenv.hostPlatform.isDarwin;

  strictDeps = true;
  __structuredAttrs = true;

  meta = {
    description = "Sound editor with graphical UI";
    mainProgram = "audacity";
    homepage = "https://www.audacityteam.org";
    changelog = "https://github.com/audacity/audacity/releases/tag/Audacity-${finalAttrs.version}";
    license = lib.licenses.AND [
      lib.licenses.gpl2Plus
      lib.licenses.gpl3Only
      lib.licenses.cc-by-30
    ];
    maintainers = with lib.maintainers; [
      johnrichardrinehart
      veprbl
    ];
    platforms = lib.platforms.unix;
  };
})