Skip to content

Commit 1ec3115

Browse files
authored
Use cargo crane in Nix flake and set up cachix action (#539)
1 parent 0ddded3 commit 1ec3115

File tree

4 files changed

+151
-58
lines changed

4 files changed

+151
-58
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,25 @@ jobs:
4545
reporter: 'github-check'
4646
- name: Run tests
4747
run: cargo test --locked
48+
49+
nix-flake-test:
50+
name: Flake checks ❄️
51+
strategy:
52+
matrix:
53+
platform: [ubuntu-latest, macos-latest]
54+
runs-on: ${{ matrix.platform }}
55+
steps:
56+
- name: Checkout Code
57+
uses: actions/checkout@v4
58+
- uses: cachix/install-nix-action@v31
59+
with:
60+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
61+
- uses: cachix/cachix-action@v15
62+
with:
63+
name: iamb-prs
64+
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
65+
- name: Flake check
66+
run: |
67+
nix flake show
68+
nix flake check --print-build-logs
69+

flake.lock

Lines changed: 52 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 76 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,99 @@
55
inputs = {
66
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
77
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+
};
913
};
1014

1115
outputs =
1216
{
1317
self,
1418
nixpkgs,
19+
crane,
1520
flake-utils,
16-
rust-overlay,
21+
fenix,
1722
...
1823
}:
1924
flake-utils.lib.eachDefaultSystem (
2025
system:
2126
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;
3055
pname = "iamb";
3156
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;
3580
};
36-
nativeBuildInputs = [ pkg-config ];
37-
buildInputs = [ openssl ];
81+
82+
iamb-nextest = craneLib.cargoNextest (commonArgs // {
83+
inherit cargoArtifacts;
84+
partitions = 1;
85+
partitionType = "count";
86+
});
3887
};
3988

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
51101
cargo-tarpaulin
52102
cargo-watch
53103
sqlite

src/notifications.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ async fn send_notification_bell(store: &AsyncProgramStore) {
139139
}
140140

141141
#[cfg(feature = "desktop")]
142+
#[cfg_attr(target_os = "macos", allow(unused_variables))]
142143
async fn send_notification_desktop(
143144
summary: &str,
144145
body: Option<&str>,

0 commit comments

Comments
 (0)