diff options
author | Thomas Mühlbacher <tmuehlbacher@posteo.net> | 2024-05-28 18:56:08 +0200 |
---|---|---|
committer | Thomas Mühlbacher <tmuehlbacher@posteo.net> | 2024-05-28 19:32:15 +0200 |
commit | bf2c0c88528e6e6a2ffd47fe6804ec97c4708804 (patch) | |
tree | 3d12d11b38f104bd5b4931f39ab7dbd2eb14124c /flake.nix | |
parent | ce01c61ba5e7f272b5d18ae5a46f108dd569c0f4 (diff) |
build(nix): use crane to build packages
this enables faster incremental rebuilds in nix. it also allows us to
add clippy and cargo test checks more easily. aside from that, i have
tried to carry over things that i think are sensible from the previous
`mkDerivation` call.
the `checkPhase` may as well rather be done in a `installCheckPhase` and
we can set `enableParallelBuilding` to speed up the compilation of
`libbcachefs.a`.
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 76 |
1 files changed, 74 insertions, 2 deletions
@@ -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,6 +34,7 @@ flake-parts, treefmt-nix, fenix, + crane, flake-compat, ... }: @@ -46,18 +52,84 @@ { 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}" + + runHook postInstallCheck + ''; + } + ); - packages.bcachefs-tools-fuse = config.packages.bcachefs-tools.override { fuseSupport = true; }; + packages.bcachefs-tools-fuse = config.packages.bcachefs-tools.overrideAttrs ( + final: prev: { + makeFlags = prev.makeFlags ++ [ "BCACHEFS_FUSE=1" ]; + buildInputs = prev.buildInputs ++ [ pkgs.fuse3 ]; + } + ); devShells.default = pkgs.mkShell { inputsFrom = [ |