-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
77 lines (67 loc) · 2.15 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
{
inputs = {
crane = { url = "github:ipetkov/crane?ref=master"; inputs.nixpkgs.follows = "nixpkgs"; };
fenix = { url = "github:nix-community/fenix?ref=main"; inputs.nixpkgs.follows = "nixpkgs"; };
flake-utils.url = "github:numtide/flake-utils?ref=main";
nix-filter.url = "github:numtide/nix-filter?ref=main";
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
};
outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
stdenv =
if pkgs.stdenv.isLinux then
pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv
else
pkgs.stdenv;
mkToolchain = inputs.fenix.packages.${system}.combine;
toolchain = inputs.fenix.packages.${system}.stable;
buildToolchain = mkToolchain (with toolchain; [
cargo
rustc
]);
devToolchain = mkToolchain (with toolchain; [
cargo
clippy
llvm-tools
rust-src
rustc
# Always use nightly rustfmt because most of its options are unstable
inputs.fenix.packages.${system}.latest.rustfmt
]);
builder = (
(inputs.crane.mkLib pkgs).overrideToolchain buildToolchain
).buildPackage;
in
{
packages.default = builder {
src = let filter = inputs.nix-filter.lib; in filter {
root = ./.;
include = [
"Cargo.lock"
"Cargo.toml"
"README.md"
"src"
];
};
inherit stdenv;
};
devShells.default = (pkgs.mkShell.override { inherit stdenv; }) {
env = {
# Rust Analyzer needs to be able to find the path to default crate
# sources, and it can read this environment variable to do so. The
# `rust-src` component is required in order for this to work.
RUST_SRC_PATH = "${devToolchain}/lib/rustlib/src/rust/library";
};
packages = [
devToolchain
] ++ (with pkgs; [
cargo-llvm-cov
engage
nixpkgs-fmt
]) ++ (with pkgs.nodePackages; [
markdownlint-cli
]);
};
});
}