lol
1{ stdenv, fetchFromGitHub, jdk, maven, writeText, makeWrapper, jre_headless, pcsclite }:
2
3# TODO: This is quite a bit of duplicated logic with gephi. Factor it out?
4stdenv.mkDerivation rec {
5 pname = "global-platform-pro";
6 version = "0.3.10-rc11"; # Waiting for release https://github.com/martinpaljak/GlobalPlatformPro/issues/128
7 describeVersion = "v0.3.10-rc11-0-g8923747"; # git describe --tags --always --long --dirty
8 name = "${pname}-${version}";
9
10 src = fetchFromGitHub {
11 owner = "martinpaljak";
12 repo = "GlobalPlatformPro";
13 rev = "v${version}";
14 sha256 = "0rk81x2y7vx1caxm6wa59fjrfxmjn7s8yxaxm764p8m2qxk3m4y2";
15 };
16
17 # This patch hardcodes the return of a git command the build system tries to
18 # run. As `fetchFromGitHub` doesn't fetch a full-fledged git repository,
19 # this command can only fail at build-time. As a consequence, we include the
20 # `describeVersion` variable defined above here.
21 #
22 # See upstream issue https://github.com/martinpaljak/GlobalPlatformPro/issues/129
23 patches = [ (writeText "${name}-version.patch" ''
24 diff --git a/pom.xml b/pom.xml
25 index 1e5a82d..1aa01fe 100644
26 --- a/pom.xml
27 +++ b/pom.xml
28 @@ -121,14 +121,10 @@
29 </execution>
30 </executions>
31 <configuration>
32 - <executable>git</executable>
33 + <executable>echo</executable>
34 <outputFile>target/generated-resources/pro/javacard/gp/pro_version.txt</outputFile>
35 <arguments>
36 - <argument>describe</argument>
37 - <argument>--tags</argument>
38 - <argument>--always</argument>
39 - <argument>--long</argument>
40 - <argument>--dirty</argument>
41 + <argument>${describeVersion}</argument>
42 </arguments>
43 </configuration>
44 </plugin>
45 '') ];
46
47 deps = stdenv.mkDerivation {
48 name = "${name}-deps";
49 inherit src patches;
50 nativeBuildInputs = [ jdk maven ];
51 installPhase = ''
52 # Download the dependencies
53 while ! mvn package "-Dmaven.repo.local=$out/.m2" -Dmaven.wagon.rto=5000; do
54 echo "timeout, restart maven to continue downloading"
55 done
56
57 # And keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files
58 # with lastModified timestamps inside
59 find "$out/.m2" -type f \
60 -regex '.+\(\.lastUpdated\|resolver-status\.properties\|_remote\.repositories\)' \
61 -delete
62 '';
63 outputHashAlgo = "sha256";
64 outputHashMode = "recursive";
65 outputHash = "15bbi7z9v601all9vr2azh8nk8rpz2vd91yvvw8id6birnbhn3if";
66 };
67
68 nativeBuildInputs = [ jdk maven makeWrapper ];
69
70 buildPhase = ''
71 cp -dpR "${deps}/.m2" ./
72 chmod -R +w .m2
73 mvn package --offline -Dmaven.repo.local="$(pwd)/.m2"
74 '';
75
76 installPhase = ''
77 mkdir -p "$out/lib/java" "$out/share/java"
78 cp -R target/apidocs "$out/doc"
79 cp target/gp.jar "$out/share/java"
80 makeWrapper "${jre_headless}/bin/java" "$out/bin/gp" \
81 --add-flags "-jar '$out/share/java/gp.jar'" \
82 --prefix LD_LIBRARY_PATH : "${pcsclite.out}/lib"
83 '';
84
85 meta = with stdenv.lib; {
86 description = "Command-line utility for managing applets and keys on Java Cards";
87 longDescription = ''
88 This command-line utility can be used to manage applets and keys
89 on Java Cards. It is made available as the `gp` executable.
90
91 The executable requires the PC/SC daemon running for correct execution.
92 If you run NixOS, it can be enabled with `services.pcscd.enable = true;`.
93 '';
94 homepage = https://github.com/martinpaljak/GlobalPlatformPro;
95 license = with licenses; [ lgpl3 ];
96 platforms = platforms.all;
97 };
98}