generated from Rexcrazy804/advent-of-code-rust-flake-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
118 lines (102 loc) · 2.87 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{
description = "Build a cargo project with a custom toolchain";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
git-hooks-nix = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
nixpkgs,
crane,
flake-parts,
rust-overlay,
...
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
inputs.git-hooks-nix.flakeModule
];
systems = [
"x86_64-linux"
"aarch64-linux"
];
flake = {};
perSystem = {
pkgs,
system,
config,
...
}: let
# NB: we don't need to overlay our custom toolchain for the *entire*
# pkgs (which would require rebuidling anything else which uses rust).
# Instead, we just want to update the scope that crane will use by appending
# our specific toolchain there.
craneLib = (crane.mkLib pkgs).overrideToolchain (p:
p.rust-bin.stable.latest.default.override {
extensions = ["rust-src"];
});
my-crate = craneLib.buildPackage {
src = craneLib.cleanCargoSource ./.;
strictDeps = true;
doCheck = true;
buildInputs =
[
# Add additional build inputs here
]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
};
in {
_module.args.pkgs = import nixpkgs {
inherit system;
overlays = [rust-overlay.overlays.default];
};
checks = {
inherit my-crate;
};
pre-commit = {
check.enable = true;
settings.hooks = let
rust = pkgs.rust-bin.stable.latest;
in {
alejandra.enable = true;
rustfmt = {
enable = true;
packageOverrides = {
inherit (rust) rustfmt cargo;
};
excludes = [
"4.rs"
];
};
};
};
packages.default = my-crate;
devShells.default = craneLib.devShell {
shellHook = ''
${config.pre-commit.installationScript}
'';
# Inherit inputs from checks.
checks = self.checks.${system};
# Extra inputs can be added here; cargo and rustc are provided by default
# from the toolchain that was specified earlier.
packages = [
];
};
};
};
}