godot3: refactor and rename from godot

The godot base derivation was implemented by passing a recursive
attrset to mkDerivation. This is problematic because recursive
references to attributes that are later overridden don't notice the
override. Switched to the approach of giving mkDerivation a lambda
that receives a self argument, which allows recursive references to
the final value after overrides are applied.

The related derivations (for export templates, headless, and server
builds of godot) duplicated content from the base derivation. This
refactor eliminated that by using overridable attributes to
parameterize the scripts.

The main motivation for this refactor was to help me add derivations
for mono builds of godot.

Renamed to godot3 to distinguish from version 4, which is a complete
rewrite and effectively a different tool altogether.
This commit is contained in:
rotaerk 2022-09-11 20:05:50 -04:00
parent 07be8b4c39
commit e138e656c7
13 changed files with 241 additions and 172 deletions

View file

@ -1,4 +1,21 @@
{ lib, stdenv, fetchFromGitHub, godot-headless, godot-export-templates, nix-update-script }:
{ lib
, stdenv
, alsa-lib
, autoPatchelfHook
, fetchFromGitHub
, godot3-headless
, godot3-export-templates
, libGLU
, libpulseaudio
, libX11
, libXcursor
, libXi
, libXinerama
, libXrandr
, libXrender
, nix-update-script
, udev
}:
let
preset =
@ -19,7 +36,18 @@ in stdenv.mkDerivation (finalAttrs: {
};
nativeBuildInputs = [
godot-headless
autoPatchelfHook
godot3-headless
];
buildInputs = [
libGLU
libX11
libXcursor
libXi
libXinerama
libXrandr
libXrender
];
buildPhase = ''
@ -27,10 +55,10 @@ in stdenv.mkDerivation (finalAttrs: {
export HOME=$(mktemp -d)
mkdir -p $HOME/.local/share/godot/
ln -s "${godot-export-templates}/share/godot/templates" "$HOME/.local/share/godot/templates"
ln -s "${godot3-export-templates}/share/godot/templates" "$HOME/.local/share/godot/templates"
mkdir -p build
godot-headless -v --export "${preset}" ./build/pixelorama
godot-headless -v --export-pack "${preset}" ./build/pixelorama.pck
godot3-headless -v --export "${preset}" ./build/pixelorama
godot3-headless -v --export-pack "${preset}" ./build/pixelorama.pck
runHook postBuild
'';
@ -47,6 +75,12 @@ in stdenv.mkDerivation (finalAttrs: {
runHook postInstall
'';
runtimeDependencies = map lib.getLib [
alsa-lib
libpulseaudio
udev
];
passthru.updateScript = nix-update-script { };
meta = with lib; {

View file

@ -2,15 +2,17 @@
, stdenv
, fetchFromGitHub
, autoPatchelfHook
, copyDesktopItems
, makeDesktopItem
, godot-export-templates
, godot-headless
, godot3-export-templates
, godot3-headless
, alsa-lib
, libGL
, libGLU
, libpulseaudio
, libX11
, libXcursor
, libXext
@ -41,8 +43,9 @@ stdenv.mkDerivation rec {
};
nativeBuildInputs = [
autoPatchelfHook
copyDesktopItems
godot-headless
godot3-headless
];
buildInputs = [
@ -83,11 +86,11 @@ stdenv.mkDerivation rec {
# Link the export-templates to the expected location. The --export commands
# expects the template-file at .../templates/{godot-version}.stable/linux_x11_64_release
mkdir -p $HOME/.local/share/godot
ln -s ${godot-export-templates}/share/godot/templates $HOME/.local/share/godot
ln -s ${godot3-export-templates}/share/godot/templates $HOME/.local/share/godot
mkdir -p $out/share/lorien
godot-headless --path lorien --export "${preset}" $out/share/lorien/lorien
godot3-headless --path lorien --export "${preset}" $out/share/lorien/lorien
runHook postBuild
'';
@ -110,6 +113,12 @@ stdenv.mkDerivation rec {
runHook postInstall
'';
runtimeDependencies = map lib.getLib [
alsa-lib
libpulseaudio
udev
];
meta = with lib; {
homepage = "https://github.com/mbrlabs/Lorien";
description = "An infinite canvas drawing/note-taking app";

View file

@ -1,7 +1,7 @@
{ lib
, python3Packages
, fetchFromGitHub
, godot-server
, godot3-server
}:
let lark080 = python3Packages.lark.overrideAttrs (old: rec {
@ -43,12 +43,12 @@ python3Packages.buildPythonApplication rec {
nativeCheckInputs = with python3Packages; [
pytestCheckHook
hypothesis
godot-server
godot3-server
];
preCheck =
let
godotServerMajorVersion = lib.versions.major godot-server.version;
godotServerMajorVersion = lib.versions.major godot3-server.version;
gdtoolkitMajorVersion = lib.versions.major version;
msg = ''
gdtoolkit major version ${gdtoolkitMajorVersion} does not match godot-server major version ${godotServerMajorVersion}!

View file

@ -0,0 +1,7 @@
{ godot3-headless }:
godot3-headless.overrideAttrs (self: base: {
pname = "godot3-debug-server";
godotBuildDescription = "debug server";
shouldBuildTools = false;
})

View file

@ -1,109 +1,166 @@
{ stdenv
, lib
{ lib
, stdenv
, alsa-lib
, alsa-plugins
, autoPatchelfHook
, fetchFromGitHub
, scons
, pkg-config
, udev
, freetype
, installShellFiles
, libGLU
, libpulseaudio
, libX11
, libXcursor
, libXext
, libXfixes
, libXi
, libXinerama
, libXrandr
, libXrender
, libpulseaudio
, libXi
, libXext
, libXfixes
, freetype
, openssl
, alsa-lib
, alsa-plugins
, makeWrapper
, libGLU
, zlib
, openssl
, pkg-config
, scons
, udev
, yasm
, withUdev ? true
, zlib
}:
let
options = {
touch = libXi != null;
pulseaudio = false;
udev = withUdev;
};
in
stdenv.mkDerivation rec {
pname = "godot";
stdenv.mkDerivation (self: {
pname = "godot3";
version = "3.5.2";
godotBuildDescription = "X11 tools";
src = fetchFromGitHub {
owner = "godotengine";
repo = "godot";
rev = "${version}-stable";
rev = "${self.version}-stable";
sha256 = "sha256-C+1J5N0ETL1qKust+2xP9uB4x9NwrMqIm8aFAivVYQw=";
};
nativeBuildInputs = [ pkg-config makeWrapper ];
buildInputs = [
nativeBuildInputs = [
autoPatchelfHook
installShellFiles
makeWrapper
pkg-config
scons
udev
];
buildInputs = [
alsa-lib
freetype
libGLU
libpulseaudio
libX11
libXcursor
libXext
libXfixes
libXi
libXinerama
libXrandr
libXrender
libXi
libXext
libXfixes
freetype
openssl
alsa-lib
libpulseaudio
libGLU
zlib
udev
yasm
zlib
];
patches = [ ./pkg_config_additions.patch ./dont_clobber_environment.patch ];
shouldAddLinkFlagsToPulse = true;
patches = map (rp: ./patches + rp) [
# The version of SConstruct in the godot source appends the OS's PATH to the Scons PATH,
# but because it is an append, the Scons PATH takes precedence. The Scons PATH contains a
# bunch of standard Linux paths like /usr/bin, so if they happen to contain versions of any
# build-time dependencies of Godot, they will be used instead of the Nix version of them.
#
# This patch simply replaces the entire Scons environment (including the PATH) with that
# of the OS. This isn't as surgical as just fixing the PATH, but it seems to work, and
# seems to be the Nix community's current strategy when using Scons.
/SConstruct/dontClobberEnvironment.patch
];
enableParallelBuilding = true;
godotBuildPlatform = "x11";
shouldBuildTools = true;
godotBuildTarget = "release_debug";
sconsFlags = [ "target=release_debug" "platform=x11" ];
preConfigure = ''
sconsFlags+=" ${
lib.concatStringsSep " "
(lib.mapAttrsToList (k: v: "${k}=${builtins.toJSON v}") options)
}"
'';
shouldUseLinkTimeOptimization = self.godotBuildTarget == "release";
outputs = [ "out" "dev" "man" ];
sconsFlags = [
"arch=${stdenv.hostPlatform.linuxArch}"
"platform=${self.godotBuildPlatform}"
"tools=${lib.boolToString self.shouldBuildTools}"
"target=${self.godotBuildTarget}"
"bits=${toString stdenv.hostPlatform.parsed.cpu.bits}"
"use_lto=${lib.boolToString self.shouldUseLinkTimeOptimization}"
];
shouldWrapBinary = self.shouldBuildTools;
shouldInstallManual = self.shouldBuildTools;
shouldPatchBinary = self.shouldBuildTools;
shouldInstallHeaders = self.shouldBuildTools;
shouldInstallShortcut = self.shouldBuildTools && self.godotBuildPlatform != "server";
outputs = ["out"] ++ lib.optional self.shouldInstallManual "man" ++ lib.optional self.shouldBuildTools "dev";
builtGodotBinNamePattern = if self.godotBuildPlatform == "server" then "godot_server.*" else "godot.*";
godotBinInstallPath = "bin";
installedGodotBinName = self.pname;
installedGodotShortcutFileName = "org.godotengine.Godot3.desktop";
installedGodotShortcutDisplayName = "Godot Engine 3";
installPhase = ''
mkdir -p "$out/bin"
cp bin/godot.* $out/bin/godot3
runHook preInstall
wrapProgram "$out/bin/godot3" \
--set ALSA_PLUGIN_DIR ${alsa-plugins}/lib/alsa-lib
echo "Installing godot binaries."
outbin="$out/$godotBinInstallPath"
mkdir -p "$outbin"
cp -R bin/. "$outbin"
mv "$outbin"/$builtGodotBinNamePattern "$outbin/$installedGodotBinName"
mkdir "$dev"
cp -r modules/gdnative/include $dev
if [ -n "$shouldWrapBinary" ]; then
wrapProgram "$outbin/$installedGodotBinName" \
--set ALSA_PLUGIN_DIR ${alsa-plugins}/lib/alsa-lib
fi
mkdir -p "$man/share/man/man6"
cp misc/dist/linux/godot.6 "$man/share/man/man6/"
if [ -n "$shouldInstallManual" ]; then
echo "Installing godot manual."
mansrc=misc/dist/linux
mv "$mansrc"/godot.6 "$mansrc"/godot3.6
installManPage "$mansrc"/godot3.6
fi
mkdir -p "$out"/share/{applications,icons/hicolor/scalable/apps}
cp misc/dist/linux/org.godotengine.Godot.desktop "$out/share/applications/org.godotengine.Godot3.desktop"
cp icon.svg "$out/share/icons/hicolor/scalable/apps/godot.svg"
cp icon.png "$out/share/icons/godot.png"
substituteInPlace "$out/share/applications/org.godotengine.Godot3.desktop" \
--replace "Exec=godot" "Exec=$out/bin/godot3" \
--replace "Godot Engine" "Godot Engine 3"
if [ -n "$shouldInstallHeaders" ]; then
echo "Installing godot headers."
mkdir -p "$dev"
cp -R modules/gdnative/include "$dev"
fi
if [ -n "$shouldInstallShortcut" ]; then
echo "Installing godot shortcut."
mkdir -p "$out"/share/{applications,icons/hicolor/scalable/apps}
cp misc/dist/linux/org.godotengine.Godot.desktop "$out"/share/applications/$installedGodotShortcutFileName
cp icon.svg "$out"/share/icons/hicolor/scalable/apps/godot.svg
cp icon.png "$out"/share/icons/godot.png
substituteInPlace "$out"/share/applications/$installedGodotShortcutFileName \
--replace "Exec=godot" "Exec=\"$outbin/$installedGodotBinName\"" \
--replace "Name=Godot Engine" "Name=$installedGodotShortcutDisplayName"
fi
runHook postInstall
'';
runtimeDependencies = lib.optionals self.shouldPatchBinary (map lib.getLib [
alsa-lib
libpulseaudio
udev
]);
meta = with lib; {
homepage = "https://godotengine.org";
description = "Free and Open Source 2D and 3D game engine";
description = "Free and Open Source 2D and 3D game engine (" + self.godotBuildDescription + ")";
license = licenses.mit;
platforms = [ "i686-linux" "x86_64-linux" "aarch64-linux" ];
maintainers = with maintainers; [ twey ];
maintainers = with maintainers; [ rotaerk twey ];
};
}
})

View file

@ -1,25 +1,28 @@
{ godot, lib }:
{ godot3 }:
# https://docs.godotengine.org/en/stable/development/compiling/compiling_for_x11.html#building-export-templates
godot.overrideAttrs (oldAttrs: rec {
pname = "godot-export-templates";
sconsFlags = [ "target=release" "platform=x11" "tools=no" ];
installPhase = ''
# The godot export command expects the export templates at
# .../share/godot/templates/3.2.3.stable with 3.2.3 being the godot version.
mkdir -p "$out/share/godot/templates/${oldAttrs.version}.stable"
cp bin/godot.x11.opt.64 $out/share/godot/templates/${oldAttrs.version}.stable/linux_x11_64_release
'';
godot3.overrideAttrs (self: base: {
pname = "godot3-export-templates";
godotBuildDescription = "nix export templates";
# As described in default.nix, adding the link flags to pulseaudio in detect.py was necessary to
# allow the dlopen calls to succeed in Nix builds of godot. However, it seems that this *breaks*
# the export templates, resulting in programs exported from godot using these export templates to
# be unable to load this library.
shouldAddLinkFlagsToPulse = false;
shouldBuildTools = false;
godotBuildTarget = "release";
godotBinInstallPath = "share/godot/templates/${self.version}.stable";
installedGodotBinName = "linux_${self.godotBuildPlatform}_64_${self.godotBuildTarget}";
# https://docs.godotengine.org/en/stable/development/compiling/optimizing_for_size.html
# Stripping reduces the template size from around 500MB to 40MB for Linux.
# This also impacts the size of the exported games.
# This is added explicitly here because mkDerivation does not automatically
# strip binaries in the template directory.
stripAllList = (oldAttrs.stripAllList or []) ++ [ "share/godot/templates" ];
stripAllList = (base.stripAllList or []) ++ [ "share/godot/templates" ];
outputs = [ "out" ];
meta.description =
"Free and Open Source 2D and 3D game engine (export templates)";
meta.maintainers = with lib.maintainers; [ twey jojosch ];
meta = base.meta // {
homepage = "https://docs.godotengine.org/en/stable/development/compiling/compiling_for_x11.html#building-export-templates";
};
})

View file

@ -1,18 +1,7 @@
{ godot, lib }:
godot.overrideAttrs (oldAttrs: rec {
pname = "godot-headless";
sconsFlags = [ "target=release_debug" "platform=server" "tools=yes" ];
installPhase = ''
mkdir -p "$out/bin"
cp bin/godot_server.* $out/bin/godot-headless
{ godot3 }:
mkdir "$dev"
cp -r modules/gdnative/include $dev
mkdir -p "$man/share/man/man6"
cp misc/dist/linux/godot.6 "$man/share/man/man6/"
'';
meta.description =
"Free and Open Source 2D and 3D game engine (headless build)";
meta.maintainers = with lib.maintainers; [ twey yusdacra ];
godot3.overrideAttrs (self: base: {
pname = "godot3-headless";
godotBuildDescription = "headless";
godotBuildPlatform = "server";
})

View file

@ -1,8 +1,5 @@
scons does not use os environment by default:
https://scons.org/doc/2.1.0/HTML/scons-user/x1750.html
nixpkgs' cc-wrapper on the other hand relies on various NIX_* variables
to be passed through like NIX_CFLAGS_COMPILE_BEFORE.
diff --git a/SConstruct b/SConstruct
index 057ec7628c..760be89fff 100644
--- a/SConstruct
+++ b/SConstruct
@@ -67,14 +67,7 @@ elif platform_arg == "javascript":

View file

@ -1,33 +0,0 @@
diff --git a/platform/x11/detect.py b/platform/x11/detect.py
index 98c9ddb..0cc2bff 100644
--- a/platform/x11/detect.py
+++ b/platform/x11/detect.py
@@ -255,6 +255,10 @@ def configure(env):
env.ParseConfig("pkg-config xrender --cflags --libs")
env.ParseConfig("pkg-config xi --cflags --libs")
+ env.ParseConfig("pkg-config xfixes --cflags --libs")
+ env.ParseConfig("pkg-config glu --cflags --libs")
+ env.ParseConfig("pkg-config zlib --cflags --libs")
+
if env["touch"]:
env.Append(CPPDEFINES=["TOUCH_ENABLED"])
@@ -359,7 +363,7 @@ def configure(env):
if os.system("pkg-config --exists alsa") == 0: # 0 means found
env["alsa"] = True
env.Append(CPPDEFINES=["ALSA_ENABLED", "ALSAMIDI_ENABLED"])
- env.ParseConfig("pkg-config alsa --cflags") # Only cflags, we dlopen the library.
+ env.ParseConfig("pkg-config alsa --cflags --libs")
else:
print("Warning: ALSA libraries not found. Disabling the ALSA audio driver.")
@@ -375,7 +379,7 @@ def configure(env):
if env["udev"]:
if os.system("pkg-config --exists libudev") == 0: # 0 means found
env.Append(CPPDEFINES=["UDEV_ENABLED"])
- env.ParseConfig("pkg-config libudev --cflags") # Only cflags, we dlopen the library.
+ env.ParseConfig("pkg-config libudev --cflags --libs")
else:
print("Warning: libudev development libraries not found. Disabling controller hotplugging support.")
else:

View file

@ -1,18 +1,7 @@
{ godot, lib }:
godot.overrideAttrs (oldAttrs: rec {
pname = "godot-server";
sconsFlags = [ "target=release" "platform=server" "tools=no" ];
installPhase = ''
mkdir -p "$out/bin"
cp bin/godot_server.* $out/bin/godot-server
{ godot3-debug-server }:
mkdir "$dev"
cp -r modules/gdnative/include $dev
mkdir -p "$man/share/man/man6"
cp misc/dist/linux/godot.6 "$man/share/man/man6/"
'';
meta.description =
"Free and Open Source 2D and 3D game engine (server build)";
meta.maintainers = with lib.maintainers; [ twey yusdacra ];
godot3-debug-server.overrideAttrs (self: base: {
pname = "godot3-server";
godotBuildDescription = "server";
godotBuildTarget = "release";
})

View file

@ -1,4 +1,5 @@
{ lib
, autoPatchelfHook
, copyDesktopItems
, fetchFromGitHub
, makeDesktopItem
@ -6,8 +7,8 @@
, alsa-lib
, gcc-unwrapped
, git
, godot-export-templates
, godot-headless
, godot3-export-templates
, godot3-headless
, libGLU
, libX11
, libXcursor
@ -36,8 +37,9 @@ stdenv.mkDerivation rec {
};
nativeBuildInputs = [
autoPatchelfHook
copyDesktopItems
godot-headless
godot3-headless
];
buildInputs = [
@ -89,10 +91,10 @@ stdenv.mkDerivation rec {
# expects the template-file at .../templates/3.2.3.stable/linux_x11_64_release
# with 3.2.3 being the version of godot.
mkdir -p $HOME/.local/share/godot
ln -s ${godot-export-templates}/share/godot/templates $HOME/.local/share/godot
ln -s ${godot3-export-templates}/share/godot/templates $HOME/.local/share/godot
mkdir -p $out/share/oh-my-git
godot-headless --export "Linux" $out/share/oh-my-git/oh-my-git
godot3-headless --export "Linux" $out/share/oh-my-git/oh-my-git
runHook postBuild
'';
@ -116,6 +118,12 @@ stdenv.mkDerivation rec {
runHook postInstall
'';
runtimeDependencies = map lib.getLib [
alsa-lib
libpulseaudio
udev
];
meta = with lib; {
homepage = "https://ohmygit.org/";
description = "An interactive Git learning game";

View file

@ -627,6 +627,13 @@ mapAliases ({
gnuvd = throw "gnuvd was removed because the backend service is missing"; # Added 2020-01-14
gobby5 = gobby; # Added 2021-02-01
gobjectIntrospection = throw "'gobjectIntrospection' has been renamed to/replaced by 'gobject-introspection'"; # Converted to throw 2022-02-22
#godot
godot = throw "godot has been renamed to godot3 to distinguish from version 4"; # Added 2023-07-16
godot-export-templates = throw "godot-export-templates has been renamed to godot3-export-templates to distinguish from version 4"; # Added 2023-07-16
godot-headless = throw "godot-headless has been renamed to godot3-headless to distinguish from version 4"; # Added 2023-07-16
godot-server = throw "godot-server has been renamed to godot3-server to distinguish from version 4"; # Added 2023-07-16
gogoclient = throw "gogoclient has been removed, because it was unmaintained"; # Added 2021-12-15
goklp = throw "goklp has been dropped due to the lack of maintenance from upstream since 2017"; # Added 2022-06-02
golly-beta = throw "golly-beta has been removed: use golly instead"; # Added 2022-03-21

View file

@ -8226,13 +8226,15 @@ with pkgs;
godot_4 = callPackage ../development/tools/godot/4 { };
godot = callPackage ../development/tools/godot/3 { };
godot3 = callPackage ../development/tools/godot/3 { };
godot-export-templates = callPackage ../development/tools/godot/3/export-templates.nix { };
godot3-export-templates = callPackage ../development/tools/godot/3/export-templates.nix { };
godot-headless = callPackage ../development/tools/godot/3/headless.nix { };
godot3-headless = callPackage ../development/tools/godot/3/headless.nix { };
godot-server = callPackage ../development/tools/godot/3/server.nix { };
godot3-debug-server = callPackage ../development/tools/godot/3/debug-server.nix { };
godot3-server = callPackage ../development/tools/godot/3/server.nix { };
goeland = callPackage ../applications/networking/feedreaders/goeland { };