diff --git a/.config/nextest.toml b/.config/nextest.toml new file mode 100644 index 0000000..0bda379 --- /dev/null +++ b/.config/nextest.toml @@ -0,0 +1,13 @@ +# https://nexte.st/book/configuration.html + +[profile.ci] +# Print out output for failing tests as soon as they fail, and also at the end +# of the run (for easy scrollability). +failure-output = "immediate-final" +# Do not cancel the test run on the first failure. +fail-fast = false +# The Garnix CI builders run in some weird virtual filesystem that messes with +# `notify`. Even with sleeps before writing and poll-based notifications, +# sometimes `notify` misses events (this is rare, maybe 1 in 50 test runs). +# Retry tests if they fail in CI to mitigate this. +retries = 3 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index bc0bc44..0000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- -# This is the main CI workflow, run for PRs and on `main`. - -on: - push: - branches: - - main - - pull_request: - types: - - opened - - synchronize - - reopened - -name: Continuous integration - -jobs: - checks: - name: Checks - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: cachix/install-nix-action@v22 - with: - extra_nix_config: | - access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} - nix_path: nixpkgs=channel:nixos-unstable - - - name: Log versions - run: | - nix --version - - - name: Check Nix flake - run: nix --extra-experimental-features 'nix-command flakes' flake check --print-build-logs diff --git a/.github/workflows/get-crate-version.sh b/.github/workflows/get-crate-version.sh deleted file mode 100755 index 3024491..0000000 --- a/.github/workflows/get-crate-version.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Gets the version of `nix-your-shell` in `Cargo.toml` using -# `cargo metadata` and `jq`. - -VERSION=$(cargo metadata --format-version 1 \ - | jq -r '.packages[] | select(.name == "nix-your-shell") | .version') - -echo "Version in \`Cargo.toml\` is $VERSION" 1>&2 - -if [[ -z "$VERSION" ]]; then - echo "I wasn't able to determine the version in \`Cargo.toml\` with \`cargo metadata\`" - exit 1 -fi - -echo "$VERSION" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 6427f30..ab6b552 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,7 +3,7 @@ # Run when PRs to main are closed. on: - pull_request: + pull_request_target: types: - closed branches: @@ -24,7 +24,7 @@ jobs: steps: - run: | echo "This is a canonical hack to run GitHub Actions on merged PRs" - echo "See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-workflow-when-a-pull-request-merges" + echo "See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-pull_request-workflow-when-a-pull-request-merges" - name: Comment on PR with link to this action uses: peter-evans/create-or-update-comment@v2 @@ -45,16 +45,16 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Install rustup - uses: dtolnay/rust-toolchain@stable - - - name: Install jq - run: sudo apt install -y jq + - uses: cachix/install-nix-action@v22 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + extra_nix_config: | + extra-experimental-features = nix-command flakes + accept-flake-config = true - name: Get version number id: get_cargo_metadata - run: | - echo "version=$(./.github/workflows/get-crate-version.sh)" >> "$GITHUB_OUTPUT" + run: echo "version=$(nix run .#get-crate-version)" >> "$GITHUB_OUTPUT" build: name: Release Build @@ -67,75 +67,24 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest] steps: - name: Checkout code uses: actions/checkout@v3 - - name: Install rustup - uses: dtolnay/rust-toolchain@stable - if: runner.os == 'macOS' - with: - target: x86_64-apple-darwin, aarch64-apple-darwin - - - name: Install rustup - uses: dtolnay/rust-toolchain@stable - if: runner.os == 'Linux' - with: - target: x86_64-unknown-linux-musl, aarch64-unknown-linux-musl - - - name: Log versions - run: which -a rustup && rustup --version - - - name: Test - run: cargo test - - - name: Build (macOS, x86_64) - if: runner.os == 'macOS' - run: cargo build --release --target x86_64-apple-darwin - - - name: Build (macOS, aarch64) - if: runner.os == 'macOS' - run: cargo build --release --target aarch64-apple-darwin - - - name: Build (Linux, x86_64) - if: runner.os == 'Linux' - run: cargo build --release --target x86_64-unknown-linux-musl - - - name: Create macOS universal executable and codesign it - if: runner.os == 'macOS' - run: | - lipo -create -output target/release/nix-your-shell-macos \ - target/x86_64-apple-darwin/release/nix-your-shell \ - target/aarch64-apple-darwin/release/nix-your-shell - - - name: Rename executables for upload - if: runner.os == 'Linux' - run: | - mkdir -p target/release - mv target/x86_64-unknown-linux-musl/release/nix-your-shell \ - target/release/nix-your-shell-x86_64-linux - - - name: Upload macOS executable - uses: actions/upload-artifact@v3 - if: runner.os == 'macOS' - with: - name: macos - path: target/release/nix-your-shell-macos - - - name: Upload Linux x86_64 executable - uses: actions/upload-artifact@v3 - if: runner.os == 'Linux' + - uses: cachix/install-nix-action@v22 with: - name: linux-x86_64 - path: target/release/nix-your-shell-x86_64-linux + github_access_token: ${{ secrets.GITHUB_TOKEN }} + extra_nix_config: | + extra-experimental-features = nix-command flakes + accept-flake-config = true - name: Publish to crates.io if: runner.os == 'Linux' env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} run: | - cargo publish + nix run .#pkgs.x86_64-linux.cargo -- publish --no-verify upload: name: Upload assets to release @@ -180,9 +129,6 @@ jobs: prerelease: false generate_release_notes: true tag_name: v${{ needs.version.outputs.version }} - files: | - macos/nix-your-shell-macos - linux-x86_64/nix-your-shell-x86_64-linux - name: Comment on PR with link to the release uses: peter-evans/create-or-update-comment@v2 diff --git a/.github/workflows/version.yaml b/.github/workflows/version.yaml index 866f0aa..8fb0364 100644 --- a/.github/workflows/version.yaml +++ b/.github/workflows/version.yaml @@ -9,13 +9,13 @@ # and update the `REPO_GITHUB_TOKEN` secret to a new, valid token. on: - pull_request: + pull_request_target: types: - closed branches: - main -name: Update versions and release +name: Update versions and create release PR jobs: # We make `if_merged` a `needs:` of the other jobs here to only run this @@ -31,7 +31,7 @@ jobs: steps: - run: | echo "This is a canonical hack to run GitHub Actions on merged PRs" - echo "See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-workflow-when-a-pull-request-merges" + echo "See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-pull_request-workflow-when-a-pull-request-merges" bump_type: name: Determine version bump type @@ -56,7 +56,7 @@ jobs: fi version: - name: Update and tag version numbers + name: Bump version and create release PR permissions: pull-requests: write needs: @@ -70,42 +70,23 @@ jobs: # Fetch all history/tags (needed to compute versions) fetch-depth: 0 - - name: Install rustup - uses: dtolnay/rust-toolchain@stable - - - name: Download and install `cargo-release` - run: | - set -v - pushd "$(mktemp -d)" - curl -L -o cargo-release.tar.gz \ - https://github.com/crate-ci/cargo-release/releases/download/v0.21.1/cargo-release-v0.21.1-x86_64-unknown-linux-gnu.tar.gz - tar -xvf cargo-release.tar.gz - install -d ~/.local/bin - install cargo-release ~/.local/bin - echo "$HOME/.local/bin" >> "$GITHUB_PATH" - popd - ~/.local/bin/cargo-release release --version + - uses: cachix/install-nix-action@v22 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + extra_nix_config: | + extra-experimental-features = nix-command flakes + accept-flake-config = true - name: Get old version number id: old_cargo_metadata - run: | - echo "version=$(./.github/workflows/get-crate-version.sh)" >> "$GITHUB_OUTPUT" + run: echo "version=$(nix run .#get-crate-version)" >> "$GITHUB_OUTPUT" - name: Increment `Cargo.toml` version - # `cargo-release` changes the version numbers in `Cargo.toml` and - # `Cargo.lock` and commits the changes. - run: | - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - cargo-release release \ - --execute \ - --no-confirm \ - ${{ needs.bump_type.outputs.bump_type }} + run: nix run .#make-release-commit -- ${{ needs.bump_type.outputs.bump_type }} - name: Get new version number id: new_cargo_metadata - run: | - echo "version=$(./.github/workflows/get-crate-version.sh)" >> "$GITHUB_OUTPUT" + run: echo "version=$(nix run .#get-crate-version)" >> "$GITHUB_OUTPUT" - name: Create release PR id: release_pr @@ -128,7 +109,7 @@ jobs: labels: release - name: Comment on PR with link to release PR - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v3 with: issue-number: ${{ github.event.pull_request.number }} body: | diff --git a/flake.lock b/flake.lock index e107a1a..3f17333 100644 --- a/flake.lock +++ b/flake.lock @@ -1,102 +1,48 @@ { "nodes": { - "alejandra": { - "inputs": { - "fenix": "fenix", - "flakeCompat": "flakeCompat", - "nixpkgs": "nixpkgs" - }, + "advisory-db": { + "flake": false, "locked": { - "lastModified": 1694541876, - "narHash": "sha256-lStDIPizbJipd1JpNKX1olBKzyIosyC2U/mVFwJPcZE=", - "owner": "kamadorueda", - "repo": "alejandra", - "rev": "e53c2c6c6c103dc3f848dbd9fbd93ee7c69c109f", + "lastModified": 1710515894, + "narHash": "sha256-tmQ9TMCb2jZY3jYdf53qIberkYV3dnUzdAYYK/NB+No=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "369d98c1b95b7b56d0859605916d7b81a7d1f1c4", "type": "github" }, "original": { - "owner": "kamadorueda", - "repo": "alejandra", + "owner": "rustsec", + "repo": "advisory-db", "type": "github" } }, - "fenix": { + "crane": { "inputs": { "nixpkgs": [ - "alejandra", "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1668234453, - "narHash": "sha256-FmuZThToBvRsqCauYJ3l8HJoGLAY5cMULeYEKIaGrRw=", - "owner": "nix-community", - "repo": "fenix", - "rev": "8f219f6b36e8d0d56afa7f67e6e3df63ef013cdb", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "fenix", - "type": "github" - } - }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", - "type": "github" + ] }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flakeCompat": { - "flake": false, "locked": { - "lastModified": 1650374568, - "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "lastModified": 1710819233, + "narHash": "sha256-YJsu2BVgUl2qRo0t2ksu5rK4yD59Mudd6BUXGwpC0DE=", + "owner": "ipetkov", + "repo": "crane", + "rev": "fc610a825db14bd8fdc5c7f57450422ae6ff4e7a", "type": "github" }, "original": { - "owner": "edolstra", - "repo": "flake-compat", + "owner": "ipetkov", + "repo": "crane", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1668226844, - "narHash": "sha256-G/S4FBWDAqHeBS/hfXwUCJbnaKnrQFoeeKwzvZEOgxM=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "dd4767bf613bf9553eee6ff37c0996b9c876e7d8", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable-small", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1675982352, - "narHash": "sha256-jtx492OH5xAa6V8kwLJ/+uIQDltF0sELjR22exubL88=", + "lastModified": 1710878323, + "narHash": "sha256-7VU9h+E2JNcfUABPaHrn5qOG+0gAb+6geuZDv32YdPg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "275d807773b07e481b711ec98eb13bb8ea925ad7", + "rev": "fd6871114e5d296456c8483c279dfd4a3f34e25f", "type": "github" }, "original": { @@ -107,29 +53,12 @@ }, "root": { "inputs": { - "alejandra": "alejandra", - "flake-compat": "flake-compat", - "nixpkgs": "nixpkgs_2", + "advisory-db": "advisory-db", + "crane": "crane", + "nixpkgs": "nixpkgs", "systems": "systems" } }, - "rust-analyzer-src": { - "flake": false, - "locked": { - "lastModified": 1668182250, - "narHash": "sha256-PYGaOCiFvnJdVz+ZCaKF8geGdffXjJUNcMwaBHv0FT4=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "45ec315e01dc8dd1146dfeb65f0ef6e5c2efed78", - "type": "github" - }, - "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", - "type": "github" - } - }, "systems": { "locked": { "lastModified": 1681028828, diff --git a/flake.nix b/flake.nix index c2f0b06..07b5572 100644 --- a/flake.nix +++ b/flake.nix @@ -3,111 +3,71 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs"; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; systems.url = "github:nix-systems/default"; - flake-compat = { - url = "github:edolstra/flake-compat"; + advisory-db = { + url = "github:rustsec/advisory-db"; flake = false; }; - alejandra.url = "github:kamadorueda/alejandra"; }; - outputs = { + nixConfig = { + extra-substituters = ["https://cache.garnix.io"]; + extra-trusted-substituters = ["https://cache.garnix.io"]; + extra-trusted-public-keys = ["cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g="]; + }; + + outputs = inputs @ { self, nixpkgs, systems, - alejandra, ... }: let inherit (nixpkgs) lib; - eachSystem = fn: - lib.genAttrs (import systems) (system: let - pkgs = import nixpkgs { - localSystem = system; - overlays = [self.overlays.default]; - }; - in - fn pkgs system); + makePkgs = system: + import nixpkgs { + localSystem = system; + }; + eachSystem = fn: lib.genAttrs (import systems) fn; in { - packages = eachSystem (pkgs: system: { - nix-your-shell = pkgs.nix-your-shell; - default = self.packages.${system}.nix-your-shell; - }); + pkgs = eachSystem (system: makePkgs system); - checks = eachSystem (pkgs: system: - self.packages.${system} + localPkgs = eachSystem (system: self.pkgs.${system}.callPackage ./nix/makePackages.nix {inherit inputs;}); + + packages = eachSystem (system: let + localPkgs = self.localPkgs.${system}; + in + (lib.filterAttrs (_name: lib.isDerivation) localPkgs) // { - check-formatting = pkgs.stdenvNoCC.mkDerivation { - name = "check-formatting"; - src = ./.; - phases = ["checkPhase" "installPhase"]; - doCheck = true; - nativeCheckInputs = [ - pkgs.cargo - pkgs.rustfmt - alejandra.packages.${system}.default + default = localPkgs.nix-your-shell; + + nix-your-shell-from-overlay = let + overlayed = self.pkgs.${system}.appendOverlays [ + self.overlays.default ]; - checkPhase = '' - cd $src - echo 'Checking Nix code formatting with Alejandra:' - alejandra --check . - echo 'Checking Rust code formatting with `cargo fmt`:' - cargo fmt --check - ''; - installPhase = "touch $out"; - }; + in + overlayed.nix-your-shell; }); - # for debugging - # inherit pkgs; + checks = eachSystem ( + system: + builtins.removeAttrs + self.localPkgs.${system}.checks + # Ugh. + ["override" "overrideDerivation"] + ); - devShells = eachSystem (pkgs: system: { - default = pkgs.nix-your-shell.overrideAttrs (old: { - # Make rust-analyzer work - RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; - - # Any dev tools you use in excess of the rust ones - nativeBuildInputs = old.nativeBuildInputs; - }); + devShells = eachSystem (system: { + default = self.localPkgs.${system}.nix-your-shell.devShell; }); - overlays.default = final: prev: { - nix-your-shell = let - manifest = lib.importTOML ./Cargo.toml; - in - final.rustPlatform.buildRustPackage { - pname = manifest.package.name; - inherit (manifest.package) version; - - cargoLock = {lockFile = ./Cargo.lock;}; - - src = ./.; - - # Tools on the builder machine needed to build; e.g. pkg-config - nativeBuildInputs = [final.rustfmt final.clippy]; - - # Native libs - buildInputs = []; - - preCheck = '' - cargo check --frozen - cargo clippy -- --deny warnings - ''; - - passthru.generate-config = shell: - final.runCommand "nix-your-shell-config" {} '' - ${final.nix-your-shell}/bin/nix-your-shell ${shell} >> $out - ''; - - meta = { - inherit (manifest.package) description homepage; - license = lib.licenses.mit; - maintainers = [lib.maintainers._9999years]; - platforms = import systems; - mainProgram = manifest.package.name; - }; - }; + overlays.default = final: prev: let + localPkgs = prev.callPackage ./nix/makePackages.nix {inherit inputs;}; + in { + inherit (localPkgs) nix-your-shell; }; - - formatter = eachSystem (_: system: alejandra.packages.${system}.default); }; } diff --git a/garnix.yaml b/garnix.yaml new file mode 100644 index 0000000..179782f --- /dev/null +++ b/garnix.yaml @@ -0,0 +1,10 @@ +--- +# See: https://garnix.io/docs/yaml_config +builds: + include: + - devShells.x86_64-linux.default + - devShells.aarch64-darwin.default + - 'packages.x86_64-linux.*' + - 'packages.aarch64-darwin.*' + - 'checks.x86_64-linux.*' + - 'checks.aarch64-darwin.*' diff --git a/nix/makePackages.nix b/nix/makePackages.nix new file mode 100644 index 0000000..45defc6 --- /dev/null +++ b/nix/makePackages.nix @@ -0,0 +1,13 @@ +{ + lib, + newScope, + inputs, +}: +lib.makeScope newScope ( + self: + {inherit inputs;} + // (lib.packagesFromDirectoryRecursive { + inherit (self) callPackage; + directory = ./packages; + }) +) diff --git a/nix/packages/checks.nix b/nix/packages/checks.nix new file mode 100644 index 0000000..0bc1f93 --- /dev/null +++ b/nix/packages/checks.nix @@ -0,0 +1,7 @@ +{ + make-checks, + nix-your-shell, +}: +make-checks [ + nix-your-shell +] diff --git a/nix/packages/crane-lib.nix b/nix/packages/crane-lib.nix new file mode 100644 index 0000000..11d8962 --- /dev/null +++ b/nix/packages/crane-lib.nix @@ -0,0 +1,5 @@ +{ + inputs, + pkgs, +}: +inputs.crane.mkLib pkgs diff --git a/nix/packages/get-crate-version.nix b/nix/packages/get-crate-version.nix new file mode 100644 index 0000000..7a9af24 --- /dev/null +++ b/nix/packages/get-crate-version.nix @@ -0,0 +1,30 @@ +{ + writeShellApplication, + cargo, + jq, +}: +writeShellApplication { + name = "get-crate-version"; + + runtimeInputs = [ + cargo + jq + ]; + + text = '' + # Gets the version of `nix-your-shell` in `Cargo.toml` using + # `cargo metadata` and `jq`. + + VERSION=$(cargo metadata --format-version 1 \ + | jq -r '.packages[] | select(.name == "nix-your-shell") | .version') + + echo "Version in \`Cargo.toml\` is $VERSION" 1>&2 + + if [[ -z "$VERSION" ]]; then + echo "I wasn't able to determine the version in \`Cargo.toml\` with \`cargo metadata\`" + exit 1 + fi + + echo "$VERSION" + ''; +} diff --git a/nix/packages/make-checks.nix b/nix/packages/make-checks.nix new file mode 100644 index 0000000..2f18818 --- /dev/null +++ b/nix/packages/make-checks.nix @@ -0,0 +1,19 @@ +{lib}: pkgs: +lib.pipe pkgs [ + (builtins.map ( + pkg: + lib.pipe pkg.checks [ + builtins.attrValues + (builtins.map + ( + check: + lib.nameValuePair + # The Nix CLI doesn't like attribute names that contain dots. + (builtins.replaceStrings ["."] ["-"] check.name) + check + )) + ] + )) + lib.flatten + builtins.listToAttrs +] diff --git a/nix/packages/make-release-commit.nix b/nix/packages/make-release-commit.nix new file mode 100644 index 0000000..cafb739 --- /dev/null +++ b/nix/packages/make-release-commit.nix @@ -0,0 +1,29 @@ +{ + writeShellApplication, + cargo, + cargo-release, + gitAndTools, +}: +writeShellApplication { + name = "make-release-commit"; + + runtimeInputs = [ + cargo + cargo-release + gitAndTools.git + ]; + + text = '' + if [[ -n "''${CI:-}" ]]; then + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + fi + + cargo release --version + + cargo release \ + --execute \ + --no-confirm \ + "$@" + ''; +} diff --git a/nix/packages/nix-your-shell.nix b/nix/packages/nix-your-shell.nix new file mode 100644 index 0000000..34b46c3 --- /dev/null +++ b/nix/packages/nix-your-shell.nix @@ -0,0 +1,98 @@ +{ + lib, + stdenv, + libiconv, + darwin, + crane-lib, + inputs, + rustPlatform, + rust-analyzer, +}: let + src = lib.cleanSourceWith { + src = crane-lib.path ../../.; + # Keep template/test data. + filter = path: type: + lib.hasInfix "/data" path + || (crane-lib.filterCargoSources path type); + }; + cargoToml = lib.importTOML ../../Cargo.toml; + + commonArgs' = { + inherit src; + inherit (cargoToml.package) version; + pname = cargoToml.package.name; + + nativeBuildInputs = lib.optionals stdenv.isDarwin [ + libiconv + darwin.apple_sdk.frameworks.CoreServices + ]; + }; + + # Build *just* the cargo dependencies, so we can reuse + # all of that work (e.g. via cachix) when running in CI + cargoArtifacts = crane-lib.buildDepsOnly commonArgs'; + + commonArgs = + commonArgs' + // { + inherit cargoArtifacts; + }; + + checks = { + tests = crane-lib.cargoNextest (commonArgs + // { + NEXTEST_PROFILE = "ci"; + NEXTEST_HIDE_PROGRESS_BAR = "true"; + }); + clippy = crane-lib.cargoClippy (commonArgs + // { + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + doc = crane-lib.cargoDoc (commonArgs + // { + cargoDocExtraArgs = "--document-private-items"; + RUSTDOCFLAGS = "-D warnings"; + }); + fmt = crane-lib.cargoFmt commonArgs; + audit = crane-lib.cargoAudit (commonArgs + // { + inherit (inputs) advisory-db; + }); + }; + + devShell = crane-lib.devShell { + inherit checks; + + # Make rust-analyzer work + RUST_SRC_PATH = rustPlatform.rustLibSrc; + + # Extra development tools (cargo and rustc are included by default). + packages = [ + rust-analyzer + ]; + }; +in + # Build the actual crate itself, reusing the dependency + # artifacts from above. + crane-lib.buildPackage (commonArgs + // { + # Don't run tests; we'll do that in a separate derivation. + # This will allow people to install and depend on `ghciwatch` + # without downloading a half dozen different versions of GHC. + doCheck = false; + + # Only build `ghciwatch`, not the test macros. + cargoBuildCommand = "cargoWithProfile build"; + + passthru = { + inherit checks devShell; + }; + + meta = { + inherit (cargoToml.package) description homepage; + license = lib.licenses.mit; + maintainers = [lib.maintainers._9999years]; + platforms = import inputs.systems; + mainProgram = cargoToml.package.name; + }; + })