/
flake.nix
97 lines (91 loc) · 2.95 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{
description = "A simple rust flake using rust-overlay and craneLib";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
crane,
flake-utils,
nixpkgs,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [rust-overlay.overlays.default];
};
inherit (pkgs) lib;
stableToolchain = pkgs.rust-bin.stable.latest.default;
stableToolchainWithRustAnalyzer = pkgs.rust-bin.stable.latest.default.override {
extensions = ["rust-src" "rust-analyzer"];
# Extra targets if required
# targets = [
# "x86_64-unknown-linux-gnu"
# "x86_64-unknown-linux-musl"
# "x86_64-apple-darwin"
# "aarch64-apple-darwin"
# ];
};
craneLib = crane.lib.${system}.overrideToolchain stableToolchain;
src = craneLib.cleanCargoSource (craneLib.path ./.);
commonArgs = {
inherit src;
buildInputs = with pkgs; [libz]; # Inputs required for the TARGET system
nativeBuildInputs = with pkgs; [cmake] ++ lib.optionals pkgs.stdenv.isDarwin [libiconv]; # Intputs required for the HOST system
# This is often requird for any ffi based packages that use bindgen
# LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
# For using pkg-config that many libraries require
# PKG_CONFIG_PATH = lib.makeSearchPath "lib/pkgconfig" (with pkgs;[ openssl.dev zlib.dev ]);
};
cargoArtefacts = craneLib.buildDepsOnly commonArgs;
libraw = craneLib.buildPackage (commonArgs
// {
inherit cargoArtefacts;
});
in {
checks = {
libraw-clippy = craneLib.cargoClippy (commonArgs
// {
inherit cargoArtefacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
libraw-fmt = craneLib.cargoFmt {
inherit src;
};
libraw-nextest = craneLib.cargoNextest (commonArgs
// {
inherit cargoArtefacts;
partitions = 1;
partitionType = "count";
});
};
packages = {
default = libraw;
};
apps.default = flake-utils.lib.mkApp {
drv = libraw;
};
devShells.default =
(craneLib.overrideToolchain stableToolchainWithRustAnalyzer).devShell commonArgs
// {
buildInputs = [];
nativeBuildInputs = [];
packages = with pkgs; [
just
];
};
}
);
}