From 444a9fd8f22a2c7d2252668cfe2968de55e8b9e5 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Mon, 5 Dec 2022 10:27:12 -0800 Subject: [PATCH] Nix flake checks now do ci-checks (#88) * Nix flake checks now do ci-checks * Make sure checks actually run --- .github/workflows/ci.yml | 8 ++++---- flake.nix | 44 +++++++++++++++++++++++++--------------- nix/check.nix | 44 ++++++++++++++++++++++++++++++++++++++++ nix/ci.nix | 39 ----------------------------------- 4 files changed, 76 insertions(+), 59 deletions(-) create mode 100644 nix/check.nix delete mode 100644 nix/ci.nix diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ded4c35..2e48f04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,13 +22,13 @@ jobs: path: ~/.ci-store key: lint-store-x86_64-linux-${{ hashFiles('**/Cargo.lock', '**/flake.lock') }}-v1 - name: Check rustfmt - run: nix develop --store ~/.ci-store --command ci-check-rustfmt + run: nix develop --store ~/.ci-store --command check-rustfmt - name: Check Spelling - run: nix develop --store ~/.ci-store --command ci-check-spelling + run: nix develop --store ~/.ci-store --command check-spelling - name: Check nixpkgs-fmt formatting - run: nix develop --store ~/.ci-store --command ci-check-nixpkgs-fmt + run: nix develop --store ~/.ci-store --command check-nixpkgs-fmt - name: Check EditorConfig conformance - run: nix develop --store ~/.ci-store --command ci-check-editorconfig + run: nix develop --store ~/.ci-store --command check-editorconfig build-x86_64-linux: name: Build x86_64 Linux diff --git a/flake.nix b/flake.nix index 990e01c..8625543 100644 --- a/flake.nix +++ b/flake.nix @@ -50,15 +50,8 @@ devShells = forAllSystems ({ system, pkgs, ... }: let toolchain = fenixToolchain system; - ci = import ./nix/ci.nix { inherit pkgs; }; eclint = import ./nix/eclint.nix { inherit pkgs; }; - - spellcheck = pkgs.writeScriptBin "spellcheck" '' - ${pkgs.codespell}/bin/codespell \ - --ignore-words-list crate,pullrequest,pullrequests,ser \ - --skip target \ - . - ''; + check = import ./nix/check.nix { inherit pkgs eclint toolchain; }; in { default = pkgs.mkShell { @@ -82,8 +75,11 @@ git nixpkgs-fmt eclint + check.check-rustfmt + check.check-spelling + check.check-nixpkgs-fmt + check.check-editorconfig ] - ++ ci ++ lib.optionals (pkgs.stdenv.isDarwin) (with pkgs; [ libiconv darwin.apple_sdk.frameworks.Security ]); }; }); @@ -93,14 +89,30 @@ pkgs = import nixpkgs { inherit system; }; + toolchain = fenixToolchain system; + eclint = import ./nix/eclint.nix { inherit pkgs; }; + check = import ./nix/check.nix { inherit pkgs eclint toolchain; }; in { - format = pkgs.runCommand "check-format" - { - buildInputs = with pkgs; [ rustfmt cargo ]; - } '' - ${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt --check ${./.} - touch $out # it worked! + check-rustfmt = pkgs.runCommand "check-rustfmt" { buildInputs = [ check.check-rustfmt ]; } '' + cd ${./.} + check-rustfmt + touch $out + ''; + check-spelling = pkgs.runCommand "check-spelling" { buildInputs = [ check.check-spelling ]; } '' + cd ${./.} + check-spelling + touch $out + ''; + check-nixpkgs-fmt = pkgs.runCommand "check-nixpkgs-fmt" { buildInputs = [ check.check-nixpkgs-fmt ]; } '' + cd ${./.} + check-nixpkgs-fmt + touch $out + ''; + check-editorconfig = pkgs.runCommand "check-editorconfig" { buildInputs = [ pkgs.git check.check-editorconfig ]; } '' + cd ${./.} + check-editorconfig + touch $out ''; }); @@ -130,7 +142,7 @@ doDoc = true; doDocFail = true; RUSTFLAGS = "--cfg tracing_unstable --cfg tokio_unstable"; - cargoTestOptions = f: f ++ ["--all"]; + cargoTestOptions = f: f ++ [ "--all" ]; override = { preBuild ? "", ... }: { preBuild = preBuild + '' diff --git a/nix/check.nix b/nix/check.nix new file mode 100644 index 0000000..e2a7255 --- /dev/null +++ b/nix/check.nix @@ -0,0 +1,44 @@ +{ pkgs, eclint, toolchain }: + +let + inherit (pkgs) writeShellApplication; +in +{ + + # Format + check-rustfmt = (writeShellApplication { + name = "check-rustfmt"; + runtimeInputs = [ toolchain ]; + text = "cargo fmt --check"; + }); + + # Spelling + check-spelling = (writeShellApplication { + name = "check-spelling"; + runtimeInputs = with pkgs; [ git codespell ]; + text = '' + codespell \ + --ignore-words-list ba,sur,crate,pullrequest,pullrequests,ser \ + --skip target \ + . + ''; + }); + + # NixFormatting + check-nixpkgs-fmt = (writeShellApplication { + name = "check-nixpkgs-fmt"; + runtimeInputs = with pkgs; [ git nixpkgs-fmt findutils ]; + text = '' + nixpkgs-fmt --check . + ''; + }); + + # EditorConfig + check-editorconfig = (writeShellApplication { + name = "check-editorconfig"; + runtimeInputs = with pkgs; [ eclint ]; + text = '' + eclint . + ''; + }); +} diff --git a/nix/ci.nix b/nix/ci.nix deleted file mode 100644 index 6bb6b2f..0000000 --- a/nix/ci.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ pkgs }: - -let - inherit (pkgs) writeScriptBin; -in -[ - - # Format - (writeScriptBin "ci-check-rustfmt" "cargo fmt --check") - - # Test - (writeScriptBin "ci-test-rust" "cargo test") - - # Spelling - (writeScriptBin "ci-check-spelling" '' - codespell \ - --ignore-words-list ba,sur,crate,pullrequest,pullrequests,ser \ - --skip target \ - . - '') - - # NixFormatting - (writeScriptBin "ci-check-nixpkgs-fmt" '' - git ls-files '*.nix' | xargs | nixpkgs-fmt --check - '') - - # EditorConfig - (writeScriptBin "ci-check-editorconfig" '' - eclint - '') - - (writeScriptBin "ci-all" '' - ci-check-rustfmt - ci-test-rust - ci-check-spelling - ci-check-nixpkgs-fmt - ci-check-editorconfig - '') -]