34 withFontconfig ? true,
36 withPlatform ? "linuxbsd",
37 withPrecision ? "single",
38 withPulseaudio ? true,
40 withTarget ? "editor",
43 # Wayland in Godot requires X11 until upstream fix is merged
44 # https://github.com/godotengine/godot/pull/73504
48 assert lib.asserts.assertOneOf "withPrecision" withPrecision [
53 mkSconsFlagsFromAttrSet = lib.mapAttrsToList (
54 k: v: if builtins.isString v then "${k}=${v}" else "${k}=${builtins.toJSON v}"
57 suffix = if withMono then "-mono" else "";
60 pname = "godot4${suffix}";
61 version = "4.3-stable";
62 commitHash = "77dcf97d82cbfe4e4615475fa52ca03da645dbd8";
64 src = fetchFromGitHub {
65 owner = "godotengine";
68 hash = "sha256-v2lBD3GEL8CoIwBl3UoLam0dJxkLGX0oneH6DiWkEsM=";
75 separateDebugInfo = true;
77 # Set the build name which is part of the version. In official downloads, this
78 # is set to 'official'. When not specified explicitly, it is set to
79 # 'custom_build'. Other platforms packaging Godot (Gentoo, Arch, Flatpack
80 # etc.) usually set this to their name as well.
82 # See also 'methods.py' in the Godot repo and 'build' in
83 # https://docs.godotengine.org/en/stable/classes/class_engine.html#class-engine-method-get-version-info
84 BUILD_NAME = "nixpkgs";
86 # Required for the commit hash to be included in the version number.
88 # `methods.py` reads the commit hash from `.git/HEAD` and manually follows
89 # refs. Since we just write the hash directly, there is no need to emulate any
90 # other parts of the .git directory.
93 # https://docs.godotengine.org/en/stable/classes/class_engine.html#class-engine-method-get-version-info
97 echo ${commitHash} > .git/HEAD
99 + lib.optionalString withMono ''
100 dotnet restore modules/mono/glue/GodotSharp/GodotSharp.sln
101 dotnet restore modules/mono/editor/GodotTools/GodotTools.sln
102 dotnet restore modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk.sln
105 # From: https://github.com/godotengine/godot/blob/4.2.2-stable/SConstruct
106 sconsFlags = mkSconsFlagsFromAttrSet {
107 # Options from 'SConstruct'
108 precision = withPrecision; # Floating-point precision level
109 production = true; # Set defaults to build Godot for use in production
110 platform = withPlatform;
112 debug_symbols = true;
114 # Options from 'platform/linuxbsd/detect.py'
115 dbus = withDbus; # Use D-Bus to handle screensaver and portal desktop settings
116 fontconfig = withFontconfig; # Use fontconfig for system fonts support
117 pulseaudio = withPulseaudio; # Use PulseAudio
118 speechd = withSpeechd; # Use Speech Dispatcher for Text-to-Speech support
119 touch = withTouch; # Enable touch events
120 udev = withUdev; # Use udev for gamepad connection callbacks
121 wayland = withWayland; # Compile with Wayland support
122 x11 = withX11; # Compile with X11 support
124 module_mono_enabled = withMono;
127 enableParallelBuilding = true;
131 depsBuildBuild = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
132 buildPackages.stdenv.cc
143 ++ lib.optionals withWayland [ wayland-scanner ]
144 ++ lib.optionals withMono [
149 postBuild = lib.optionalString withMono ''
150 echo "Generating Glue"
151 if [[ ${withPrecision} == *double* ]]; then
152 bin/godot.${withPlatform}.${withTarget}.${withPrecision}.x86_64.mono --headless --generate-mono-glue modules/mono/glue
154 bin/godot.${withPlatform}.${withTarget}.x86_64.mono --headless --generate-mono-glue modules/mono/glue
156 echo "Building C#/.NET Assemblies"
157 python modules/mono/build_scripts/build_assemblies.py --godot-output-dir bin --precision=${withPrecision}
160 runtimeDependencies =
166 ++ lib.optionals withX11 [
177 ++ lib.optionals withWayland [
181 ++ lib.optionals withDbus [
185 ++ lib.optionals withFontconfig [
189 ++ lib.optionals withPulseaudio [ libpulseaudio ]
190 ++ lib.optionals withSpeechd [ speechd-minimal ]
191 ++ lib.optionals withUdev [ udev ];
198 cp bin/godot.* $out/bin/godot4${suffix}
200 installManPage misc/dist/linux/godot.6
202 mkdir -p "$out"/share/{applications,icons/hicolor/scalable/apps}
203 cp misc/dist/linux/org.godotengine.Godot.desktop "$out/share/applications/org.godotengine.Godot4${suffix}.desktop"
204 substituteInPlace "$out/share/applications/org.godotengine.Godot4${suffix}.desktop" \
205 --replace "Exec=godot" "Exec=$out/bin/godot4${suffix}" \
206 --replace "Godot Engine" "Godot Engine 4"
207 cp icon.svg "$out/share/icons/hicolor/scalable/apps/godot.svg"
208 cp icon.png "$out/share/icons/godot.png"
210 + lib.optionalString withMono ''
211 cp -r bin/GodotSharp/ $out/bin/
212 wrapProgram $out/bin/godot4${suffix} \
213 --set DOTNET_ROOT ${dotnet-sdk_8} \
225 changelog = "https://github.com/godotengine/godot/releases/tag/${version}";
226 description = "Free and Open Source 2D and 3D game engine";
227 homepage = "https://godotengine.org";
228 license = lib.licenses.mit;
232 ] ++ lib.optional (!withMono) "i686-linux";
233 maintainers = with lib.maintainers; [
237 mainProgram = "godot4${suffix}";
242 stdenv.mkDerivation (
245 dotnetCorePackages.addNuGetDeps {
246 nugetDeps = ./deps.nix;
247 overrideFetchAttrs = old: rec {
248 runtimeIds = map (system: dotnetCorePackages.systemToDotnetRid system) old.meta.platforms;
251 ++ lib.concatLists (lib.attrValues (lib.getAttrs runtimeIds dotnet-sdk_8.targetPackages));