improve the nix flake
It's pretty much the same as it was before but now it's more better.
This commit is contained in:
parent
118a061ac9
commit
f54dd1c0fb
1 changed files with 59 additions and 45 deletions
104
flake.nix
104
flake.nix
|
@ -7,6 +7,7 @@
|
||||||
url = "github:nix-community/fenix";
|
url = "github:nix-community/fenix";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
crane = {
|
crane = {
|
||||||
url = "github:ipetkov/crane";
|
url = "github:ipetkov/crane";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
@ -22,14 +23,32 @@
|
||||||
, crane
|
, crane
|
||||||
}: flake-utils.lib.eachDefaultSystem (system:
|
}: flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
|
||||||
# Use mold on Linux
|
overlays = [
|
||||||
stdenv =
|
(final: prev: {
|
||||||
if pkgs.stdenv.isLinux then
|
rocksdb = prev.rocksdb.overrideAttrs (old:
|
||||||
pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv
|
let
|
||||||
else
|
version = "8.8.1";
|
||||||
pkgs.stdenv;
|
in
|
||||||
|
{
|
||||||
|
inherit version;
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "facebook";
|
||||||
|
repo = "rocksdb";
|
||||||
|
rev = "v${version}";
|
||||||
|
hash = "sha256-eE29iojVhR660mXTdX7yT+oqFk5oteBjZcLkmgHQWaY=";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
stdenv = if pkgs.stdenv.isLinux then
|
||||||
|
pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv
|
||||||
|
else
|
||||||
|
pkgs.stdenv;
|
||||||
|
|
||||||
# Nix-accessible `Cargo.toml`
|
# Nix-accessible `Cargo.toml`
|
||||||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
||||||
|
@ -43,62 +62,57 @@
|
||||||
sha256 = "sha256-gdYqng0y9iHYzYPAdkC/ka3DRny3La/S5G8ASj0Ayyc=";
|
sha256 = "sha256-gdYqng0y9iHYzYPAdkC/ka3DRny3La/S5G8ASj0Ayyc=";
|
||||||
};
|
};
|
||||||
|
|
||||||
rocksdb = pkgs.rocksdb.overrideAttrs
|
mkToolchain = fenix.packages.${system}.combine;
|
||||||
(oldAttrs: rec {
|
|
||||||
version = "8.8.1";
|
|
||||||
src = pkgs.fetchFromGitHub {
|
|
||||||
owner = "facebook";
|
|
||||||
repo = "rocksdb";
|
|
||||||
rev = "v${version}";
|
|
||||||
hash = "sha256-eE29iojVhR660mXTdX7yT+oqFk5oteBjZcLkmgHQWaY=";
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
# The system's RocksDB
|
buildToolchain = mkToolchain (with toolchain; [
|
||||||
ROCKSDB_INCLUDE_DIR = "${rocksdb}/include";
|
cargo
|
||||||
ROCKSDB_LIB_DIR = "${rocksdb}/lib";
|
rustc
|
||||||
|
]);
|
||||||
|
|
||||||
|
devToolchain = mkToolchain (with toolchain; [
|
||||||
|
cargo
|
||||||
|
clippy
|
||||||
|
rust-src
|
||||||
|
rustc
|
||||||
|
|
||||||
|
# Always use nightly rustfmt because most of its options are unstable
|
||||||
|
fenix.packages.${system}.latest.rustfmt
|
||||||
|
]);
|
||||||
|
|
||||||
|
builder =
|
||||||
|
((crane.mkLib pkgs).overrideToolchain buildToolchain).buildPackage;
|
||||||
|
|
||||||
# Shared between the package and the devShell
|
|
||||||
nativeBuildInputs = (with pkgs.rustPlatform; [
|
nativeBuildInputs = (with pkgs.rustPlatform; [
|
||||||
bindgenHook
|
bindgenHook
|
||||||
]);
|
]);
|
||||||
|
|
||||||
builder =
|
env = {
|
||||||
((crane.mkLib pkgs).overrideToolchain toolchain.toolchain).buildPackage;
|
ROCKSDB_INCLUDE_DIR = "${pkgs.rocksdb}/include";
|
||||||
|
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib";
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages.default = builder {
|
packages.default = builder {
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
stdenv
|
env
|
||||||
nativeBuildInputs
|
nativeBuildInputs
|
||||||
ROCKSDB_INCLUDE_DIR
|
stdenv;
|
||||||
ROCKSDB_LIB_DIR;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells.default = (pkgs.mkShell.override { inherit stdenv; }) {
|
devShells.default = (pkgs.mkShell.override { inherit stdenv; }) {
|
||||||
# Rust Analyzer needs to be able to find the path to default crate
|
env = env // {
|
||||||
# sources, and it can read this environment variable to do so
|
# Rust Analyzer needs to be able to find the path to default crate
|
||||||
RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/library";
|
# sources, and it can read this environment variable to do so. The
|
||||||
|
# `rust-src` component is required in order for this to work.
|
||||||
inherit
|
RUST_SRC_PATH = "${devToolchain}/lib/rustlib/src/rust/library";
|
||||||
ROCKSDB_INCLUDE_DIR
|
};
|
||||||
ROCKSDB_LIB_DIR;
|
|
||||||
|
|
||||||
# Development tools
|
# Development tools
|
||||||
nativeBuildInputs = nativeBuildInputs ++ (with toolchain; [
|
nativeBuildInputs = nativeBuildInputs ++ [
|
||||||
cargo
|
devToolchain
|
||||||
clippy
|
];
|
||||||
rust-src
|
|
||||||
rustc
|
|
||||||
rustfmt
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
checks = {
|
|
||||||
packagesDefault = self.packages.${system}.default;
|
|
||||||
devShellsDefault = self.devShells.${system}.default;
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue