|
5 | 5 | inputs = { |
6 | 6 | nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; |
7 | 7 | flake-utils.url = "github:numtide/flake-utils"; |
8 | | - rust-overlay.url = "github:oxalica/rust-overlay"; |
| 8 | + crane.url = "github:ipetkov/crane"; |
| 9 | + fenix = { |
| 10 | + url = "github:nix-community/fenix"; |
| 11 | + inputs.nixpkgs.follows = "nixpkgs"; |
| 12 | + }; |
9 | 13 | }; |
10 | 14 |
|
11 | 15 | outputs = |
12 | 16 | { |
13 | 17 | self, |
14 | 18 | nixpkgs, |
| 19 | + crane, |
15 | 20 | flake-utils, |
16 | | - rust-overlay, |
| 21 | + fenix, |
17 | 22 | ... |
18 | 23 | }: |
19 | 24 | flake-utils.lib.eachDefaultSystem ( |
20 | 25 | system: |
21 | 26 | let |
22 | | - # We only need the nightly overlay in the devShell because .rs files are formatted with nightly. |
23 | | - overlays = [ (import rust-overlay) ]; |
24 | | - pkgs = import nixpkgs { inherit system overlays; }; |
25 | | - rustNightly = pkgs.rust-bin.nightly."2025-08-31".default; |
26 | | - in |
27 | | - with pkgs; |
28 | | - { |
29 | | - packages.default = rustPlatform.buildRustPackage { |
| 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-Hn2uaQzRLidAWpfmRwSRdImifGUCAb9HeAqTYFXWeQk="; |
| 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.toolchain; |
| 39 | + rustNightlyFmt = fenix.packages.${system}.latest.rustfmt; |
| 40 | + |
| 41 | + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; |
| 42 | + craneLibNightly = (crane.mkLib pkgs).overrideToolchain rustNightly; |
| 43 | + |
| 44 | + src = lib.fileset.toSource { |
| 45 | + root = ./.; |
| 46 | + fileset = lib.fileset.unions [ |
| 47 | + (craneLib.fileset.commonCargoSources ./.) |
| 48 | + ./src/windows/welcome.md |
| 49 | + ]; |
| 50 | + }; |
| 51 | + |
| 52 | + commonArgs = { |
| 53 | + inherit src; |
| 54 | + strictDeps = true; |
30 | 55 | pname = "iamb"; |
31 | 56 | version = self.shortRev or self.dirtyShortRev; |
32 | | - src = ./.; |
33 | | - cargoLock = { |
34 | | - lockFile = ./Cargo.lock; |
| 57 | + }; |
| 58 | + |
| 59 | + # Build *just* the cargo dependencies, so we can reuse |
| 60 | + # all of that work (e.g. via cachix) when running in CI |
| 61 | + cargoArtifacts = craneLib.buildDepsOnly commonArgs; |
| 62 | + |
| 63 | + # Build the actual crate |
| 64 | + iamb = craneLib.buildPackage (commonArgs // { |
| 65 | + inherit cargoArtifacts; |
| 66 | + }); |
| 67 | + in |
| 68 | + { |
| 69 | + checks = { |
| 70 | + # Build the crate as part of `nix flake check` |
| 71 | + inherit iamb; |
| 72 | + |
| 73 | + iamb-clippy = craneLib.cargoClippy (commonArgs // { |
| 74 | + inherit cargoArtifacts; |
| 75 | + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; |
| 76 | + }); |
| 77 | + |
| 78 | + iamb-fmt = craneLibNightly.cargoFmt { |
| 79 | + inherit src; |
35 | 80 | }; |
36 | | - nativeBuildInputs = [ pkg-config ]; |
37 | | - buildInputs = [ openssl ]; |
| 81 | + |
| 82 | + iamb-nextest = craneLib.cargoNextest (commonArgs // { |
| 83 | + inherit cargoArtifacts; |
| 84 | + partitions = 1; |
| 85 | + partitionType = "count"; |
| 86 | + }); |
38 | 87 | }; |
39 | 88 |
|
40 | | - devShell = mkShell { |
41 | | - buildInputs = [ |
42 | | - (rustNightly.override { |
43 | | - extensions = [ |
44 | | - "rust-src" |
45 | | - "rust-analyzer-preview" |
46 | | - "rustfmt" |
47 | | - "clippy" |
48 | | - ]; |
49 | | - }) |
50 | | - pkg-config |
| 89 | + packages.default = iamb; |
| 90 | + |
| 91 | + apps.default = flake-utils.lib.mkApp { |
| 92 | + drv = iamb; |
| 93 | + }; |
| 94 | + |
| 95 | + devShells.default = craneLib.devShell { |
| 96 | + # Inherit inputs from checks |
| 97 | + checks = self.checks.${system}; |
| 98 | + |
| 99 | + packages = with pkgs; [ |
| 100 | + rustNightlyFmt |
51 | 101 | cargo-tarpaulin |
52 | 102 | cargo-watch |
53 | 103 | sqlite |
|
0 commit comments