From b94dd6b1be698305f988e2d9630218511d5a340e Mon Sep 17 00:00:00 2001 From: Theo Paris Date: Sun, 6 Oct 2024 19:38:41 -0700 Subject: [PATCH 1/6] Add nix flake --- flake.lock | 41 +++++++++++++++++++++ flake.nix | 90 +++++++++++++++++++++++++++++++++++++++++++++ package.nix | 90 +++++++++++++++++++++++++++++++++++++++++++++ platform_methods.py | 4 ++ 4 files changed, 225 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 package.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..f65e248060c --- /dev/null +++ b/flake.lock @@ -0,0 +1,41 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1728018373, + "narHash": "sha256-NOiTvBbRLIOe5F6RbHaAh6++BNjsb149fGZd1T4+KBg=", + "rev": "bc947f541ae55e999ffdb4013441347d83b00feb", + "revCount": 688563, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.688563%2Brev-bc947f541ae55e999ffdb4013441347d83b00feb/01925b66-3b70-71bd-b277-924a6c208ba7/source.tar.gz?rev=bc947f541ae55e999ffdb4013441347d83b00feb&revCount=688563" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.%2A.tar.gz" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000000..bc14f77dfc0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,90 @@ +{ + description = "A Nix-flake-based C/C++ development environment"; + + inputs = { + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz"; + systems.url = "github:nix-systems/default"; + }; + + outputs = + { + self, + nixpkgs, + systems, + }: + let + forEachSupportedSystem = + f: + nixpkgs.lib.genAttrs (import systems) ( + system: + f { + pkgs = import nixpkgs { inherit system; }; + } + ); + in + { + packages = forEachSupportedSystem ( + { + pkgs, + }: + { + default = + pkgs.callPackage ./package.nix + { + }; + } + ); + devShells = forEachSupportedSystem ( + { + pkgs, + }: + { + default = + pkgs.mkShell.override + { + # Override stdenv in order to change compiler: + # stdenv = pkgs.clangStdenv; + } + rec { + packages = + with pkgs; + [ + pkgconf + autoPatchelfHook + installShellFiles + python3 + makeWrapper + dotnet-sdk_8 + dotnet-runtime_8 + vulkan-loader + vulkan-headers + fontconfig + fontconfig.lib + scons + ] + ++ pkgs.lib.optionals pkgs.stdenv.targetPlatform.isLinux [ + speechd + alsa-lib + xorg.libX11 + xorg.libXcursor + xorg.libXinerama + xorg.libXext + xorg.libXrandr + xorg.libXrender + xorg.libXi + xorg.libXfixes + libxkbcommon + dbus + dbus.lib + udev + wayland-scanner + wayland + libdecor + libpulseaudio + ]; + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath packages; + }; + } + ); + }; +} diff --git a/package.nix b/package.nix new file mode 100644 index 00000000000..222406dad10 --- /dev/null +++ b/package.nix @@ -0,0 +1,90 @@ +{ + stdenv, + lib, + enableWayland ? stdenv.targetPlatform.isLinux, + enablePulseAudio ? stdenv.targetPlatform.isLinux, + enableX11 ? stdenv.targetPlatform.isLinux, + enableAlsa ? stdenv.targetPlatform.isLinux, + enableSpeechd ? stdenv.targetPlatform.isLinux, + enableVulkan ? true, + pkgconf, + autoPatchelfHook, + installShellFiles, + python3, + scons, + makeWrapper, + vulkan-loader, + vulkan-headers, + speechd, + fontconfig, + wayland, + wayland-scanner, + wayland-protocols, + libdecor, + libxkbcommon, + libpulseaudio, + xorg, + udev, + alsa-lib, + dbus, + xcbuild, + darwin, +}: + +stdenv.mkDerivation { + name = "redot-engine"; + src = ./.; + + buildInputs = + [ + pkgconf + autoPatchelfHook + installShellFiles + python3 + makeWrapper + scons + fontconfig + ] + ++ lib.optionals enableSpeechd [ speechd ] + ++ lib.optionals enableVulkan [ + vulkan-loader + vulkan-headers + ] + ++ lib.optionals enableWayland [ + wayland + wayland-scanner + wayland-protocols + libdecor + libxkbcommon + ] + ++ lib.optionals enablePulseAudio [ libpulseaudio ] + ++ lib.optionals enableX11 [ + xorg.libX11 + xorg.libXcursor + xorg.libXinerama + xorg.libXext + xorg.libXrandr + xorg.libXrender + xorg.libXi + xorg.libXfixes + ] + ++ lib.optionals enableAlsa [ alsa-lib ] + ++ lib.optionals stdenv.targetPlatform.isLinux [ + udev + dbus + ] + ++ lib.optionals stdenv.targetPlatform.isDarwin [ + xcbuild + darwin.moltenvk + ] + ++ lib.optionals stdenv.targetPlatform.isDarwin ( + with darwin.apple_sdk.frameworks; + [ + AppKit + ] + ); + + sconsFlags = lib.optionals stdenv.targetPlatform.isDarwin [ + "vulkan_sdk_path=${darwin.moltenvk}" + ]; +} diff --git a/platform_methods.py b/platform_methods.py index c8646a40226..18b77fa0fcf 100644 --- a/platform_methods.py +++ b/platform_methods.py @@ -155,8 +155,12 @@ def detect_mvk(env, osname): ) for mvk_path in mvk_list: + # FIXME: Iterate over all files in the sdk path if mvk_path and os.path.isfile(os.path.join(mvk_path, f"{osname}/libMoltenVK.a")): print(f"MoltenVK found at: {mvk_path}") return mvk_path + elif mvk_path and os.path.isfile(os.path.join(mvk_path, f"lib/libMoltenVK.dylib")): + print(f"MoltenVK found at: {mvk_path}") + return mvk_path return "" From 36d7f0d3db015b0c93dc0e0c8ca03b740ef5bdc4 Mon Sep 17 00:00:00 2001 From: Theo Paris Date: Sun, 6 Oct 2024 23:02:41 -0700 Subject: [PATCH 2/6] Use pkg-config See https://github.com/NixOS/nixpkgs/issues/334195 --- flake.nix | 2 +- package.nix | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index bc14f77dfc0..9b21c270999 100644 --- a/flake.nix +++ b/flake.nix @@ -49,7 +49,7 @@ packages = with pkgs; [ - pkgconf + pkg-config autoPatchelfHook installShellFiles python3 diff --git a/package.nix b/package.nix index 222406dad10..2eb86b0d020 100644 --- a/package.nix +++ b/package.nix @@ -7,7 +7,7 @@ enableAlsa ? stdenv.targetPlatform.isLinux, enableSpeechd ? stdenv.targetPlatform.isLinux, enableVulkan ? true, - pkgconf, + pkg-config, autoPatchelfHook, installShellFiles, python3, @@ -35,14 +35,17 @@ stdenv.mkDerivation { name = "redot-engine"; src = ./.; + nativeBuildInputs = [ + pkg-config + autoPatchelfHook + installShellFiles + makeWrapper + python3 + scons + ]; + buildInputs = [ - pkgconf - autoPatchelfHook - installShellFiles - python3 - makeWrapper - scons fontconfig ] ++ lib.optionals enableSpeechd [ speechd ] From afd3b8c97af682c8ce57dfad6ac0d40ed3ec5d84 Mon Sep 17 00:00:00 2001 From: Theo Paris Date: Mon, 7 Oct 2024 00:15:16 -0700 Subject: [PATCH 3/6] Add install phase --- package.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/package.nix b/package.nix index 2eb86b0d020..85b5dc6adaa 100644 --- a/package.nix +++ b/package.nix @@ -90,4 +90,12 @@ stdenv.mkDerivation { sconsFlags = lib.optionals stdenv.targetPlatform.isDarwin [ "vulkan_sdk_path=${darwin.moltenvk}" ]; + + installPhase = '' + runHook preInstall + mkdir -p "$out/bin" + cp bin/godot.* $out/bin/redot + + runHook postInstall + ''; } From ef117a06adb5e85ac537777064c7997871aa221b Mon Sep 17 00:00:00 2001 From: Theo Paris Date: Wed, 4 Dec 2024 22:51:18 -0800 Subject: [PATCH 4/6] Update binary naming Update the copy command in package.nix to match the output binary names. --- flake.nix | 6 ++---- package.nix | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index 9b21c270999..69801ab216d 100644 --- a/flake.nix +++ b/flake.nix @@ -28,10 +28,8 @@ pkgs, }: { - default = - pkgs.callPackage ./package.nix - { - }; + default = pkgs.callPackage ./package.nix { + }; } ); devShells = forEachSupportedSystem ( diff --git a/package.nix b/package.nix index 85b5dc6adaa..c32451ee761 100644 --- a/package.nix +++ b/package.nix @@ -94,7 +94,7 @@ stdenv.mkDerivation { installPhase = '' runHook preInstall mkdir -p "$out/bin" - cp bin/godot.* $out/bin/redot + cp bin/redot*.* $out/bin/redot runHook postInstall ''; From 1d25cf1c37a992a91cab8e23dec68f88d2b3d543 Mon Sep 17 00:00:00 2001 From: Theo Paris Date: Wed, 8 Jan 2025 18:43:55 -0800 Subject: [PATCH 5/6] Update flake.lock --- flake.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index f65e248060c..7665757eda6 100644 --- a/flake.lock +++ b/flake.lock @@ -2,12 +2,12 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1728018373, - "narHash": "sha256-NOiTvBbRLIOe5F6RbHaAh6++BNjsb149fGZd1T4+KBg=", - "rev": "bc947f541ae55e999ffdb4013441347d83b00feb", - "revCount": 688563, + "lastModified": 1736012469, + "narHash": "sha256-/qlNWm/IEVVH7GfgAIyP6EsVZI6zjAx1cV5zNyrs+rI=", + "rev": "8f3e1f807051e32d8c95cd12b9b421623850a34d", + "revCount": 733374, "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.688563%2Brev-bc947f541ae55e999ffdb4013441347d83b00feb/01925b66-3b70-71bd-b277-924a6c208ba7/source.tar.gz?rev=bc947f541ae55e999ffdb4013441347d83b00feb&revCount=688563" + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.733374%2Brev-8f3e1f807051e32d8c95cd12b9b421623850a34d/01943a5d-98a8-75c0-9963-3a93900583fd/source.tar.gz" }, "original": { "type": "tarball", From c9f645dd05635ee8d33d9f39fc3daba8bcb5cbc3 Mon Sep 17 00:00:00 2001 From: Theo Paris Date: Wed, 8 Jan 2025 18:53:18 -0800 Subject: [PATCH 6/6] Update nix flake - Added a mono build option with dotnet 9 - Added OpenGL and fixed runtime dependencies - Migrated to nixpkgs master --- .gitignore | 3 ++ flake.lock | 18 ++++++------ flake.nix | 6 ++-- package.nix | 79 +++++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 78 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 22a1d53a879..8b1184a6c1a 100644 --- a/.gitignore +++ b/.gitignore @@ -380,3 +380,6 @@ $RECYCLE.BIN/ *.msp *.lnk *.generated.props + +# Nix +result diff --git a/flake.lock b/flake.lock index 7665757eda6..af9fb58832a 100644 --- a/flake.lock +++ b/flake.lock @@ -2,16 +2,18 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1736012469, - "narHash": "sha256-/qlNWm/IEVVH7GfgAIyP6EsVZI6zjAx1cV5zNyrs+rI=", - "rev": "8f3e1f807051e32d8c95cd12b9b421623850a34d", - "revCount": 733374, - "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.733374%2Brev-8f3e1f807051e32d8c95cd12b9b421623850a34d/01943a5d-98a8-75c0-9963-3a93900583fd/source.tar.gz" + "lastModified": 1736390910, + "narHash": "sha256-MmOb9KKtflYASR0NsEJxyWAQy8tLUzQKypMZ/D5pMfg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "52d9f693941a15687549d05215450cefa4fc3a03", + "type": "github" }, "original": { - "type": "tarball", - "url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.%2A.tar.gz" + "owner": "nixos", + "ref": "master", + "repo": "nixpkgs", + "type": "github" } }, "root": { diff --git a/flake.nix b/flake.nix index 69801ab216d..2599575e2d0 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "A Nix-flake-based C/C++ development environment"; inputs = { - nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz"; + nixpkgs.url = "github:nixos/nixpkgs/master"; systems.url = "github:nix-systems/default"; }; @@ -52,8 +52,8 @@ installShellFiles python3 makeWrapper - dotnet-sdk_8 - dotnet-runtime_8 + dotnet-sdk_9 + dotnet-runtime_9 vulkan-loader vulkan-headers fontconfig diff --git a/package.nix b/package.nix index c32451ee761..9cdb7c53b8c 100644 --- a/package.nix +++ b/package.nix @@ -1,11 +1,12 @@ { stdenv, lib, - enableWayland ? stdenv.targetPlatform.isLinux, - enablePulseAudio ? stdenv.targetPlatform.isLinux, - enableX11 ? stdenv.targetPlatform.isLinux, - enableAlsa ? stdenv.targetPlatform.isLinux, - enableSpeechd ? stdenv.targetPlatform.isLinux, + enableWayland ? stdenv.hostPlatform.isLinux, + enablePulseAudio ? stdenv.hostPlatform.isLinux, + enableX11 ? stdenv.hostPlatform.isLinux, + enableAlsa ? stdenv.hostPlatform.isLinux, + enableSpeechd ? stdenv.hostPlatform.isLinux, + enableMono ? false, enableVulkan ? true, pkg-config, autoPatchelfHook, @@ -13,6 +14,7 @@ python3, scons, makeWrapper, + libGL, vulkan-loader, vulkan-headers, speechd, @@ -24,29 +26,39 @@ libxkbcommon, libpulseaudio, xorg, - udev, + eudev, alsa-lib, dbus, xcbuild, darwin, + dotnet-sdk_9, + dotnet-runtime_9, }: stdenv.mkDerivation { name = "redot-engine"; src = ./.; - nativeBuildInputs = [ - pkg-config - autoPatchelfHook - installShellFiles - makeWrapper - python3 - scons - ]; + nativeBuildInputs = + [ + pkg-config + autoPatchelfHook + installShellFiles + makeWrapper + python3 + scons + ] + ++ lib.optionals enableMono [ + dotnet-sdk_9 + ] + ++ lib.optionals enableWayland [ + wayland-scanner + ]; buildInputs = [ fontconfig + libGL ] ++ lib.optionals enableSpeechd [ speechd ] ++ lib.optionals enableVulkan [ @@ -55,7 +67,6 @@ stdenv.mkDerivation { ] ++ lib.optionals enableWayland [ wayland - wayland-scanner wayland-protocols libdecor libxkbcommon @@ -73,7 +84,7 @@ stdenv.mkDerivation { ] ++ lib.optionals enableAlsa [ alsa-lib ] ++ lib.optionals stdenv.targetPlatform.isLinux [ - udev + eudev dbus ] ++ lib.optionals stdenv.targetPlatform.isDarwin [ @@ -85,7 +96,41 @@ stdenv.mkDerivation { [ AppKit ] - ); + ) + ++ lib.optionals enableMono [ + dotnet-runtime_9 + ]; + + runtimeDependencies = + [ + fontconfig.lib + libGL + ] + ++ lib.optionals stdenv.targetPlatform.isLinux [ + eudev + dbus + ] + ++ lib.optionals enableSpeechd [ speechd ] + ++ lib.optionals enableVulkan [ + vulkan-loader + ] + ++ lib.optionals enableWayland [ + wayland + libdecor + libxkbcommon + ] + ++ lib.optionals enablePulseAudio [ libpulseaudio ] + ++ lib.optionals enableX11 [ + xorg.libX11 + xorg.libXcursor + xorg.libXinerama + xorg.libXext + xorg.libXrandr + xorg.libXrender + xorg.libXi + xorg.libXfixes + ] + ++ lib.optionals enableAlsa [ alsa-lib ]; sconsFlags = lib.optionals stdenv.targetPlatform.isDarwin [ "vulkan_sdk_path=${darwin.moltenvk}"