diff --git a/.envrc b/.envrc new file mode 100644 index 00000000000..3550a30f2de --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/README.md b/README.md index 4ea568e280d..af45646f250 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,32 @@ Official binaries for the Redot editor and the export templates will be found ### Compiling from source -[For the time being, see the official Godot docs](https://docs.godotengine.org/en/latest/contributing/development/compiling) -for compilation instructions for every supported platform. +#### Using Nix (recommended) + +If you have the Nix package manager installed, you can build and run the editor in one command: + +```bash +nix run . +``` + +This will automatically install all build dependencies and compile Redot if the binary doesn't exist. + +For manual control over the build process: + +```bash +# Enter the Nix development environment +nix develop + +# Build Redot (use 'macos' on macOS, 'linuxbsd' on Linux) +scons platform=linuxbsd # or: scons platform=macos + +# Run the editor - binary name reflects your platform and architecture +# Examples: redot.linuxbsd.editor.x86_64, redot.macos.editor.arm64 +./bin/redot..editor. +``` + +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. + ## Community and contributing diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..644277dbb3f --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1767364772, + "narHash": "sha256-fFUnEYMla8b7UKjijLnMe+oVFOz6HjijGGNS1l7dYaQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "16c7794d0a28b5a37904d55bcca36003b9109aaa", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000000..79456bcba3e --- /dev/null +++ b/flake.nix @@ -0,0 +1,112 @@ +{ + description = "A Nix-flake-based C/C++ development environment"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + outputs = { + self, + nixpkgs, + }: let + supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; + forEachSupportedSystem = f: + nixpkgs.lib.genAttrs supportedSystems (system: + f rec { + pkgs = import nixpkgs {inherit system;}; + isDarwin = pkgs.lib.hasSuffix system "darwin"; + arch = if pkgs.stdenv.hostPlatform.isAarch64 then "arm64" else "x86_64"; + + linuxDeps = with pkgs; [ + autoPatchelfHook + xorg.libX11 + xorg.libXcursor + xorg.libXinerama + xorg.libXext + xorg.libXrandr + xorg.libXrender + xorg.libXi + xorg.libXfixes + libxkbcommon + wayland-scanner + wayland + libdecor + alsa-lib + libpulseaudio + udev + dbus + dbus.lib + ]; + + darwinDeps = with pkgs; [ + Foundation + Cocoa + AudioToolbox + CoreAudio + CoreVideo + AVFoundation + ]; + + commonDeps = with pkgs; [ + pkg-config + installShellFiles + python3 + speechd + makeWrapper + mono + dotnet-sdk_8 + dotnet-runtime_8 + vulkan-loader + libGL + fontconfig + fontconfig.lib + scons + ]; + + deps = if isDarwin then darwinDeps ++ commonDeps else linuxDeps ++ commonDeps; + libraryPathVar = if isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH"; + platform = if isDarwin then "macos" else "linuxbsd"; + binary = if isDarwin then "redot.macos.editor.${arch}" else "redot.linuxbsd.editor.${arch}"; + }); + in { + apps = forEachSupportedSystem ({ + pkgs, + deps, + libraryPathVar, + platform, + binary, + arch, + ... + }: let + script = pkgs.writeShellScript "redot" '' + export ${libraryPathVar}=${pkgs.lib.makeLibraryPath deps} + if [ ! -f ./bin/${binary} ]; then + echo "Building Redot..." + scons platform=${platform} + fi + exec ./bin/${binary} "$@" + ''; + in { + default = { + type = "app"; + program = "${script}"; + }; + }); + + devShells = forEachSupportedSystem ({ + pkgs, + deps, + libraryPathVar, + ... + }: { + default = + pkgs.mkShell.override + { + # Override stdenv in order to change compiler: + # stdenv = pkgs.clangStdenv; + } + { + packages = deps; + ${libraryPathVar} = pkgs.lib.makeLibraryPath deps; + }; + }); + }; +}