summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--INSTALL.md5
-rw-r--r--build.nix77
-rw-r--r--flake.lock21
-rw-r--r--flake.nix106
4 files changed, 125 insertions, 84 deletions
diff --git a/INSTALL.md b/INSTALL.md
index 99c33776..977f6456 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -17,8 +17,9 @@ Build dependencies:
* zlib1g
In addition a recent Rust toolchain is required (rustc, cargo), either by using
-[rustup](https://rustup.rs/) or make sure to use a distribution where rustc (>=1.65)
-is available.
+[rustup](https://rustup.rs/) or make sure to use a distribution where a recent
+enough rustc is available. Please check `rust-version` in `Cargo.toml` to see
+the minimum supported Rust version (MSRV).
``` shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path
diff --git a/build.nix b/build.nix
deleted file mode 100644
index 4927519c..00000000
--- a/build.nix
+++ /dev/null
@@ -1,77 +0,0 @@
-{
- lib,
- stdenv,
- pkg-config,
- attr,
- libuuid,
- libsodium,
- keyutils,
- liburcu,
- zlib,
- libaio,
- udev,
- zstd,
- lz4,
- nix-gitignore,
- rustPlatform,
- rustc,
- cargo,
- fuse3,
- fuseSupport ? false,
-}:
-let
- src = nix-gitignore.gitignoreSource [ ] ./.;
-
- commit = lib.strings.substring 0 7 (builtins.readFile ./.bcachefs_revision);
- version = "git-${commit}";
-in
-stdenv.mkDerivation {
- inherit src version;
-
- pname = "bcachefs-tools";
-
- nativeBuildInputs = [
- pkg-config
- cargo
- rustc
- rustPlatform.cargoSetupHook
- rustPlatform.bindgenHook
- ];
-
- buildInputs = [
- libaio
- keyutils # libkeyutils
- lz4 # liblz4
-
- libsodium
- liburcu
- libuuid
- zstd # libzstd
- zlib # zlib1g
- attr
- udev
- ] ++ lib.optional fuseSupport fuse3;
-
- ${if fuseSupport then "BCACHEFS_FUSE" else null} = "1";
-
- cargoRoot = ".";
- # when git-based crates are updated, run:
- # nix run github:Mic92/nix-update -- --version=skip --flake default
- # to update the hashes
- cargoDeps = rustPlatform.importCargoLock { lockFile = "${src}/Cargo.lock"; };
-
- makeFlags = [
- "DESTDIR=${placeholder "out"}"
- "PREFIX="
- "VERSION=${commit}"
- ];
-
- dontStrip = true;
- checkPhase = "./target/release/bcachefs version";
- doCheck = true;
-
- meta = {
- mainProgram = "bcachefs";
- license = lib.licenses.gpl2Only;
- };
-}
diff --git a/flake.lock b/flake.lock
index 6cd43325..47820499 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,5 +1,25 @@
{
"nodes": {
+ "crane": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1716745752,
+ "narHash": "sha256-8K1R9Yg4r08rYk86Yq+lu3E9L3uRUb4xMqYHgl0VGS0=",
+ "owner": "ipetkov",
+ "repo": "crane",
+ "rev": "19ca94ec2d288de334ae932107816b4a97736cd8",
+ "type": "github"
+ },
+ "original": {
+ "owner": "ipetkov",
+ "repo": "crane",
+ "type": "github"
+ }
+ },
"fenix": {
"inputs": {
"nixpkgs": [
@@ -85,6 +105,7 @@
},
"root": {
"inputs": {
+ "crane": "crane",
"fenix": "fenix",
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
diff --git a/flake.nix b/flake.nix
index 6d946dbc..3cd44ec8 100644
--- a/flake.nix
+++ b/flake.nix
@@ -11,6 +11,11 @@
inputs.nixpkgs.follows = "nixpkgs";
};
+ crane = {
+ url = "github:ipetkov/crane";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
@@ -29,7 +34,7 @@
flake-parts,
treefmt-nix,
fenix,
- flake-compat,
+ crane,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
@@ -46,18 +51,110 @@
{
self',
config,
+ lib,
pkgs,
system,
...
}:
let
+ cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
rustfmtToml = builtins.fromTOML (builtins.readFile ./rustfmt.toml);
+
+ craneLib = crane.mkLib pkgs;
+
+ commit = lib.strings.substring 0 7 (builtins.readFile ./.bcachefs_revision);
+
+ commonArgs = {
+ version = "git-${commit}";
+ src = self;
+
+ makeFlags = [
+ "DESTDIR=${placeholder "out"}"
+ "PREFIX="
+ "VERSION=${commit}"
+ ];
+
+ dontStrip = true;
+
+ nativeBuildInputs = with pkgs; [
+ pkg-config
+ rustPlatform.bindgenHook
+ ];
+
+ buildInputs = with pkgs; [
+ attr
+ keyutils
+ libaio
+ libsodium
+ liburcu
+ libuuid
+ lz4
+ udev
+ zlib
+ zstd
+ ];
+ };
+
+ cargoArtifacts = craneLib.buildDepsOnly (commonArgs // { pname = cargoToml.package.name; });
in
{
packages.default = config.packages.bcachefs-tools;
- packages.bcachefs-tools = pkgs.callPackage ./build.nix { };
+ packages.bcachefs-tools = craneLib.buildPackage (
+ commonArgs
+ // {
+ inherit cargoArtifacts;
+
+ enableParallelBuilding = true;
+ buildPhaseCargoCommand = ''
+ make ''${enableParallelBuilding:+-j''${NIX_BUILD_CORES}} $makeFlags
+ '';
+ installPhaseCommand = ''
+ make ''${enableParallelBuilding:+-j''${NIX_BUILD_CORES}} $makeFlags install
+ '';
+
+ doInstallCheck = true;
+ installCheckPhase = ''
+ runHook preInstallCheck
+
+ test "$($out/bin/bcachefs version)" = "${commit}"
- packages.bcachefs-tools-fuse = config.packages.bcachefs-tools.override { fuseSupport = true; };
+ runHook postInstallCheck
+ '';
+ }
+ );
+
+ packages.bcachefs-tools-fuse = config.packages.bcachefs-tools.overrideAttrs (
+ final: prev: {
+ makeFlags = prev.makeFlags ++ [ "BCACHEFS_FUSE=1" ];
+ buildInputs = prev.buildInputs ++ [ pkgs.fuse3 ];
+ }
+ );
+
+ checks.cargo-clippy = craneLib.cargoClippy (
+ commonArgs
+ // {
+ inherit cargoArtifacts;
+ cargoClippyExtraArgs = "--all-targets -- --deny warnings";
+ }
+ );
+
+ # we have to build our own `craneLib.cargoTest`
+ checks.cargo-test = craneLib.mkCargoDerivation (
+ commonArgs
+ // {
+ inherit cargoArtifacts;
+ doCheck = true;
+
+ enableParallelChecking = true;
+
+ pnameSuffix = "-test";
+ buildPhaseCargoCommand = "";
+ checkPhaseCargoCommand = ''
+ make ''${enableParallelChecking:+-j''${NIX_BUILD_CORES}} $makeFlags libbcachefs.a
+ cargo test --profile release -- --nocapture
+ '';
+ }
+ );
devShells.default = pkgs.mkShell {
inputsFrom = [
@@ -65,8 +162,6 @@
config.treefmt.build.devShell
];
- LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib";
-
# here go packages that aren't required for builds but are used for
# development, and might need to be version matched with build
# dependencies (e.g. clippy or rust-analyzer).
@@ -76,6 +171,7 @@
clang-tools
clippy
rust-analyzer
+ rustc
];
};