From 3bcd05e9a17f4df53ef7b8a1f02f08e23d69173c Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Tue, 11 Oct 2022 01:05:35 +0200 Subject: [PATCH] Added Nix build and dev-shell support via Nix flakes --- default.nix | 10 +++++ flake.lock | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 80 ++++++++++++++++++++++++++++++++++++++ shell.nix | 10 +++++ 4 files changed, 210 insertions(+) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/default.nix b/default.nix new file mode 100644 index 000000000..2cccff28d --- /dev/null +++ b/default.nix @@ -0,0 +1,10 @@ +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..d10c2c006 --- /dev/null +++ b/flake.lock @@ -0,0 +1,110 @@ +{ + "nodes": { + "crane": { + "inputs": { + "flake-compat": [ + "flake-compat" + ], + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1665356181, + "narHash": "sha256-ONEzlKL5LN4Y1TRfFY6C39G2Am1YFEjArwMYJONFhhs=", + "owner": "ipetkov", + "repo": "crane", + "rev": "d78cb0453b9823d2102f7b22bb98686215462416", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1665431855, + "narHash": "sha256-/z4/QjPQ5g4Y4mQ5HJPn8siqqE1bjtEcmmkBUU0MqrQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f77a8a1df0cb83542be93f7d7ae962ab5a3ee78b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1665398664, + "narHash": "sha256-y/UcVB5k0Wdc0j+7whJE2+vko8m296wZYX37b2lFSpI=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "af29a900f10dd6e467622202fb4f6d944d72a3a6", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..b91b3367f --- /dev/null +++ b/flake.nix @@ -0,0 +1,80 @@ +{ + description = "Fornjot is an early-stage project to create a next-generation, code-first CAD application"; + inputs = { + flake-compat = { url = "github:edolstra/flake-compat"; flake = false; }; + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { url = "github:oxalica/rust-overlay"; inputs = { nixpkgs.follows = "nixpkgs"; flake-utils.follows = "flake-utils"; }; }; + crane = { + url = "github:ipetkov/crane"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-compat.follows = "flake-compat"; + flake-utils.follows = "flake-utils"; + }; + }; + }; + + outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; overlays = [ (import rust-overlay) ]; }; + rustToolchain = pkgs.rust-bin.fromRustupToolchain ( + # extend toolchain with rust-analyzer for better IDE support + let toolchainToml = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain; in + { + channel = toolchainToml.channel; + components = toolchainToml.components ++ [ "rust-analyzer" ]; + } + ); + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; + # Only keeps assets in crates/ (currently shaders and fonts) + assetsFilter = path: _type: (builtins.match ".*(:?wgsl|ttf)$" path) != null; + filter = path: type: (assetsFilter path type) || (craneLib.filterCargoSources path type); + buildInputs = with pkgs; [ + pkg-config + fontconfig + cmake + wayland + libGL + xorg.libX11 + xorg.libXcursor + xorg.libXi + xorg.libXrandr + ]; + + fornjot = craneLib.buildPackage { + pname = "fj-app"; + src = nixpkgs.lib.cleanSourceWith { src = ./.; inherit filter; }; + inherit buildInputs; + }; + + wrappedFornjot = pkgs.symlinkJoin { + name = "fj-app"; + paths = [ fornjot ]; + + buildInputs = [ pkgs.makeWrapper ]; + + postBuild = '' + wrapProgram $out/bin/fj-app \ + --prefix LD_LIBRARY_PATH : ${nixpkgs.lib.makeLibraryPath [ pkgs.vulkan-loader ]} + ''; + }; + in + { + checks = { inherit fornjot; }; + + packages.default = wrappedFornjot; + + apps.default = flake-utils.lib.mkApp { drv = wrappedFornjot; }; + + devShells.default = pkgs.mkShell { + inputsFrom = builtins.attrValues self.checks; + + inherit buildInputs; + nativeBuildInputs = [ rustToolchain ]; + + LD_LIBRARY_PATH = "${nixpkgs.lib.makeLibraryPath [ pkgs.vulkan-loader ]}"; + }; + }); +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 000000000..6234bb4d6 --- /dev/null +++ b/shell.nix @@ -0,0 +1,10 @@ +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).shellNix