Skip to content

Commit fe0c89b

Browse files
MichaelFisher1997MichaelFisher1997
andauthored
Added a Nix flake containing everything needed to build, dev, and run redot (#154)
* Added a Nix flake containing everything needed to build, dev and run redot * Trigger Build * Update nixpkgs URL to GitHub and remove duplicate dependencies * Add app to build and run Redot in one command * Fix app program path reference * Add Nix build instructions to README * Remove outdated other platforms compilation link * Add proper macOS/Darwin support with platform-specific dependencies * Fix architecture detection for ARM64 systems in Nix flake - Add dynamic arch detection using pkgs.stdenv.hostPlatform.isAarch64 - Update binary naming to use detected architecture instead of hardcoded x86_64 - Update README manual instructions to show platform/arch-agnostic guidance This fixes nix run . on ARM64 systems (Apple Silicon, ARM Linux). --------- Co-authored-by: MichaelFisher1997 <contact@micahelfisher.tech>
1 parent 1ac5678 commit fe0c89b

4 files changed

Lines changed: 166 additions & 2 deletions

File tree

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,32 @@ Official binaries for the Redot editor and the export templates will be found
4848

4949
### Compiling from source
5050

51-
[For the time being, see the official Godot docs](https://docs.godotengine.org/en/latest/contributing/development/compiling)
52-
for compilation instructions for every supported platform.
51+
#### Using Nix (recommended)
52+
53+
If you have the Nix package manager installed, you can build and run the editor in one command:
54+
55+
```bash
56+
nix run .
57+
```
58+
59+
This will automatically install all build dependencies and compile Redot if the binary doesn't exist.
60+
61+
For manual control over the build process:
62+
63+
```bash
64+
# Enter the Nix development environment
65+
nix develop
66+
67+
# Build Redot (use 'macos' on macOS, 'linuxbsd' on Linux)
68+
scons platform=linuxbsd # or: scons platform=macos
69+
70+
# Run the editor - binary name reflects your platform and architecture
71+
# Examples: redot.linuxbsd.editor.x86_64, redot.macos.editor.arm64
72+
./bin/redot.<platform>.editor.<arch>
73+
```
74+
75+
Nix works on Linux and macOS, and is available at [nixos.org/download.html](https://nixos.org/download.html). The `nix run .` command automatically detects your platform and architecture.
76+
5377

5478
## Community and contributing
5579

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
description = "A Nix-flake-based C/C++ development environment";
3+
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5+
6+
outputs = {
7+
self,
8+
nixpkgs,
9+
}: let
10+
supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
11+
forEachSupportedSystem = f:
12+
nixpkgs.lib.genAttrs supportedSystems (system:
13+
f rec {
14+
pkgs = import nixpkgs {inherit system;};
15+
isDarwin = pkgs.lib.hasSuffix system "darwin";
16+
arch = if pkgs.stdenv.hostPlatform.isAarch64 then "arm64" else "x86_64";
17+
18+
linuxDeps = with pkgs; [
19+
autoPatchelfHook
20+
xorg.libX11
21+
xorg.libXcursor
22+
xorg.libXinerama
23+
xorg.libXext
24+
xorg.libXrandr
25+
xorg.libXrender
26+
xorg.libXi
27+
xorg.libXfixes
28+
libxkbcommon
29+
wayland-scanner
30+
wayland
31+
libdecor
32+
alsa-lib
33+
libpulseaudio
34+
udev
35+
dbus
36+
dbus.lib
37+
];
38+
39+
darwinDeps = with pkgs; [
40+
Foundation
41+
Cocoa
42+
AudioToolbox
43+
CoreAudio
44+
CoreVideo
45+
AVFoundation
46+
];
47+
48+
commonDeps = with pkgs; [
49+
pkg-config
50+
installShellFiles
51+
python3
52+
speechd
53+
makeWrapper
54+
mono
55+
dotnet-sdk_8
56+
dotnet-runtime_8
57+
vulkan-loader
58+
libGL
59+
fontconfig
60+
fontconfig.lib
61+
scons
62+
];
63+
64+
deps = if isDarwin then darwinDeps ++ commonDeps else linuxDeps ++ commonDeps;
65+
libraryPathVar = if isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH";
66+
platform = if isDarwin then "macos" else "linuxbsd";
67+
binary = if isDarwin then "redot.macos.editor.${arch}" else "redot.linuxbsd.editor.${arch}";
68+
});
69+
in {
70+
apps = forEachSupportedSystem ({
71+
pkgs,
72+
deps,
73+
libraryPathVar,
74+
platform,
75+
binary,
76+
arch,
77+
...
78+
}: let
79+
script = pkgs.writeShellScript "redot" ''
80+
export ${libraryPathVar}=${pkgs.lib.makeLibraryPath deps}
81+
if [ ! -f ./bin/${binary} ]; then
82+
echo "Building Redot..."
83+
scons platform=${platform}
84+
fi
85+
exec ./bin/${binary} "$@"
86+
'';
87+
in {
88+
default = {
89+
type = "app";
90+
program = "${script}";
91+
};
92+
});
93+
94+
devShells = forEachSupportedSystem ({
95+
pkgs,
96+
deps,
97+
libraryPathVar,
98+
...
99+
}: {
100+
default =
101+
pkgs.mkShell.override
102+
{
103+
# Override stdenv in order to change compiler:
104+
# stdenv = pkgs.clangStdenv;
105+
}
106+
{
107+
packages = deps;
108+
${libraryPathVar} = pkgs.lib.makeLibraryPath deps;
109+
};
110+
});
111+
};
112+
}

0 commit comments

Comments
 (0)