Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,8 @@ $RECYCLE.BIN/
*.msp
*.lnk
*.generated.props

# Nix
.direnv/
/result
/result-*
3 changes: 3 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ opts.Add("rcflags", "Custom flags for Windows resource compiler")
opts.Add("c_compiler_launcher", "C compiler launcher (e.g. `ccache`)")
opts.Add("cpp_compiler_launcher", "C++ compiler launcher (e.g. `ccache`)")

# Nix
opts.Add(BoolVariable("nix", "Whether the project is built using Nix.", False))

# Update the environment to have all above options defined
# in following code (especially platform and custom_modules).
opts.Update(env)
Expand Down
116 changes: 116 additions & 0 deletions export-template-package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
pkgsCross,
symlinkJoin,
lib,
redot,
}:
{
templateType ? "release",
platform ? "linuxbsd",
}:
let
exportPlatformNames = {
linuxbsd = "linux";
windows = "windows";
};

mkTemplate =
{
pkg,
templateType ? "release",
platform ? "linuxbsd",
arch ? "x86_64",
}:
let
basePkg =
(pkg.override {
withTarget = "template_${templateType}";
withPlatform = platform;
}).overrideAttrs
(old: {
pname = "redot4-export-templates-${platform}-${templateType}";

outputs = [ "out" ];

installPhase = ''
runHook preInstall

mkdir -p "$out/share/redot/export_templates/${old.redotVersion}"

cp bin/redot.* "$out/share/redot/export_templates/${old.redotVersion}/${
exportPlatformNames.${platform}
}_${templateType}_${arch}"

runHook postInstall
'';
});
in
(
if platform == "windows" then
mkWindowsTemplate {
inherit templateType;
pkg = basePkg;
}
else
basePkg
);

mkWindowsTemplate =
{
pkg,
templateType ? "release",
}:
let
arch = "x86_64";
in
(pkg.override {
withPlatform = "windows";
inherit arch;
importEnvVars = [
"CPLUS_INCLUDE_PATH"
];
}).overrideAttrs
(
old:
let
buildInputs = (old.buildInputs or [ ]) ++ [
pkgsCross.mingwW64.windows.mingw_w64_pthreads
pkgsCross.mingwW64.windows.mcfgthreads
pkgsCross.mingw32.windows.mcfgthreads
];

libs = symlinkJoin {
name = "redot-export-templates-windows-libpath";
paths = buildInputs;
};
in
{
nativeBuildInputs = old.nativeBuildInputs ++ [
pkgsCross.mingwW64.buildPackages.gcc
pkgsCross.mingw32.buildPackages.gcc
];

inherit buildInputs;

env = (old.env or { }) // {
CPLUS_INCLUDE_PATH = lib.makeIncludePath buildInputs;
NIX_LIBS = "${libs}/lib";
};

installPhase = ''
runHook preInstall

mkdir -p "$out/share/redot/export_templates/${old.redotVersion}"

cp bin/redot.*.console.exe "$out/share/redot/export_templates/${old.redotVersion}/windows_${templateType}_${arch}_console.exe"
cp bin/redot.*.${arch}.exe "$out/share/redot/export_templates/${old.redotVersion}/windows_${templateType}_${arch}.exe"

runHook postInstall
'';
}
);
in
mkTemplate {
inherit platform templateType;
pkg = redot;
}
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 113 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
description = "Redot Game Engine";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};

outputs =
{
self,
nixpkgs,
}:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];

forEachSupportedSystem =
f:
nixpkgs.lib.genAttrs supportedSystems (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlays.default
];
};
in
f {
inherit pkgs system;
}
);
in
{
packages = forEachSupportedSystem (
{
pkgs,
system,
...
}:
{
default = self.packages.${system}.redot;

inherit (pkgs)
redot
redot-export-templates
redot-export-templates-linux-debug
redot-export-templates-linux-release
redot-export-templates-windows-debug
redot-export-templates-windows-release
;
}
);

overlays.default = final: prev: {
mkExportTemplate = final.callPackage (import ./export-template-package.nix) { };

redot = final.callPackage (import ./package.nix) {
src = self;
commitHash = if self ? rev then self.rev else "devel";
};

redot-export-templates-linux-release = final.mkExportTemplate {
templateType = "release";
platform = "linuxbsd";
};

redot-export-templates-linux-debug = final.mkExportTemplate {
templateType = "debug";
platform = "linuxbsd";
};

redot-export-templates-windows-release = final.mkExportTemplate {
templateType = "release";
platform = "windows";
};

redot-export-templates-windows-debug = final.mkExportTemplate {
templateType = "debug";
platform = "windows";
};

redot-export-templates = final.symlinkJoin {
name = "redot-export-templates";
paths = builtins.attrValues {
inherit (final)
redot-export-templates-linux-debug
redot-export-templates-linux-release
redot-export-templates-windows-debug
redot-export-templates-windows-release
;
};
};
};

devShells = forEachSupportedSystem (
{ pkgs, system, ... }:
{
default = pkgs.mkShell {
inputsFrom = [
self.packages.${system}.redot
];

packages = self.packages.${system}.redot.runtimeDependencies;
};
}
);
};
}
Loading