Skip to content

Commit 5e9840d

Browse files
committed
add nix flake + package definitions for editor & export templates
1 parent c52e3cf commit 5e9840d

8 files changed

Lines changed: 508 additions & 0 deletions

File tree

.envrc

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

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,8 @@ $RECYCLE.BIN/
386386
*.msp
387387
*.lnk
388388
*.generated.props
389+
390+
# Nix
391+
.direnv/
392+
/result
393+
/result-*

SConstruct

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ opts.Add("rcflags", "Custom flags for Windows resource compiler")
299299
opts.Add("c_compiler_launcher", "C compiler launcher (e.g. `ccache`)")
300300
opts.Add("cpp_compiler_launcher", "C++ compiler launcher (e.g. `ccache`)")
301301

302+
# Nix
303+
opts.Add(BoolVariable("nix", "Whether the project is built using Nix.", False))
304+
302305
# Update the environment to have all above options defined
303306
# in following code (especially platform and custom_modules).
304307
opts.Update(env)

export-template-package.nix

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
3+
pkgsCross,
4+
symlinkJoin,
5+
lib,
6+
redot,
7+
}:
8+
{
9+
templateType ? "release",
10+
platform ? "linuxbsd",
11+
}:
12+
let
13+
exportPlatformNames = {
14+
linuxbsd = "linux";
15+
windows = "windows";
16+
};
17+
18+
mkTemplate =
19+
{
20+
pkg,
21+
templateType ? "release",
22+
platform ? "linuxbsd",
23+
arch ? "x86_64",
24+
}:
25+
let
26+
basePkg =
27+
(pkg.override {
28+
withTarget = "template_${templateType}";
29+
withPlatform = platform;
30+
}).overrideAttrs
31+
(old: {
32+
pname = "redot4-export-templates-${platform}-${templateType}";
33+
34+
outputs = [ "out" ];
35+
36+
installPhase = ''
37+
runHook preInstall
38+
39+
mkdir -p "$out/share/redot/export_templates/${old.redotVersion}"
40+
41+
cp bin/redot.* "$out/share/redot/export_templates/${old.redotVersion}/${
42+
exportPlatformNames.${platform}
43+
}_${templateType}_${arch}"
44+
45+
runHook postInstall
46+
'';
47+
});
48+
in
49+
(
50+
if platform == "windows" then
51+
mkWindowsTemplate {
52+
inherit templateType;
53+
pkg = basePkg;
54+
}
55+
else
56+
basePkg
57+
);
58+
59+
mkWindowsTemplate =
60+
{
61+
pkg,
62+
templateType ? "release",
63+
}:
64+
let
65+
arch = "x86_64";
66+
in
67+
(pkg.override {
68+
withPlatform = "windows";
69+
inherit arch;
70+
importEnvVars = [
71+
"CPLUS_INCLUDE_PATH"
72+
];
73+
}).overrideAttrs
74+
(
75+
old:
76+
let
77+
buildInputs = (old.buildInputs or [ ]) ++ [
78+
pkgsCross.mingwW64.windows.mingw_w64_pthreads
79+
pkgsCross.mingwW64.windows.mcfgthreads
80+
pkgsCross.mingw32.windows.mcfgthreads
81+
];
82+
83+
libs = symlinkJoin {
84+
name = "redot-export-templates-windows-libpath";
85+
paths = buildInputs;
86+
};
87+
in
88+
{
89+
nativeBuildInputs = old.nativeBuildInputs ++ [
90+
pkgsCross.mingwW64.buildPackages.gcc
91+
pkgsCross.mingw32.buildPackages.gcc
92+
];
93+
94+
inherit buildInputs;
95+
96+
env = (old.env or { }) // {
97+
CPLUS_INCLUDE_PATH = lib.makeIncludePath buildInputs;
98+
NIX_LIBS = "${libs}/lib";
99+
};
100+
101+
installPhase = ''
102+
runHook preInstall
103+
104+
mkdir -p "$out/share/redot/export_templates/${old.redotVersion}"
105+
106+
cp bin/redot.*.console.exe "$out/share/redot/export_templates/${old.redotVersion}/windows_${templateType}_${arch}_console.exe"
107+
cp bin/redot.*.${arch}.exe "$out/share/redot/export_templates/${old.redotVersion}/windows_${templateType}_${arch}.exe"
108+
109+
runHook postInstall
110+
'';
111+
}
112+
);
113+
in
114+
mkTemplate {
115+
inherit platform templateType;
116+
pkg = redot;
117+
}

flake.lock

Lines changed: 61 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: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
description = "Redot Game Engine";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
7+
flake-utils.url = "github:numtide/flake-utils";
8+
};
9+
10+
outputs =
11+
{
12+
self,
13+
nixpkgs,
14+
flake-utils,
15+
}:
16+
flake-utils.lib.eachDefaultSystem (
17+
system:
18+
let
19+
pkgs = import nixpkgs {
20+
inherit system;
21+
};
22+
pkgsCross = import nixpkgs {
23+
config = {
24+
crossSystem = "x86_64-w64-mingw32";
25+
};
26+
27+
inherit system;
28+
};
29+
30+
mkExportTemplate = pkgs.callPackage (import ./export-template-package.nix) {
31+
inherit (self.packages.${system}) redot;
32+
};
33+
in
34+
{
35+
packages = {
36+
default = self.packages.${system}.redot;
37+
38+
redot = pkgs.callPackage (import ./package.nix) {
39+
src = self;
40+
commitHash = if self ? rev then self.rev else "devel";
41+
};
42+
43+
export-templates-linux-release = mkExportTemplate {
44+
templateType = "release";
45+
platform = "linuxbsd";
46+
};
47+
48+
export-templates-linux-debug = mkExportTemplate {
49+
templateType = "debug";
50+
platform = "linuxbsd";
51+
};
52+
53+
export-templates-windows-release = mkExportTemplate {
54+
templateType = "release";
55+
platform = "windows";
56+
};
57+
58+
export-templates-windows-debug = mkExportTemplate {
59+
templateType = "debug";
60+
platform = "windows";
61+
};
62+
63+
export-templates = pkgs.symlinkJoin {
64+
name = "redot-export-templates";
65+
paths = builtins.attrValues {
66+
inherit (self.packages.${system})
67+
export-templates-linux-release
68+
export-templates-linux-debug
69+
export-templates-windows-release
70+
export-templates-windows-debug
71+
;
72+
};
73+
};
74+
};
75+
76+
devShells.default = pkgs.mkShell {
77+
inherit (self.packages.${system}.redot) nativeBuildInputs;
78+
79+
buildInputs =
80+
self.packages.${system}.redot.buildInputs ++ self.packages.${system}.redot.runtimeDependencies;
81+
};
82+
}
83+
);
84+
}

0 commit comments

Comments
 (0)