11{
22 lib ,
33 stdenv ,
4- fetchurl ,
4+ fetchFromGitHub ,
5+ maven ,
56 swt ,
7+ jdk ,
68 jre ,
7- makeWrapper ,
9+ makeBinaryWrapper ,
10+ pkg-config ,
811 alsa-lib ,
912 jack2 ,
1013 fluidsynth ,
1114 libpulseaudio ,
1215 lilv ,
16+ suil ,
17+ qt5 ,
1318 which ,
1419 wrapGAppsHook3 ,
1520 nixosTests ,
21+ fetchpatch ,
1622} :
1723
18- stdenv . mkDerivation ( finalAttrs : {
19- version = "1.6.6" ;
24+ let
25+ swtArtifactId =
26+ "org.eclipse.swt." + ( if stdenv . hostPlatform . isDarwin then "cocoa.macosx" else "gtk.linux" ) ;
27+ buildDir =
28+ "desktop/build-scripts/tuxguitar-"
29+ + ( if stdenv . hostPlatform . isDarwin then "macosx-swt-cocoa" else "linux-swt" ) ;
30+ buildScript = "${ buildDir } /pom.xml" ;
31+ mvnParams = lib . escapeShellArgs [
32+ "-f"
33+ buildScript
34+ "-P"
35+ "native-modules"
36+ "-Dmaven.test.skip=true"
37+ ] ;
38+ ldLibVar = if stdenv . hostPlatform . isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH" ;
39+ classpath = [
40+ "${ swt } /jars/swt.jar"
41+ ]
42+ ++ lib . optionals stdenv . hostPlatform . isLinux [
43+ "$out/lib/tuxguitar.jar"
44+ "$out/lib/itext.jar"
45+ ] ;
46+ libraryPath = [
47+ "$out/lib"
48+ fluidsynth
49+ lilv
50+ ]
51+ ++ lib . optionals stdenv . hostPlatform . isLinux [
52+ swt
53+ alsa-lib
54+ jack2
55+ libpulseaudio
56+ ] ;
57+ wrapperPaths = [
58+ jre
59+ which
60+ ] ;
61+ # FIXME: Makes hash stable across platforms and convert to a single hash.
62+ mvnHashByPlatform = {
63+ "x86_64-linux" = "sha256-7UDFGuOMERvY74mkneusJyuAHfF3U6b4qV4MPHGQYdM=" ;
64+ "aarch64-linux" = "sha256-7UDFGuOMERvY74mkneusJyuAHfF3U6b4qV4MPHGQYdM=" ;
65+ "aarch64-darwin" = "sha256-lfO2YH+yKZWzh3MeQ7baESGmmW7zPdTLs8CjZ/FtLu0=" ;
66+ } ;
67+ wrapperArgs = [
68+ "\ ${gappsWrapperArgs[@]}"
69+ "--prefix"
70+ "PATH"
71+ ":"
72+ ( lib . makeBinPath wrapperPaths )
73+ "--prefix"
74+ ldLibVar
75+ ":"
76+ ( lib . makeLibraryPath libraryPath )
77+ "--prefix"
78+ "CLASSPATH"
79+ ":"
80+ ( lib . concatStringsSep ":" classpath )
81+ ] ;
82+ version = "2.0.1" ;
83+ in
84+ maven . buildMavenPackage {
2085 pname = "tuxguitar" ;
86+ inherit version ;
2187
22- src = fetchurl {
23- url = "https://github.com/helge17/tuxguitar/releases/download/${ finalAttrs . version } /tuxguitar-${ finalAttrs . version } -linux-swt-amd64.tar.gz" ;
24- hash = "sha256-kfPk+IIg5Q4Fc9HMS0kxxCarlbJjVKluIvz8KpDjJLM=" ;
88+ src = fetchFromGitHub {
89+ owner = "helge17" ;
90+ repo = "tuxguitar" ;
91+ tag = version ;
92+ hash = "sha256-USdYj8ebosXkiZpDqyN5J+g1kjyWm225iQlx/szXmLA=" ;
2593 } ;
2694
95+ patches = [
96+ ./fix-include.patch
97+ # Helps a little bit with https://github.com/helge17/tuxguitar/issues/961
98+ ( fetchpatch {
99+ name = "create-new-file" ;
100+ url = "https://github.com/helge17/tuxguitar/commit/3dc828a9b92e932952c2b33d8ee41db734f2fcc0.patch" ;
101+ hash = "sha256-umZlCSCTWqj3tgR+qFcPucEDv5vpaC6zHbDJg/W5KUI=" ;
102+ } )
103+ ] ;
104+
105+ buildOffline = true ;
106+
107+ mvnJdk = jdk ;
108+
109+ mvnHash = (
110+ mvnHashByPlatform . ${ stdenv . system }
111+ or ( lib . warn "Missing mvnHash for ${ stdenv . system } , using lib.fakeHash" lib . fakeHash )
112+ ) ;
113+
114+ mvnParameters = mvnParams ;
115+ mvnDepsParameters = mvnParams ;
116+
117+ mvnFetchExtraArgs = {
118+ dontWrapQtApps = true ;
119+ dontWrapGApps = true ;
120+ preBuild = ''
121+ mkdir -p $out/.m2
122+ mvn install:install-file \
123+ -Dfile=${ swt } /jars/swt.jar \
124+ -DgroupId=org.eclipse.swt \
125+ -DartifactId=${ swtArtifactId } \
126+ -Dpackaging=jar \
127+ -Dversion=4.36 \
128+ -Dmaven.repo.local=$out/.m2
129+ '' ;
130+ postInstall = ''
131+ rm -rf $out/.m2/repository/org/eclipse/swt
132+ find $out -type f -name "maven-metadata-*.xml" -delete
133+ '' ;
134+ } ;
135+
136+ afterDepsSetup = ''
137+ mvn install:install-file \
138+ -Dfile=${ swt } /jars/swt.jar \
139+ -DgroupId=org.eclipse.swt \
140+ -DartifactId=${ swtArtifactId } \
141+ -Dpackaging=jar \
142+ -Dversion=4.36 \
143+ -Dmaven.repo.local=$mvnDeps/.m2
144+ '' ;
145+
27146 nativeBuildInputs = [
28- makeWrapper
147+ makeBinaryWrapper
148+ jdk
149+ pkg-config
150+ ]
151+ ++ lib . optionals stdenv . hostPlatform . isLinux [
29152 wrapGAppsHook3
30153 ] ;
31154
155+ buildInputs = [
156+ swt
157+ fluidsynth
158+ lilv
159+ ]
160+ ++ lib . optionals stdenv . hostPlatform . isLinux [
161+ alsa-lib
162+ jack2
163+ libpulseaudio
164+ suil
165+ qt5 . qtbase
166+ ] ;
167+
168+ dontWrapQtApps = true ;
169+
32170 dontWrapGApps = true ;
33171
34172 installPhase = ''
173+ runHook preInstall
174+
175+ cd ${ buildDir }
176+ ''
177+ # macOS: The build creates tuxguitar-VERSION-macosx-swt-cocoa.app directly
178+ # This directory name already ends with .app and IS the app bundle
179+ + lib . optionalString stdenv . hostPlatform . isDarwin ''
180+ mkdir -p $out/Applications
181+ cp -r target/tuxguitar-9.99-SNAPSHOT-macosx-swt-cocoa.app $out/Applications/TuxGuitar.app
182+
183+ # Fix the launch script to use the Nix JRE instead of bundled JRE
184+ substituteInPlace $out/Applications/TuxGuitar.app/Contents/MacOS/tuxguitar.sh \
185+ --replace-fail 'JAVA="./jre/bin/java"' 'JAVA="${ jre } /bin/java"'
186+
187+ # Ensure the main executable has execute permissions
188+ chmod +x $out/Applications/TuxGuitar.app/Contents/MacOS/tuxguitar.sh
189+
190+ # Symlink doesn't work. We have to create a wrapper script instead
35191 mkdir -p $out/bin
36- cp -r dist lib share $out/
37- cp tuxguitar.sh $out/bin/tuxguitar
192+ makeWrapper "$out/Applications/TuxGuitar.app/Contents/MacOS/tuxguitar.sh" \
193+ "$out/bin/tuxguitar"
194+ ''
195+ # Linux: Install traditional layout
196+ + lib . optionalString stdenv . hostPlatform . isLinux ''
197+ TUXGUITAR_DIR=target/tuxguitar-9.99-SNAPSHOT-linux-swt
198+ mkdir -p $out/{bin,lib}
199+ cp -r $TUXGUITAR_DIR $out/lib/tuxguitar
200+ ln -s $out/lib/tuxguitar/tuxguitar.sh $out/bin/tuxguitar
201+
202+ mkdir -p $out/share
203+ ln -s $out/lib/tuxguitar/share/{applications,man,metainfo,mime,pixmaps} -t $out/share/
204+
205+ # See https://github.com/helge17/tuxguitar/issues/961
206+ mkdir -p $out/share/templates/.source
207+ ln -s $out/lib/tuxguitar/share/templates/ $out/share/templates/.source/tuxguitar
208+ cp /build/source/desktop/build-scripts/common-resources/common-linux/share/templates/tuxguitar.desktop $out/share/templates/
209+ ''
210+ + ''
38211
39- ln -s $out/dist $out/bin/dist
40- ln -s $out/lib $out/bin/lib
41- ln -s $out/share $out/bin/share
212+ runHook postInstall
42213 '' ;
43214
44- postFixup = ''
45- wrapProgram $out/bin/tuxguitar \
46- "'' ${gappsWrapperArgs[@]}" \
47- --prefix PATH : ${
48- lib . makeBinPath [
49- jre
50- which
51- ]
52- } \
53- --prefix LD_LIBRARY_PATH : "$out/lib/:${
54- lib . makeLibraryPath [
55- swt
56- alsa-lib
57- jack2
58- fluidsynth
59- libpulseaudio
60- lilv
61- ]
62- } " \
63- --prefix CLASSPATH : "${ swt } /jars/swt.jar:$out/lib/tuxguitar.jar:$out/lib/itext.jar"
215+ postFixup = lib . optionalString stdenv . hostPlatform . isLinux ''
216+ wrapProgram $out/bin/tuxguitar ${ lib . concatStringsSep " " wrapperArgs }
64217 '' ;
65218
66- passthru . tests = {
67- nixos = nixosTests . tuxguitar ;
219+ passthru = {
220+ tests . nixos = nixosTests . tuxguitar ;
68221 } ;
69222
70223 meta = {
@@ -74,10 +227,12 @@ stdenv.mkDerivation (finalAttrs: {
74227 in Java-SWT. It can open GuitarPro, PowerTab and TablEdit files.
75228 '' ;
76229 homepage = "https://github.com/helge17/tuxguitar" ;
77- sourceProvenance = with lib . sourceTypes ; [ binaryBytecode ] ;
78230 license = lib . licenses . lgpl21Plus ;
79- maintainers = with lib . maintainers ; [ ardumont ] ;
80- platforms = [ "x86_64-linux" ] ;
231+ maintainers = with lib . maintainers ; [
232+ ardumont
233+ mio
234+ ] ;
235+ platforms = builtins . attrNames mvnHashByPlatform ;
81236 mainProgram = "tuxguitar" ;
82237 } ;
83- } )
238+ }
0 commit comments