From b75e33f6c8f9b76fe4fc671e32ba30b4dd12b593 Mon Sep 17 00:00:00 2001 From: jappeace-sloth Date: Thu, 11 Jun 2026 15:59:49 +0200 Subject: [PATCH] Add nix/ci.nix and enforce hlint in CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI was calling 'nix-build' (== default.nix), which only produces the cabal build derivation; .hlint.yaml was a sample file with no enforcement, so projects derived from this template silently drifted away from their lint configuration. Introduces 'nix/ci.nix' with two attrs: - native: imports default.nix, so 'nix-build nix/ci.nix' still produces the cabal build derivation - hlint: runs 'hlint -h .hlint.yaml app src test' inside a 'pkgs.runCommand' derivation, pinning the hlint binary to the same nixpkgs as the rest of the toolchain The GitHub Actions 'nix' job is updated to 'nix-build nix/ci.nix' so the hlint pass runs alongside the build instead of needing a separate workflow step. The cabal-only matrix job is unchanged — it doesn't have nix available. Mirrors the same pattern used in jappeace/mijn-webwinkel-migraine's nix/ci.nix. Prompt: add the same idea to haskell-template-project. we want hlint enabled in ci.nix Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/ci.yaml | 2 +- nix/ci.nix | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 nix/ci.nix diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c1482e5..ec4f834 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,7 +24,7 @@ jobs: with: primary-key: nix-${{ hashFiles('npins/sources.json', 'nix/*.nix', '*.cabal') }} restore-prefixes-first-match: nix- - - run: nix-build + - run: nix-build nix/ci.nix - run: nix-shell --run "echo OK" - run: nix-shell --run "cabal build" - name: Cancel workflow on failure diff --git a/nix/ci.nix b/nix/ci.nix new file mode 100644 index 0000000..0899a31 --- /dev/null +++ b/nix/ci.nix @@ -0,0 +1,37 @@ +{ sources ? import ../npins +, pkgs ? import ./pkgs.nix { inherit sources; } +, hpkgs ? import ./hpkgs.nix { inherit pkgs; } +, +}: +let + # The fileset filter on ../nix/hpkgs.nix already keeps the haskell + # build from being invalidated by edits to .hlint.yaml, so we can + # safely use the wider tree here without thrashing the cabal cache. + src = builtins.path { + path = ../.; + name = "template-project-src"; + filter = path: _type: + let base = baseNameOf (toString path); + in !(builtins.elem base [ "dist-newstyle" "dist" "result" ".git" ]); + }; +in +{ + # The cabal build / library / executable derivation — what + # 'nix-build' has always built. Kept here so CI builds the project + # /and/ the hlint pass with a single 'nix-build nix/ci.nix' rather + # than two separate invocations. + native = import ../default.nix { inherit hpkgs; }; + + # Enforce .hlint.yaml across app/src/test as part of CI. Treating + # hlint as a derivation lets the same 'nix-build nix/ci.nix' run + # locally and in GitHub Actions, and keeps the hlint version pinned + # to the same nixpkgs as the rest of the toolchain. + hlint = pkgs.runCommand "ci-hlint" + { + nativeBuildInputs = [ pkgs.hlint ]; + } '' + cd ${src} + hlint -h .hlint.yaml app src test + touch $out + ''; +}