Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Nix build and dev-shell support via Nix flakes #1199

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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