diff options
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 52 |
1 files changed, 35 insertions, 17 deletions
@@ -1,15 +1,16 @@ { inputs = { - nixpkgs.url = "github:NixOS/nixpkgs"; + nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; fenix = { url = "github:nix-community/fenix"; inputs.nixpkgs.follows = "nixpkgs"; }; - naersk = { - url = "github:nix-community/naersk"; + crane = { + url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; }; }; @@ -19,11 +20,17 @@ , flake-utils , fenix - , naersk + , crane }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; + # Use mold on Linux + stdenv = if pkgs.stdenv.isLinux then + pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv + else + pkgs.stdenv; + # Nix-accessible `Cargo.toml` cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); @@ -32,33 +39,44 @@ # Use the Rust version defined in `Cargo.toml` channel = cargoToml.package.rust-version; - # This will need to be updated when `package.rust-version` is changed in - # `Cargo.toml` - sha256 = "sha256-KXx+ID0y4mg2B3LHp7IyaiMrdexF6octADnAtFIOjrY="; + # THE rust-version HASH + sha256 = "sha256-gdYqng0y9iHYzYPAdkC/ka3DRny3La/S5G8ASj0Ayyc="; }; - builder = (pkgs.callPackage naersk { - inherit (toolchain) rustc cargo; - }).buildPackage; + # The system's RocksDB + ROCKSDB_INCLUDE_DIR = "${pkgs.rocksdb}/include"; + ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib"; + + # Shared between the package and the devShell + nativeBuildInputs = (with pkgs.rustPlatform; [ + bindgenHook + ]); + + builder = + ((crane.mkLib pkgs).overrideToolchain toolchain.toolchain).buildPackage; in { packages.default = builder { src = ./.; - nativeBuildInputs = (with pkgs.rustPlatform; [ - bindgenHook - ]); + inherit + stdenv + nativeBuildInputs + ROCKSDB_INCLUDE_DIR + ROCKSDB_LIB_DIR; }; - devShells.default = pkgs.mkShell { + devShells.default = (pkgs.mkShell.override { inherit stdenv; }) { # Rust Analyzer needs to be able to find the path to default crate # sources, and it can read this environment variable to do so RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/library"; + inherit + ROCKSDB_INCLUDE_DIR + ROCKSDB_LIB_DIR; + # Development tools - nativeBuildInputs = (with pkgs.rustPlatform; [ - bindgenHook - ]) ++ (with toolchain; [ + nativeBuildInputs = nativeBuildInputs ++ (with toolchain; [ cargo clippy rust-src |