Skip to content

Commit

Permalink
chore: add nix enviroment
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Apr 7, 2024
1 parent e54a956 commit b51a76a
Show file tree
Hide file tree
Showing 3 changed files with 364 additions and 0 deletions.
115 changes: 115 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
let
inherit
(builtins)
currentSystem
fromJSON
readFile
;
getFlake = name:
with (fromJSON (readFile ./flake.lock)).nodes.${name}.locked; {
inherit rev;
outPath = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};
};
in
{
system ? currentSystem,
pkgs ? import (getFlake "nixpkgs") {localSystem = {inherit system;};},
lib ? pkgs.lib,
crane,
cranix,
fenix,
stdenv ? pkgs.stdenv,
...
}: let
# fenix: rustup replacement for reproducible builds
# toolchain = fenix.${system}.fromToolchainFile { dir = ./..; };
toolchain = fenix.${system}.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-e4mlaJehWBymYxJGgnbuCObVlqMlQSilZ8FljG9zPHY=";
};
# crane: cargo and artifacts manager
craneLib = crane.${system}.overrideToolchain toolchain;
# cranix: extends crane building system with workspace bin building and Mold + Cranelift integrations
cranixLib = craneLib.overrideScope' (cranix.${system}.craneOverride);

# buildInputs for Examples
buildInputs = with pkgs; [
stdenv.cc.cc.lib
alsa-lib
udev
libxkbcommon
libxkbcommon.dev
wayland
wayland-protocols
xorg.libX11
xorg.libXcursor
xorg.libXrandr
xorg.libXi
vulkan-loader
];

# Base args, need for build all crate artifacts and caching this for late builds
deps = {
nativeBuildInputs = with pkgs;
[
pkg-config
autoPatchelfHook
]
++ lib.optionals stdenv.buildPlatform.isDarwin [
pkgs.libiconv
]
++ lib.optionals stdenv.buildPlatform.isLinux [
pkgs.libxkbcommon.dev
];
runtimeDependencies = with pkgs;
lib.optionals stdenv.isLinux [
wayland
libGL
libxkbcommon
];
inherit buildInputs;
};

# Lambda for build packages with cached artifacts
commonArgs = targetName:
deps
// {
src = lib.cleanSourceWith {
src = craneLib.path ./.;
filter = craneLib.filterCargoSources;
};
doCheck = false;
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "${stdenv.cc.targetPrefix}cc";
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER = "qemu-aarch64";
HOST_CC = "${stdenv.cc.nativePrefix}cc";
pname = targetName;
cargoExtraArgs = "-F dev --example ${targetName}";
};
customSkipApp = cranixLib.buildCranixBundle (commonArgs "custom_skip");
layoutsApp = cranixLib.buildCranixBundle (commonArgs "layouts");
screensApp = cranixLib.buildCranixBundle (commonArgs "screens");
simpleApp = cranixLib.buildCranixBundle (commonArgs "simple");
in {
# `nix run`
apps = rec {
simple = simpleApp.app;
layouts= layoutsApp.app;
screens = screensApp.app;
customSkip = customSkipApp.app;
default = simple;
};
# `nix develop`
devShells.default = cranixLib.devShell {
packages = with pkgs;
[
toolchain
pkg-config
cargo-release
]
++ buildInputs;
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
};
}
218 changes: 218 additions & 0 deletions flake.lock

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

31 changes: 31 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
description = "SplashScreen Bevy lib";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
cranix.url = "github:Lemin-n/cranix";
crane.url = "github:ipetkov/crane";
fenix.url = "github:nix-community/fenix";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = {
self,
nixpkgs,
flake-utils,
...
} @ inputs:
# Iterate over Arm, x86 for MacOs 🍎 and Linux 🐧
flake-utils.lib.eachSystem (flake-utils.lib.defaultSystems) (
system: let
bevyLibBundle = import ./. {
inherit system;
pkgs = nixpkgs.legacyPackages.${system};
crane = inputs.crane.lib;
cranix = inputs.cranix.lib;
fenix = inputs.fenix.packages;
};
in {
inherit (bevyLibBundle) apps devShells;
}
);
}

0 comments on commit b51a76a

Please sign in to comment.