nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv
2, lib
3, fetchFromGitHub
4, pkg-config
5, autoPatchelfHook
6, installShellFiles
7, scons
8, vulkan-loader
9, libGL
10, libX11
11, libXcursor
12, libXinerama
13, libXext
14, libXrandr
15, libXrender
16, libXi
17, libXfixes
18, libxkbcommon
19, alsa-lib
20, libpulseaudio
21, dbus
22, speechd-minimal
23, fontconfig
24, udev
25, withDebug ? false
26, withPlatform ? "linuxbsd"
27, withTarget ? "editor"
28, withPrecision ? "single"
29, withPulseaudio ? true
30, withDbus ? true
31, withSpeechd ? true
32, withFontconfig ? true
33, withUdev ? true
34, withTouch ? true
35}:
36
37assert lib.asserts.assertOneOf "withPrecision" withPrecision [ "single" "double" ];
38
39let
40 mkSconsFlagsFromAttrSet = lib.mapAttrsToList (k: v:
41 if builtins.isString v
42 then "${k}=${v}"
43 else "${k}=${builtins.toJSON v}");
44in
45stdenv.mkDerivation rec {
46 pname = "godot4";
47 version = "4.2.2-stable";
48 commitHash = "15073afe3856abd2aa1622492fe50026c7d63dc1";
49
50 src = fetchFromGitHub {
51 owner = "godotengine";
52 repo = "godot";
53 rev = commitHash;
54 hash = "sha256-anJgPEeHIW2qIALMfPduBVgbYYyz1PWCmPsZZxS9oHI=";
55 };
56
57 nativeBuildInputs = [
58 pkg-config
59 autoPatchelfHook
60 installShellFiles
61 ];
62
63 buildInputs = [
64 scons
65 ];
66
67 runtimeDependencies = [
68 vulkan-loader
69 libGL
70 libX11
71 libXcursor
72 libXinerama
73 libXext
74 libXrandr
75 libXrender
76 libXi
77 libXfixes
78 libxkbcommon
79 alsa-lib
80 ]
81 ++ lib.optional withPulseaudio libpulseaudio
82 ++ lib.optional withDbus dbus
83 ++ lib.optional withDbus dbus.lib
84 ++ lib.optional withSpeechd speechd-minimal
85 ++ lib.optional withFontconfig fontconfig
86 ++ lib.optional withFontconfig fontconfig.lib
87 ++ lib.optional withUdev udev;
88
89 enableParallelBuilding = true;
90
91 # Set the build name which is part of the version. In official downloads, this
92 # is set to 'official'. When not specified explicitly, it is set to
93 # 'custom_build'. Other platforms packaging Godot (Gentoo, Arch, Flatpack
94 # etc.) usually set this to their name as well.
95 #
96 # See also 'methods.py' in the Godot repo and 'build' in
97 # https://docs.godotengine.org/en/stable/classes/class_engine.html#class-engine-method-get-version-info
98 BUILD_NAME = "nixpkgs";
99
100 # Required for the commit hash to be included in the version number.
101 #
102 # `methods.py` reads the commit hash from `.git/HEAD` and manually follows
103 # refs. Since we just write the hash directly, there is no need to emulate any
104 # other parts of the .git directory.
105 #
106 # See also 'hash' in
107 # https://docs.godotengine.org/en/stable/classes/class_engine.html#class-engine-method-get-version-info
108 preConfigure = ''
109 mkdir -p .git
110 echo ${commitHash} > .git/HEAD
111 '';
112
113 sconsFlags = mkSconsFlagsFromAttrSet {
114 # Options from 'SConstruct'
115 production = true; # Set defaults to build Godot for use in production
116 platform = withPlatform;
117 target = withTarget;
118 precision = withPrecision; # Floating-point precision level
119 debug_symbols = withDebug;
120
121 # Options from 'platform/linuxbsd/detect.py'
122 pulseaudio = withPulseaudio; # Use PulseAudio
123 dbus = withDbus; # Use D-Bus to handle screensaver and portal desktop settings
124 speechd = withSpeechd; # Use Speech Dispatcher for Text-to-Speech support
125 fontconfig = withFontconfig; # Use fontconfig for system fonts support
126 udev = withUdev; # Use udev for gamepad connection callbacks
127 touch = withTouch; # Enable touch events
128 };
129
130 dontStrip = withDebug;
131
132 outputs = [ "out" "man" ];
133
134 installPhase = ''
135 runHook preInstall
136
137 mkdir -p "$out/bin"
138 cp bin/godot.* $out/bin/godot4
139
140 installManPage misc/dist/linux/godot.6
141
142 mkdir -p "$out"/share/{applications,icons/hicolor/scalable/apps}
143 cp misc/dist/linux/org.godotengine.Godot.desktop "$out/share/applications/org.godotengine.Godot4.desktop"
144 substituteInPlace "$out/share/applications/org.godotengine.Godot4.desktop" \
145 --replace "Exec=godot" "Exec=$out/bin/godot4" \
146 --replace "Godot Engine" "Godot Engine 4"
147 cp icon.svg "$out/share/icons/hicolor/scalable/apps/godot.svg"
148 cp icon.png "$out/share/icons/godot.png"
149
150 runHook postInstall
151 '';
152
153 meta = {
154 homepage = "https://godotengine.org";
155 description = "Free and Open Source 2D and 3D game engine";
156 license = lib.licenses.mit;
157 platforms = [ "i686-linux" "x86_64-linux" "aarch64-linux" ];
158 maintainers = with lib.maintainers; [ shiryel superherointj ];
159 mainProgram = "godot4";
160 };
161}