1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 fetchpatch,
6 cmake,
7 wrapGAppsHook3,
8 wrapQtAppsHook,
9 pkg-config,
10 ninja,
11 alsa-lib,
12 alsa-plugins,
13 freetype,
14 libjack2,
15 lame,
16 libogg,
17 libpulseaudio,
18 libsndfile,
19 libvorbis,
20 portaudio,
21 portmidi,
22 qtbase,
23 qtdeclarative,
24 flac,
25 libopusenc,
26 libopus,
27 tinyxml-2,
28 qt5compat,
29 qtwayland,
30 qtsvg,
31 qtscxml,
32 qtnetworkauth,
33 qttools,
34 nixosTests,
35}:
36
37stdenv.mkDerivation (finalAttrs: {
38 pname = "musescore";
39 version = "4.5.2-unstable-2025-07-03";
40
41 src = fetchFromGitHub {
42 owner = "musescore";
43 repo = "MuseScore";
44 rev = "0ff2476af4e16286ee9f7cf2322715273a0117e0";
45 sha256 = "sha256-0ixQfAyAyRmuIrlPosCV/VucKJYYvxjL2o4pkVb5Sd8=";
46 };
47
48 cmakeFlags = [
49 "-DMUSE_APP_BUILD_MODE=release"
50 # Disable the build and usage of the `/bin/crashpad_handler` utility - it's
51 # not useful on NixOS, see:
52 # https://github.com/musescore/MuseScore/issues/15571
53 "-DMUSE_MODULE_DIAGNOSTICS_CRASHPAD_CLIENT=OFF"
54 # Use our versions of system libraries
55 "-DMUE_COMPILE_USE_SYSTEM_FREETYPE=ON"
56 "-DMUE_COMPILE_USE_SYSTEM_HARFBUZZ=ON"
57 "-DMUE_COMPILE_USE_SYSTEM_TINYXML=ON"
58 # Implies also -DMUE_COMPILE_USE_SYSTEM_OPUS=ON
59 "-DMUE_COMPILE_USE_SYSTEM_OPUSENC=ON"
60 "-DMUE_COMPILE_USE_SYSTEM_FLAC=ON"
61 # Don't bundle qt qml files, relevant really only for darwin, but we set
62 # this for all platforms anyway.
63 "-DMUE_COMPILE_INSTALL_QTQML_FILES=OFF"
64 # Don't build unit tests unless we are going to run them.
65 (lib.cmakeBool "MUSE_ENABLE_UNIT_TESTS" finalAttrs.finalPackage.doCheck)
66 ];
67
68 qtWrapperArgs = [
69 # MuseScore JACK backend loads libjack at runtime.
70 "--prefix ${lib.optionalString stdenv.hostPlatform.isDarwin "DY"}LD_LIBRARY_PATH : ${
71 lib.makeLibraryPath [ libjack2 ]
72 }"
73 ]
74 ++ lib.optionals (stdenv.hostPlatform.isLinux) [
75 "--set ALSA_PLUGIN_DIR ${alsa-plugins}/lib/alsa-lib"
76 ]
77 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
78 # There are some issues with using the wayland backend, see:
79 # https://musescore.org/en/node/321936
80 "--set-default QT_QPA_PLATFORM xcb"
81 ];
82
83 preFixup = ''
84 qtWrapperArgs+=("''${gappsWrapperArgs[@]}")
85 '';
86
87 dontWrapGApps = true;
88
89 nativeBuildInputs = [
90 wrapQtAppsHook
91 cmake
92 qttools
93 pkg-config
94 ninja
95 ]
96 ++ lib.optionals stdenv.hostPlatform.isLinux [
97 # Since https://github.com/musescore/MuseScore/pull/13847/commits/685ac998
98 # GTK3 is needed for file dialogs. Fixes crash with No GSettings schemas error.
99 wrapGAppsHook3
100 ];
101
102 buildInputs = [
103 libjack2
104 freetype
105 lame
106 libogg
107 libpulseaudio
108 libsndfile
109 libvorbis
110 portaudio
111 portmidi
112 flac
113 libopusenc
114 libopus
115 tinyxml-2
116 qtbase
117 qtdeclarative
118 qt5compat
119 qtsvg
120 qtscxml
121 qtnetworkauth
122 ]
123 ++ lib.optionals stdenv.hostPlatform.isLinux [
124 alsa-lib
125 qtwayland
126 ];
127
128 postInstall = lib.optionalString stdenv.hostPlatform.isDarwin ''
129 mkdir -p "$out/Applications"
130 mv "$out/mscore.app" "$out/Applications/mscore.app"
131 mkdir -p $out/bin
132 ln -s $out/Applications/mscore.app/Contents/MacOS/mscore $out/bin/mscore
133 '';
134
135 # muse-sounds-manager installs Muse Sounds sampler libMuseSamplerCoreLib.so.
136 # It requires that argv0 of the calling process ends with "/mscore" or "/MuseScore-4".
137 # We need to ensure this in two cases:
138 #
139 # 1) when the user invokes MuseScore as "mscore" on the command line or from
140 # the .desktop file, and the normal argv0 is "mscore" (no "/");
141 # 2) when MuseScore invokes itself via File -> New, and the normal argv0 is
142 # the target of /proc/self/exe, which in Nixpkgs was "{...}/.mscore-wrapped"
143 #
144 # In order to achieve (2) we install the final binary as $out/libexec/mscore, and
145 # in order to achieve (1) we use makeWrapper without --inherit-argv0.
146 #
147 # wrapQtAppsHook uses wrapQtApp -> wrapProgram -> makeBinaryWrapper --inherit-argv0
148 # so we disable it and explicitly use makeQtWrapper.
149 #
150 # TODO: check if something like this is also needed for macOS.
151 dontWrapQtApps = stdenv.hostPlatform.isLinux;
152 postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
153 mkdir -p $out/libexec
154 mv $out/bin/mscore $out/libexec
155 makeQtWrapper $out/libexec/mscore $out/bin/mscore
156 '';
157
158 # Don't run bundled upstreams tests, as they require a running X window system.
159 doCheck = false;
160
161 passthru.tests = nixosTests.musescore;
162
163 meta = with lib; {
164 description = "Music notation and composition software";
165 homepage = "https://musescore.org/";
166 license = licenses.gpl3Only;
167 maintainers = with maintainers; [
168 vandenoever
169 doronbehar
170 orivej
171 ];
172 mainProgram = "mscore";
173 platforms = platforms.unix;
174 };
175})