Commit 1ec311590d
1ec311590d136d1978621aba8f55e12203ef0728
parent: 0ddded3b8b
Unregistered key
Benjamin Grosse <ste3ls@gmail.com> · 2025-10-25 22:44 UTC
committer: <noreply@github.com>
Use `cargo crane` in Nix flake and set up cachix action (#539)
Layout: unified · split
.github/workflows/ci.yml
+22
| @@ -45,3 +45,25 @@ jobs: |
| 45 | 45 | reporter: 'github-check' |
| 46 | 46 | - name: Run tests |
| 47 | 47 | 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
+52 −32
| @@ -1,5 +1,41 @@ |
| 1 | 1 | { |
| 2 | 2 | "nodes": { |
| 3 | "crane": { |
| 4 | "locked": { |
| 5 | "lastModified": 1759893430, |
| 6 | "narHash": "sha256-yAy4otLYm9iZ+NtQwTMEbqHwswSFUbhn7x826RR6djw=", |
| 7 | "owner": "ipetkov", |
| 8 | "repo": "crane", |
| 9 | "rev": "1979a2524cb8c801520bd94c38bb3d5692419d93", |
| 10 | "type": "github" |
| 11 | }, |
| 12 | "original": { |
| 13 | "owner": "ipetkov", |
| 14 | "repo": "crane", |
| 15 | "type": "github" |
| 16 | } |
| 17 | }, |
| 18 | "fenix": { |
| 19 | "inputs": { |
| 20 | "nixpkgs": [ |
| 21 | "nixpkgs" |
| 22 | ], |
| 23 | "rust-analyzer-src": "rust-analyzer-src" |
| 24 | }, |
| 25 | "locked": { |
| 26 | "lastModified": 1760510549, |
| 27 | "narHash": "sha256-NP+kmLMm7zSyv4Fufv+eSJXyqjLMUhUfPT6lXRlg/bU=", |
| 28 | "owner": "nix-community", |
| 29 | "repo": "fenix", |
| 30 | "rev": "ef7178cf086f267113b5c48fdeb6e510729c8214", |
| 31 | "type": "github" |
| 32 | }, |
| 33 | "original": { |
| 34 | "owner": "nix-community", |
| 35 | "repo": "fenix", |
| 36 | "type": "github" |
| 37 | } |
| 38 | }, |
| 3 | 39 | "flake-utils": { |
| 4 | 40 | "inputs": { |
| 5 | 41 | "systems": "systems" |
| @@ -20,11 +56,11 @@ |
| 20 | 56 | }, |
| 21 | 57 | "nixpkgs": { |
| 22 | 58 | "locked": { |
| 23 | | "lastModified": 1756542300, |
| 24 | | "narHash": "sha256-tlOn88coG5fzdyqz6R93SQL5Gpq+m/DsWpekNFhqPQk=", |
| 59 | "lastModified": 1760284886, |
| 60 | "narHash": "sha256-TK9Kr0BYBQ/1P5kAsnNQhmWWKgmZXwUQr4ZMjCzWf2c=", |
| 25 | 61 | "owner": "nixos", |
| 26 | 62 | "repo": "nixpkgs", |
| 27 | | "rev": "d7600c775f877cd87b4f5a831c28aa94137377aa", |
| 63 | "rev": "cf3f5c4def3c7b5f1fc012b3d839575dbe552d43", |
| 28 | 64 | "type": "github" |
| 29 | 65 | }, |
| 30 | 66 | "original": { |
| @@ -34,44 +70,28 @@ |
| 34 | 70 | "type": "github" |
| 35 | 71 | } |
| 36 | 72 | }, |
| 37 | | "nixpkgs_2": { |
| 38 | | "locked": { |
| 39 | | "lastModified": 1744536153, |
| 40 | | "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", |
| 41 | | "owner": "NixOS", |
| 42 | | "repo": "nixpkgs", |
| 43 | | "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", |
| 44 | | "type": "github" |
| 45 | | }, |
| 46 | | "original": { |
| 47 | | "owner": "NixOS", |
| 48 | | "ref": "nixpkgs-unstable", |
| 49 | | "repo": "nixpkgs", |
| 50 | | "type": "github" |
| 51 | | } |
| 52 | | }, |
| 53 | 73 | "root": { |
| 54 | 74 | "inputs": { |
| 75 | "crane": "crane", |
| 76 | "fenix": "fenix", |
| 55 | 77 | "flake-utils": "flake-utils", |
| 56 | | "nixpkgs": "nixpkgs", |
| 57 | | "rust-overlay": "rust-overlay" |
| 78 | "nixpkgs": "nixpkgs" |
| 58 | 79 | } |
| 59 | 80 | }, |
| 60 | | "rust-overlay": { |
| 61 | | "inputs": { |
| 62 | | "nixpkgs": "nixpkgs_2" |
| 63 | | }, |
| 81 | "rust-analyzer-src": { |
| 82 | "flake": false, |
| 64 | 83 | "locked": { |
| 65 | | "lastModified": 1756694554, |
| 66 | | "narHash": "sha256-z/Iy4qvcMqzhA2IAAg71Sw4BrMwbBHvCS90ZoPLsnIk=", |
| 67 | | "owner": "oxalica", |
| 68 | | "repo": "rust-overlay", |
| 69 | | "rev": "b29e5365120f344fe7161f14fc9e272fcc41ee56", |
| 84 | "lastModified": 1760457219, |
| 85 | "narHash": "sha256-WJOUGx42hrhmvvYcGkwea+BcJuQJLcns849OnewQqX4=", |
| 86 | "owner": "rust-lang", |
| 87 | "repo": "rust-analyzer", |
| 88 | "rev": "8747cf81540bd1bbbab9ee2702f12c33aa887b46", |
| 70 | 89 | "type": "github" |
| 71 | 90 | }, |
| 72 | 91 | "original": { |
| 73 | | "owner": "oxalica", |
| 74 | | "repo": "rust-overlay", |
| 92 | "owner": "rust-lang", |
| 93 | "ref": "nightly", |
| 94 | "repo": "rust-analyzer", |
| 75 | 95 | "type": "github" |
| 76 | 96 | } |
| 77 | 97 | }, |
flake.nix
+76 −26
| @@ -5,49 +5,99 @@ |
| 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 |
src/notifications.rs
+1
| @@ -139,6 +139,7 @@ async fn send_notification_bell(store: &AsyncProgramStore) { |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | #[cfg(feature = "desktop")] |
| 142 | #[cfg_attr(target_os = "macos", allow(unused_variables))] |
| 142 | 143 | async fn send_notification_desktop( |
| 143 | 144 | summary: &str, |
| 144 | 145 | body: Option<&str>, |