flake.nix
111 lines · 3053 bytes
1{
2 description = "iamb";
3 nixConfig.bash-prompt = "\[nix-develop\]$ ";
4
5 inputs = {
6 nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
7 flake-utils.url = "github:numtide/flake-utils";
8 crane.url = "github:ipetkov/crane";
9 fenix = {
10 url = "github:nix-community/fenix";
11 inputs.nixpkgs.follows = "nixpkgs";
12 };
13 };
14
15 outputs =
16 {
17 self,
18 nixpkgs,
19 crane,
20 flake-utils,
21 fenix,
22 ...
23 }:
24 flake-utils.lib.eachDefaultSystem (
25 system:
26 let
27 pkgs = nixpkgs.legacyPackages.${system};
28 inherit (pkgs) lib;
29
30 rustToolchain = fenix.packages.${system}.fromToolchainFile {
31 file = ./rust-toolchain.toml;
32 # When the file changes, this hash must be updated.
33 sha256 = "sha256-Qxt8XAuaUR2OMdKbN4u8dBJOhSHxS+uS06Wl9+flVEk=";
34 };
35
36 # Nightly toolchain for rustfmt (pinned to current flake lock)
37 # Note that the github CI uses "current nightly" for formatting, it 's not pinned.
38 rustNightly = fenix.packages.${system}.latest;
39
40 craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
41 craneLibNightly = (crane.mkLib pkgs).overrideToolchain rustNightly.toolchain;
42
43 src = lib.fileset.toSource {
44 root = ./.;
45 fileset = lib.fileset.unions [
46 (craneLib.fileset.commonCargoSources ./.)
47 ./src/windows/welcome.md
48 ];
49 };
50
51 commonArgs = {
52 inherit src;
53 strictDeps = true;
54 pname = "iamb";
55 version = self.shortRev or self.dirtyShortRev;
56 };
57
58 # Build *just* the cargo dependencies, so we can reuse
59 # all of that work (e.g. via cachix) when running in CI
60 cargoArtifacts = craneLib.buildDepsOnly commonArgs;
61
62 # Build the actual crate
63 iamb = craneLib.buildPackage (commonArgs // {
64 inherit cargoArtifacts;
65 });
66 in
67 {
68 checks = {
69 # Build the crate as part of `nix flake check`
70 inherit iamb;
71
72 iamb-clippy = craneLib.cargoClippy (commonArgs // {
73 inherit cargoArtifacts;
74 cargoClippyExtraArgs = "--all-targets -- --deny warnings";
75 });
76
77 iamb-fmt = craneLibNightly.cargoFmt {
78 inherit src;
79 };
80
81 iamb-nextest = craneLib.cargoNextest (commonArgs // {
82 inherit cargoArtifacts;
83 partitions = 1;
84 partitionType = "count";
85 });
86 };
87
88 packages.default = iamb;
89
90 apps.default = flake-utils.lib.mkApp {
91 drv = iamb;
92 };
93
94 devShells.default = craneLib.devShell {
95 # Inherit inputs from checks
96 checks = self.checks.${system};
97
98 packages = with pkgs; [
99 cargo-tarpaulin
100 cargo-watch
101 sqlite
102 ];
103
104 shellHook = ''
105 # Prepend nightly rustfmt to PATH.
106 export PATH="${rustNightly.rustfmt}/bin:$PATH"
107 '';
108 };
109 }
110 );
111}