biglybt: 3.5.0.0 -> 3.6.0.0
[NixPkgs.git] / pkgs / applications / office / jabref / default.nix
blob282e62584cff47e79f09656230ebf47df130d38e
1 { lib
2 , stdenv
3 , fetchurl
4 , fetchFromGitHub
5 , wrapGAppsHook
6 , makeDesktopItem
7 , copyDesktopItems
8 , unzip
9 , xdg-utils
10 , gtk3
11 , jdk
12 , gradle
13 , perl
14 , python3
17 let
18   versionReplace = {
19     easybind = {
20       snapshot = "2.2.1-SNAPSHOT";
21       pin = "2.2.1-20230117.075740-16";
22     };
23   };
24   jackson-datatype-jsr310 = fetchurl {
25     url = "https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.15.3/jackson-datatype-jsr310-2.15.3.jar";
26     hash = "sha256-vqHXgAnrxOXVSRij967F2p+9CfZiwZGiF//PN+hSfF4=";
27   };
29 stdenv.mkDerivation rec {
30   version = "5.12";
31   pname = "jabref";
33   src = fetchFromGitHub {
34     owner = "JabRef";
35     repo = "jabref";
36     rev = "v${version}";
37     hash = "sha256-+ltd9hItmMkEpKzX6TFfFy5fiOkLBK/tQNsh8OVDeoc=";
38     fetchSubmodules = true;
39   };
41   desktopItems = [
42     (makeDesktopItem {
43       comment = meta.description;
44       name = "JabRef";
45       desktopName = "JabRef";
46       genericName = "Bibliography manager";
47       categories = [ "Office" ];
48       icon = "jabref";
49       exec = "JabRef %U";
50       startupWMClass = "org.jabref.gui.JabRefMain";
51       mimeTypes = [ "text/x-bibtex" ];
52     })
53   ];
55   deps = stdenv.mkDerivation {
56     pname = "${pname}-deps";
57     inherit src version postPatch;
59     nativeBuildInputs = [ gradle perl ];
60     buildPhase = ''
61       export GRADLE_USER_HOME=$(mktemp -d)
62       gradle --no-daemon downloadDependencies -Dos.arch=amd64
63       gradle --no-daemon downloadDependencies -Dos.arch=aarch64
64     '';
65     # perl code mavenizes pathes (com.squareup.okio/okio/1.13.0/a9283170b7305c8d92d25aff02a6ab7e45d06cbe/okio-1.13.0.jar -> com/squareup/okio/okio/1.13.0/okio-1.13.0.jar)
66     installPhase = ''
67       find $GRADLE_USER_HOME/caches/modules-2/ -type f -regex '.*\.\(jar\|pom\)' \
68         | perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/$x/$3/$4/''${\($5 =~ s/-jvm//r)}" #e' \
69         | sh
70       mv $out/com/tobiasdiez/easybind/${versionReplace.easybind.pin} \
71         $out/com/tobiasdiez/easybind/${versionReplace.easybind.snapshot}
72       # This is used but not cached by Gradle.
73       cp ${jackson-datatype-jsr310} $out/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.15.3/jackson-datatype-jsr310-2.15.3.jar
74     '';
75     # Don't move info to share/
76     forceShare = [ "dummy" ];
77     outputHashMode = "recursive";
78     outputHash = "sha256-baP/zNgcc6oYwwbWvT7ontULcKKCw0rTQRkdZMgcWfY=";
79   };
81   postPatch = ''
82     # Pin the version
83     substituteInPlace build.gradle \
84       --replace 'com.tobiasdiez:easybind:${versionReplace.easybind.snapshot}' \
85         'com.tobiasdiez:easybind:${versionReplace.easybind.pin}'
87     # Disable update check
88     substituteInPlace src/main/java/org/jabref/preferences/JabRefPreferences.java \
89       --replace 'VERSION_CHECK_ENABLED, Boolean.TRUE' \
90         'VERSION_CHECK_ENABLED, Boolean.FALSE'
92     # Find OpenOffice/LibreOffice binary
93     substituteInPlace src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java \
94       --replace '/usr' '/run/current-system/sw'
96     # Don't fetch predatory sources. These source are fetched from online webpages.
97     sed -i -e '/new PJSource/,/);/c);' src/main/java/org/jabref/logic/journals/predatory/PredatoryJournalListCrawler.java
99     # Add back downloadDependencies task for deps download which is removed upstream in https://github.com/JabRef/jabref/pull/10326
100     cat <<EOF >> build.gradle
101     task downloadDependencies {
102       description "Pre-downloads *most* dependencies"
103       doLast {
104         configurations.getAsMap().each { name, config ->
105           println "Retrieving dependencies for $name"
106           try {
107             config.files
108           } catch (e) {
109             // some cannot be resolved, just log them
110             project.logger.info e.message
111           }
112         }
113       }
114     }
115     EOF
116   '';
118   preBuild = ''
119     # Use the local packages from -deps
120     sed -i -e '/repositories {/a maven { url uri("${deps}") }' \
121       build.gradle \
122       settings.gradle
123   '';
125   nativeBuildInputs = [
126     jdk
127     gradle
128     wrapGAppsHook
129     copyDesktopItems
130     unzip
131   ];
133   buildInputs = [
134     gtk3
135     python3
136   ];
138   buildPhase = ''
139     runHook preBuild
141     export GRADLE_USER_HOME=$(mktemp -d)
142     gradle \
143       --offline \
144       --no-daemon \
145       -PprojVersion="${version}" \
146       -PprojVersionInfo="${version} NixOS" \
147       -Dorg.gradle.java.home=${jdk} \
148       assemble
150     runHook postBuild
151   '';
153   dontWrapGApps = true;
155   installPhase = ''
156     runHook preInstall
158     install -dm755 $out/share/java/jabref
159     install -Dm644 LICENSE $out/share/licenses/jabref/LICENSE
160     install -Dm644 src/main/resources/icons/jabref.svg $out/share/pixmaps/jabref.svg
162     # script to support browser extensions
163     install -Dm755 buildres/linux/jabrefHost.py $out/lib/jabrefHost.py
164     patchShebangs $out/lib/jabrefHost.py
165     install -Dm644 buildres/linux/native-messaging-host/firefox/org.jabref.jabref.json $out/lib/mozilla/native-messaging-hosts/org.jabref.jabref.json
166     sed -i -e "s|/opt/jabref|$out|" $out/lib/mozilla/native-messaging-hosts/org.jabref.jabref.json
168     # Resources in the jar can't be found, workaround copied from AUR
169     cp -r build/resources $out/share/java/jabref
171     tar xf build/distributions/JabRef-${version}.tar -C $out --strip-components=1
173     # workaround for https://github.com/NixOS/nixpkgs/issues/162064
174     unzip $out/lib/javafx-web-*-*.jar libjfxwebkit.so -d $out/lib/
176     DEFAULT_JVM_OPTS=$(sed -n -E "s/^DEFAULT_JVM_OPTS='(.*)'$/\1/p" $out/bin/JabRef | sed -e "s|\$APP_HOME|$out|g" -e 's/"//g')
178     runHook postInstall
179   '';
181   postFixup = ''
182     rm $out/bin/*
184     # put this in postFixup because some gappsWrapperArgs are generated in gappsWrapperArgsHook in preFixup
185     makeWrapper ${jdk}/bin/java $out/bin/JabRef \
186       "''${gappsWrapperArgs[@]}" \
187       --suffix PATH : ${lib.makeBinPath [ xdg-utils ]} \
188       --add-flags "-Djava.library.path=$out/lib/ --patch-module org.jabref=$out/share/java/jabref/resources/main" \
189       --add-flags "$DEFAULT_JVM_OPTS"
191     # lowercase alias (for convenience and required for browser extensions)
192     ln -sf $out/bin/JabRef $out/bin/jabref
193   '';
195   meta = with lib; {
196     description = "Open source bibliography reference manager";
197     homepage = "https://www.jabref.org";
198     sourceProvenance = with sourceTypes; [
199       fromSource
200       binaryBytecode # source bundles dependencies as jars
201       binaryNativeCode # source bundles dependencies as jars
202     ];
203     license = licenses.mit;
204     platforms = [ "x86_64-linux" "aarch64-linux" ];
205     maintainers = with maintainers; [ gebner linsui ];
206   };