Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nix flake + package definitions for editor & export templates #954

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -380,3 +380,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 @@ -297,6 +297,9 @@ opts.Add("asflags", "Custom flags for the assembler")
opts.Add("arflags", "Custom flags for the archive tool")
opts.Add("rcflags", "Custom flags for Windows resource compiler")

# 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
117 changes: 117 additions & 0 deletions export-template-package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{

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;
}
61 changes: 61 additions & 0 deletions flake.lock

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

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

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

flake-utils.url = "github:numtide/flake-utils";
};

outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
};
pkgsCross = import nixpkgs {
config = {
crossSystem = "x86_64-w64-mingw32";
};

inherit system;
};

mkExportTemplate = pkgs.callPackage (import ./export-template-package.nix) {
inherit (self.packages.${system}) redot;
};
in
{
packages = {
default = self.packages.${system}.redot;

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

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

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

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

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

export-templates = pkgs.symlinkJoin {
name = "redot-export-templates";
paths = builtins.attrValues {
inherit (self.packages.${system})
export-templates-linux-release
export-templates-linux-debug
export-templates-windows-release
export-templates-windows-debug
;
};
};
};

devShells.default = pkgs.mkShell {
inherit (self.packages.${system}.redot) nativeBuildInputs;

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