nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 gradle_8,
6 copyDesktopItems,
7 makeDesktopItem,
8 makeWrapper,
9 jre,
10 libGL,
11 libX11,
12 libXtst,
13 libxkbcommon,
14 libxcb,
15 libXt,
16 libXinerama,
17}:
18
19let
20 gradle = gradle_8;
21
22 libPath = lib.makeLibraryPath [
23 # used by the Java2D OpenGL backend
24 libGL
25 # jnativehook dependencies
26 libX11
27 libXtst
28 libxkbcommon
29 libxcb
30 libXt
31 libXinerama
32 ];
33in
34stdenv.mkDerivation (finalAttrs: {
35 pname = "keyspersecond";
36 version = "8.9";
37
38 src = fetchFromGitHub {
39 owner = "RoanH";
40 repo = "KeysPerSecond";
41 rev = "v${finalAttrs.version}";
42 hash = "sha256-DGpXbCInq+RS56Ae5Y6xzyWqwXAm26c0vOYrFqDvl+8=";
43 };
44
45 patches = [
46 # deprecated shadowJar.archiveName, application.mainClassName
47 # patches already in `master` branch, but no new release yet
48 # and would be spread along multiple cherry-picks
49 ./gradleShadowJar.patch
50 ];
51
52 sourceRoot = "${finalAttrs.src.name}/KeysPerSecond";
53
54 nativeBuildInputs = [
55 gradle
56 copyDesktopItems
57 makeWrapper
58 ];
59
60 mitmCache = gradle.fetchDeps {
61 inherit (finalAttrs) pname;
62 data = ./deps.json;
63 };
64
65 # this is required for using mitm-cache on Darwin
66 __darwinAllowLocalNetworking = true;
67
68 gradleFlags = "-PrefName=v${finalAttrs.version}";
69
70 installPhase = ''
71 runHook preInstall
72
73 install -Dm644 resources/kps.png $out/share/icons/hicolor/64x64/apps/keyspersecond.png
74 install -Dm644 build/libs/KeysPerSecond-v*.jar $out/share/keyspersecond/KeysPerSecond.jar
75
76 # Note: we need to enable the Java2D OpenGL backend for proper transparency support
77 makeWrapper ${jre}/bin/java $out/bin/KeysPerSecond \
78 --prefix LD_LIBRARY_PATH : ${libPath} \
79 --add-flags "-Dsun.java2d.opengl=True" \
80 --add-flags "-jar $out/share/keyspersecond/KeysPerSecond.jar"
81
82 runHook postInstall
83 '';
84
85 desktopItems = [
86 (makeDesktopItem {
87 name = "keyspersecond";
88 desktopName = "KeysPerSecond";
89 exec = "KeysPerSecond";
90 icon = "keyspersecond";
91 comment = finalAttrs.meta.description;
92 categories = [ "Utility" ];
93 })
94 ];
95
96 meta = {
97 changelog = "https://github.com/RoanH/KeysPerSecond/blob/${finalAttrs.src.rev}/CHANGELOG.md";
98 description = "Keys-per-second meter and counter for rhythm games";
99 homepage = "https://github.com/RoanH/KeysPerSecond";
100 license = lib.licenses.gpl3Only;
101 mainProgram = "KeysPerSecond";
102 maintainers = with lib.maintainers; [ tomasajt ];
103 platforms = jre.meta.platforms;
104 sourceProvenance = with lib.sourceTypes; [
105 fromSource
106 binaryBytecode # deps
107 binaryNativeCode # jnativehook shared library
108 ];
109 };
110})