Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 lib,
3 stdenv,
4 rustPlatform,
5 fetchFromGitHub,
6 pkg-config,
7
8 bzip2,
9 libGL,
10 libX11,
11 libXcursor,
12 libxkbcommon,
13 libXi,
14 moltenvk,
15 sdl3,
16 wayland,
17 zstd,
18}:
19
20rustPlatform.buildRustPackage (finalAttrs: {
21 pname = "gopher64";
22 version = "1.0.17";
23
24 src = fetchFromGitHub {
25 owner = "gopher64";
26 repo = "gopher64";
27 tag = "v${finalAttrs.version}";
28 hash = "sha256-DDFtPISV17jQMECBIqYbbGhZpjYXuNnOq7EiEVtSzgc=";
29 fetchSubmodules = true;
30 leaveDotGit = true;
31 postFetch = ''
32 cd "$out"
33 git rev-parse HEAD > $out/GIT_REV
34 find "$out" -name .git -print0 | xargs -0 rm -rf
35 '';
36 };
37
38 cargoPatches = [
39 # upstream rebuilds SDL3 from source
40 # this patch makes it use the SDL3 library provided by nixpkgs
41 ./use-sdl3-via-pkg-config.patch
42
43 # make the build script use the @GIT_REV@ string that will be substituted in the logic below
44 ./set-git-rev.patch
45 ];
46
47 postPatch = ''
48 # use the file generated in the fetcher to supply the git revision
49 substituteInPlace build.rs \
50 --replace-fail "@GIT_REV@" $(cat GIT_REV)
51 '';
52
53 cargoHash = "sha256-31kEYwlDA6iYcwPZyQU4gM/VLfPNeYcDKhhBqzNp/QE=";
54
55 env.ZSTD_SYS_USE_PKG_CONFIG = true;
56
57 nativeBuildInputs = [
58 pkg-config
59 rustPlatform.bindgenHook
60 ];
61
62 buildInputs = [
63 bzip2
64 sdl3
65 zstd
66 ]
67 ++ lib.optionals stdenv.hostPlatform.isDarwin [
68 moltenvk
69 ];
70
71 # these are dlopen-ed during runtime
72 runtimeDependencies = lib.optionalString stdenv.hostPlatform.isLinux [
73 libGL
74 libxkbcommon
75
76 # for X11
77 libX11
78 libXcursor
79 libXi
80
81 # for wayland
82 wayland
83 ];
84
85 postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
86 patchelf $out/bin/gopher64 --add-rpath ${lib.makeLibraryPath finalAttrs.runtimeDependencies}
87 '';
88
89 meta = {
90 changelog = "https://github.com/gopher64/gopher64/releases/tag/${finalAttrs.src.tag}";
91 description = "N64 emulator written in Rust";
92 homepage = "https://github.com/gopher64/gopher64";
93 license = lib.licenses.gpl3Only;
94 mainProgram = "gopher64";
95 maintainers = with lib.maintainers; [ tomasajt ];
96 };
97})