Skip to content

Commit

Permalink
Merge pull request #1199 from Philipp-M/nix-flakes
Browse files Browse the repository at this point in the history
Added Nix build and dev-shell support via Nix flakes
  • Loading branch information
hannobraun authored Oct 11, 2022
2 parents bbddc4b + 3bcd05e commit e02c595
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 0 deletions.
10 changes: 10 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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
110 changes: 110 additions & 0 deletions flake.lock

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

80 changes: 80 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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 ]}";
};
});
}
10 changes: 10 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e02c595

Please sign in to comment.