Compare commits

..
2 changed files with 40 additions and 12 deletions

16
flake.lock generated
View file

@ -1,5 +1,20 @@
{ {
"nodes": { "nodes": {
"crane": {
"locked": {
"lastModified": 1785782307,
"narHash": "sha256-MPaRdVkf6zZP5fCPxYCi8Dr4pZzgmXzg8T9nVEbp3Mw=",
"owner": "ipetkov",
"repo": "crane",
"rev": "2c71e194474d13de031d729b729c968ddbe3507f",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-utils": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems" "systems": "systems"
@ -36,6 +51,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"crane": "crane",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }

View file

@ -2,6 +2,8 @@
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
@ -12,6 +14,7 @@
let let
pkgs = import inputs.nixpkgs { inherit system; }; pkgs = import inputs.nixpkgs { inherit system; };
lib = pkgs.lib; lib = pkgs.lib;
craneLib = inputs.crane.mkLib pkgs;
cargoToml = fromTOML (builtins.readFile ./Cargo.toml); cargoToml = fromTOML (builtins.readFile ./Cargo.toml);
name = cargoToml.package.name; name = cargoToml.package.name;
@ -44,6 +47,12 @@
src = ./.; src = ./.;
}; };
# Build *just* the cargo dependencies,
# to reuse them for build and test derivations.
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual crate itself,
# reusing the dependency artifacts from above.
crate = crate =
let let
desktopItem = pkgs.makeDesktopItem { desktopItem = pkgs.makeDesktopItem {
@ -53,11 +62,10 @@
exec = name; exec = name;
}; };
in in
pkgs.rustPlatform.buildRustPackage ( craneLib.buildPackage (
commonArgs commonArgs
// { // {
inherit name; inherit cargoArtifacts;
cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ nativeBuildInputs = commonArgs.nativeBuildInputs ++ [
pkgs.autoPatchelfHook pkgs.autoPatchelfHook
@ -81,18 +89,22 @@
{ {
packages.default = crate; packages.default = crate;
devShells.default = pkgs.mkShell { checks = {
crate-clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "-- --deny warnings";
}
);
};
devShells.default = craneLib.devShell {
LD_LIBRARY_PATH = lib.makeLibraryPath dlDeps; LD_LIBRARY_PATH = lib.makeLibraryPath dlDeps;
inputsFrom = [ crate ]; inputsFrom = [ crate ];
packages = [ pkgs.rust-analyzer ];
packages = with pkgs; [
rustc
cargo
clippy
rustfmt
rust-analyzer
];
}; };
} }
); );