Created flake and added license.txt

This commit is contained in:
chrisbell committed 2026-11-01 23:07:19 -06:00
1 parent 013d9d5cf2
commit 4ad6685042
4 files changed
+261

No files matched your search

+187
View File
@@ -0,0 +1,187 @@
{
description = "Regolith, a retained mode GUI library for Odin";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# Pinned to the latest monthly release tag
# If you change this, also change odinVersion below
odin-src = {
url = "github:odin-lang/Odin/dev-2026-10";
flake = false;
};
# OLS must match the Odin revision
ols-src = {
url = "github:DanielGavin/ols/dev-2026-10";
flake = false;
};
};
outputs = { self, nixpkgs, odin-src, ols-src }:
let
lib = nixpkgs.lib;
systems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = f:
lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
odinVersion = "2026-10";
build = pkgs:
let
llvmPackages = pkgs.llvmPackages_20;
odin = llvmPackages.stdenv.mkDerivation {
pname = "odin";
version = "dev-${odinVersion}";
src = odin-src;
nativeBuildInputs = [ pkgs.makeBinaryWrapper pkgs.which ];
buildInputs = [ llvmPackages.llvm ];
LLVM_CONFIG = "${llvmPackages.llvm.dev}/bin/llvm-config";
# The build script stamps the version from the build date, which is
# meaningless inside the Nix sandbox. Stamp the tag instead.
postPatch = ''
substituteInPlace build_odin.sh \
--replace-fail '$(date +"%Y-%m")' '${odinVersion}'
patchShebangs build_odin.sh
'';
dontConfigure = true;
buildPhase = ''
runHook preBuild
./build_odin.sh release
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin $out/share
cp odin $out/bin/odin
for d in base core vendor shared; do
if [ -d "$d" ]; then cp -r "$d" $out/share/; fi
done
wrapProgram $out/bin/odin \
--prefix PATH : ${lib.makeBinPath [
llvmPackages.bintools
llvmPackages.clang
llvmPackages.lld
]} \
--set-default ODIN_ROOT $out/share
# Build the C parts of the vendor collection.
for v in stb cgltf miniaudio; do
d="$out/share/vendor/$v/src"
[ -d "$d" ] || continue
if [ -f "$d/Makefile" ] || [ -f "$d/makefile" ] || [ -f "$d/GNUmakefile" ]; then
make -C "$d"
elif [ -f "$d/build_$v.sh" ]; then
patchShebangs "$d/build_$v.sh"
(cd "$d" && "./build_$v.sh") || echo "vendor/$v: build script failed, skipping"
else
echo "vendor/$v/src: no known build entry point, skipping"
fi
done
runHook postInstall
'';
};
ols = pkgs.stdenv.mkDerivation {
pname = "ols";
version = "dev-${odinVersion}";
src = ols-src;
nativeBuildInputs = [ odin ];
dontConfigure = true;
postPatch = ''
patchShebangs build.sh odinfmt.sh
'';
buildPhase = ''
runHook preBuild
./build.sh
./odinfmt.sh
runHook postBuild
'';
installPhase = ''
runHook preInstall
install -Dm755 ols $out/bin/ols
install -Dm755 odinfmt $out/bin/odinfmt
runHook postInstall
'';
};
in
{ inherit odin ols llvmPackages; };
in
{
packages = forAllSystems (pkgs:
let p = build pkgs; in {
inherit (p) odin ols;
default = p.odin;
});
devShells = forAllSystems (pkgs:
let
p = build pkgs;
llvmPackages = p.llvmPackages;
runtimeLibs = with pkgs; [
sdl3
wayland
libxkbcommon
libdecor
vulkan-loader
libGL
];
in
{
default = (pkgs.mkShell.override { stdenv = llvmPackages.stdenv; }) {
name = "regolith";
packages = [
# Odin toolchain
p.odin
p.ols
llvmPackages.lld
llvmPackages.bintools
# Native build and runtime
pkgs.pkg-config
pkgs.sdl3
# WASM
pkgs.emscripten
pkgs.nodejs
pkgs.python3
# Lua tooling (the engine builds its own vendored Lua)
pkgs.lua5_4
pkgs.lua54Packages.luacheck
# Debugging
pkgs.gdb
pkgs.valgrind
pkgs.git
];
shellHook = ''
# Emscripten needs a writable cache, and the store is read only.
export EM_CACHE="$PWD/.cache/emscripten"
mkdir -p "$EM_CACHE"
# SDL3 dlopens these at runtime. nixpkgs SDL3 is patched to find
# most of them, this is a fallback for anything built outside Nix.
export LD_LIBRARY_PATH="${lib.makeLibraryPath runtimeLibs}:/run/opengl-driver/lib:''${LD_LIBRARY_PATH:-}"
'';
};
});
};
}