Skip to content

Commit

Permalink
[Chore] Add weeder check
Browse files Browse the repository at this point in the history
Problem: We want to be able to check our Haskell applications for dead
code. This can be done using weeder.

Solution: Use weeder check from serokell.nix.
  • Loading branch information
Sereja313 committed Oct 1, 2024
1 parent 2162cdf commit 8c2b5a3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion haskell.nix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Haskell application and library templates for Buildkite, Gitlab or GitHub CI usi

3. If you're using `hpack` or `stack2cabal` in your project, make sure to uncomment the related lines in both `flake.nix` and pipeline configuration files. To avoid version mismatches, use `nix develop .#ci -c hpack` or `nix develop .#ci -c stack2cabal`.

4. Make sure to clean up your `flake.nix` and pipeline configuration files by removing any optional code that is left commented out.
4. You might want to add a [`weeder`](https://github.com/ocharles/weeder/) check to check for dead code in your application. To do this uncomment the related lines in both `flake.nix` (do not forget to uncomment `writeHieFiles = true;`) and pipeline configuration files, then copy `weeder.toml` (for more advanced setup, please refer to the [corresponding section](https://github.com/ocharles/weeder/?tab=readme-ov-file#calling-weederUsually) of the `weeder` README) to your repository. For a library, code is usually considered dead unless it is exported; such cases are already detected by GHC warnings, so no `weeder` is required.

5. Make sure to clean up your `flake.nix` and pipeline configuration files by removing any optional code that is left commented out.

- Enjoy working CI!

Expand Down
4 changes: 4 additions & 0 deletions haskell.nix/application/.github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ jobs:
# run: nix build -L .#checks.x86_64-linux.hpack
# if: success() || failure()

# - name: check-weeder
# run: nix build -L .#checks.x86_64-linux.weeder
# if: success() || failure()

build:
runs-on: [self-hosted, nix]
steps:
Expand Down
5 changes: 5 additions & 0 deletions haskell.nix/application/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ check-trailing-whitespace:
# script:
# - nix build -L .#checks.x86_64-linux.hpack

# check-weeder:
# stage: validate
# script:
# - nix build -L .#checks.x86_64-linux.weeder

# build haskell components
build-all:
stage: build
Expand Down
8 changes: 8 additions & 0 deletions haskell.nix/application/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
stackage = {
flake = false;
};
serokell-nix.inputs.haskell-nix.follows = "haskell-nix";
};

outputs = { self, nixpkgs, haskell-nix, hackage, stackage, serokell-nix, flake-compat, flake-utils, ... }:
Expand All @@ -43,6 +44,8 @@
# haskell.nix configuration
modules = [
(serokell-nix.lib.haskell.optionsLocalPackages {
# Uncomment if your project uses weeder check
# writeHieFiles = true;
ghcOptions = [
# fail on warnings
"-Werror"
Expand Down Expand Up @@ -91,6 +94,11 @@
# cabal-check = pkgs.build.haskell.cabal-check ./.;
# Uncomment if your project uses hpack to generate cabal files
# hpack = pkgs.build.haskell.hpack ./.;
# Uncomment to check for dead code
# weeder = pkgs.build.haskell.weeder {
# weederToml = ./weeder.toml;
# inherit hs-pkgs;
# };
};
});
}
1 change: 1 addition & 0 deletions haskell.nix/application/weeder.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
roots = [ "^Main.main$", "^Paths_.*" ]

0 comments on commit 8c2b5a3

Please sign in to comment.