From b51a76a057090b6b4097e9e6dd8b3fa1dffc19cb Mon Sep 17 00:00:00 2001 From: Sergio Ribera <56278796+SergioRibera@users.noreply.github.com> Date: Sun, 7 Apr 2024 18:48:38 -0400 Subject: [PATCH] chore: add nix enviroment --- default.nix | 115 +++++++++++++++++++++++++++ flake.lock | 218 ++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 31 ++++++++ 3 files changed, 364 insertions(+) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..e2ccb0d --- /dev/null +++ b/default.nix @@ -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; + }; + } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..10765ae --- /dev/null +++ b/flake.lock @@ -0,0 +1,218 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1708794349, + "narHash": "sha256-jX+B1VGHT0ruHHL5RwS8L21R6miBn4B6s9iVyUJsJJY=", + "owner": "ipetkov", + "repo": "crane", + "rev": "2c94ff9a6fbeb9f3ea0107f28688edbe9c81deaa", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "cranix": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1705985690, + "narHash": "sha256-O5l2+lryVuT8ByokNrpv+NJreFKTt1jIIwdNg4kHAxI=", + "owner": "Lemin-n", + "repo": "cranix", + "rev": "2af6b2e71577bb8836b10e28f3267f2c5342a8fd", + "type": "github" + }, + "original": { + "owner": "Lemin-n", + "repo": "cranix", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": "nixpkgs_3", + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1708928609, + "narHash": "sha256-LcXC2NP/TzHMmJThZGG1e+7rht5HeuZK5WOirIDg+lU=", + "owner": "nix-community", + "repo": "fenix", + "rev": "e928fb6b5179ebd032c19afac5c461ccc0b6de55", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1706925685, + "narHash": "sha256-hVInjWMmgH4yZgA4ZtbgJM1qEAel72SYhP5nOWX4UIM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "79a13f1437e149dc7be2d1290c74d378dad60814", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1705677747, + "narHash": "sha256-eyM3okYtMgYDgmYukoUzrmuoY4xl4FUujnsv/P6I/zI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bbe7d8f876fbbe7c959c90ba2ae2852220573261", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1708807242, + "narHash": "sha256-sRTRkhMD4delO/hPxxi+XwLqPn8BuUq6nnj4JqLwOu0=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "73de017ef2d18a04ac4bfd0c02650007ccb31c2a", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1708807242, + "narHash": "sha256-sRTRkhMD4delO/hPxxi+XwLqPn8BuUq6nnj4JqLwOu0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "73de017ef2d18a04ac4bfd0c02650007ccb31c2a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "cranix": "cranix", + "fenix": "fenix", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_4" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1708878562, + "narHash": "sha256-IBHMNEe3lspVdIzjpM2OVZiBFmFw1DKtdgVN5G41pRc=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "5346002d07d09badaf37949bec68012d963d61fc", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6e3c748 --- /dev/null +++ b/flake.nix @@ -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; + } + ); +}