1{
2 lib,
3 fetchFromGitHub,
4 buildGoModule,
5 alsa-lib,
6 libGL,
7 libX11,
8 libXcursor,
9 libXext,
10 libXi,
11 libXinerama,
12 libXrandr,
13 libXxf86vm,
14 go-licenses,
15 pkg-config,
16 zip,
17 advancecomp,
18 makeWrapper,
19 nixosTests,
20 strip-nondeterminism,
21}:
22
23buildGoModule rec {
24 pname = "aaaaxy";
25 version = "1.6.271";
26
27 src = fetchFromGitHub {
28 owner = "divVerent";
29 repo = "aaaaxy";
30 tag = "v${version}";
31 hash = "sha256-/nSJ1FT9FE856yrupbouRzqpRzZhKfYAq1fVBBvMVmY=";
32 fetchSubmodules = true;
33 };
34
35 vendorHash = "sha256-DJvlyfCynz+M5BQ4XDYcdzb3QP5ycDPcF4B+fQ4FRRA=";
36
37 buildInputs = [
38 alsa-lib
39 libGL
40 libX11
41 libXcursor
42 libXext
43 libXi
44 libXinerama
45 libXrandr
46 libXxf86vm
47 ];
48
49 nativeBuildInputs = [
50 go-licenses
51 pkg-config
52 zip
53 advancecomp
54 makeWrapper
55 strip-nondeterminism
56 ];
57
58 outputs = [
59 "out"
60 "testing_infra"
61 ];
62
63 postPatch = ''
64 # Without patching, "go run" fails with the error message:
65 # package github.com/google/go-licenses: no Go files in /build/source/vendor/github.com/google/go-licenses
66 substituteInPlace scripts/build-licenses.sh --replace-fail \
67 '$GO run ''${GO_FLAGS} github.com/google/go-licenses' 'go-licenses'
68
69 patchShebangs scripts/
70 substituteInPlace scripts/regression-test-demo.sh \
71 --replace-fail 'sh scripts/run-timedemo.sh' "$testing_infra/scripts/run-timedemo.sh"
72
73 substituteInPlace Makefile --replace-fail \
74 'CPPFLAGS ?= -DNDEBUG' \
75 'CPPFLAGS ?= -DNDEBUG -D_GLFW_GLX_LIBRARY=\"${lib.getLib libGL}/lib/libGL.so\" -D_GLFW_EGL_LIBRARY=\"${lib.getLib libGL}/lib/libEGL.so\"'
76 '';
77
78 overrideModAttrs = (
79 _: {
80 # We can't patch in the path to libGL directly because
81 # this is a fixed output derivation and when the path to libGL
82 # changes, the hash would change.
83 # To work around this, use environment variables.
84 postBuild = ''
85 substituteInPlace 'vendor/github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl/procaddr_linbsd.go' \
86 --replace-fail \
87 'import (' \
88 'import ("os"' \
89 --replace-fail \
90 '{"libGL.so", "libGL.so.2", "libGL.so.1", "libGL.so.0"}' \
91 '{os.Getenv("EBITENGINE_LIBGL")}' \
92 --replace-fail \
93 '{"libGLESv2.so", "libGLESv2.so.2", "libGLESv2.so.1", "libGLESv2.so.0"}' \
94 '{os.Getenv("EBITENGINE_LIBGLESv2")}'
95 '';
96 }
97 );
98
99 makeFlags = [
100 "BUILDTYPE=release"
101 ];
102
103 buildPhase = ''
104 runHook preBuild
105 AAAAXY_BUILD_USE_VERSION_FILE=true make $makeFlags
106 runHook postBuild
107 '';
108
109 postInstall = ''
110 install -Dm755 'aaaaxy' -t "$out/bin/"
111 install -Dm444 'aaaaxy.svg' -t "$out/share/icons/hicolor/scalable/apps/"
112 install -Dm644 'aaaaxy.png' -t "$out/share/icons/hicolor/128x128/apps/"
113 install -Dm644 'aaaaxy.desktop' -t "$out/share/applications/"
114 install -Dm644 'io.github.divverent.aaaaxy.metainfo.xml' -t "$out/share/metainfo/"
115
116 wrapProgram $out/bin/aaaaxy \
117 --set EBITENGINE_LIBGL '${lib.getLib libGL}/lib/libGL.so' \
118 --set EBITENGINE_LIBGLESv2 '${lib.getLib libGL}/lib/libGLESv2.so'
119
120 install -Dm755 'scripts/run-timedemo.sh' -t "$testing_infra/scripts/"
121 install -Dm755 'scripts/regression-test-demo.sh' -t "$testing_infra/scripts/"
122 install -Dm644 'assets/demos/benchmark.dem' -t "$testing_infra/assets/demos/"
123 '';
124
125 passthru.tests = {
126 aaaaxy = nixosTests.aaaaxy;
127 };
128
129 strictDeps = true;
130
131 meta = {
132 description = "Nonlinear 2D puzzle platformer taking place in impossible spaces";
133 mainProgram = "aaaaxy";
134 homepage = "https://divverent.github.io/aaaaxy/";
135 license = lib.licenses.asl20;
136 maintainers = with lib.maintainers; [ Luflosi ];
137 platforms = lib.platforms.linux;
138 };
139}