|
| 1 | +{ |
| 2 | + description = "A nix development shell and build environment for galileo"; |
| 3 | + |
| 4 | + inputs = { |
| 5 | + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; |
| 6 | + flake-utils.url = "github:numtide/flake-utils"; |
| 7 | + rust-overlay = { |
| 8 | + url = "github:oxalica/rust-overlay"; |
| 9 | + inputs = { |
| 10 | + nixpkgs.follows = "nixpkgs"; |
| 11 | + flake-utils.follows = "flake-utils"; |
| 12 | + }; |
| 13 | + }; |
| 14 | + crane = { |
| 15 | + url = "github:ipetkov/crane"; |
| 16 | + inputs = { nixpkgs.follows = "nixpkgs"; }; |
| 17 | + }; |
| 18 | + }; |
| 19 | + |
| 20 | + outputs = { nixpkgs, flake-utils, rust-overlay, crane, ... }: |
| 21 | + flake-utils.lib.eachDefaultSystem |
| 22 | + (system: |
| 23 | + let |
| 24 | + # Set up for Rust builds, pinned to the Rust toolchain version in the Penumbra repository |
| 25 | + overlays = [ (import rust-overlay) ]; |
| 26 | + pkgs = import nixpkgs { inherit system overlays; }; |
| 27 | + rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; |
| 28 | + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; |
| 29 | + src = craneLib.cleanCargoSource (craneLib.path ./.); |
| 30 | + # Important environment variables so that the build can find the necessary libraries |
| 31 | + PKG_CONFIG_PATH="${pkgs.openssl.dev}/lib/pkgconfig"; |
| 32 | + LIBCLANG_PATH="${pkgs.libclang.lib}/lib"; |
| 33 | + in with pkgs; with pkgs.lib; let |
| 34 | + galileo = (craneLib.buildPackage { |
| 35 | + inherit src system PKG_CONFIG_PATH LIBCLANG_PATH; |
| 36 | + pname = "galileo"; |
| 37 | + version = "0.1.0"; |
| 38 | + nativeBuildInputs = [ pkg-config ]; |
| 39 | + buildInputs = [ clang openssl ]; |
| 40 | + # A lockfile is not used in this repository. |
| 41 | + cargoVendorDir = null; |
| 42 | + }).overrideAttrs (_: { doCheck = false; }); # Disable tests to improve build times |
| 43 | + in { |
| 44 | + inherit galileo; |
| 45 | + devShells.default = craneLib.devShell { |
| 46 | + inherit LIBCLANG_PATH; |
| 47 | + inputsFrom = [ galileo ]; |
| 48 | + packages = [ cargo-watch cargo-nextest ]; |
| 49 | + shellHook = '' |
| 50 | + export LIBCLANG_PATH=${LIBCLANG_PATH} |
| 51 | + export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} # Required for rust-analyzer |
| 52 | + ''; |
| 53 | + }; |
| 54 | + } |
| 55 | + ); |
| 56 | +} |
0 commit comments