query
On this page

checkUnusedPackages

pkgs.haskell.lib.checkUnusedPackages

Docs pulled from | This Revision | about 1 hour ago


Add a post-build check to verify that dependencies declared in the cabal file are actually used.

The first attrset argument can be used to configure the strictness of this check and a list of ignored package names that would otherwise cause false alarms.


Noogle detected

Implementation

The following is the current implementation of this function.

checkUnusedPackages =
    {
      ignoreEmptyImports ? false,
      ignoreMainModule ? false,
      ignorePackages ? [ ],
    }:
    drv:
    overrideCabal (_drv: {
      postBuild =
        let
          args = lib.concatStringsSep " " (
            lib.optional ignoreEmptyImports "--ignore-empty-imports"
            ++ lib.optional ignoreMainModule "--ignore-main-module"
            ++ map (pkg: "--ignore-package ${pkg}") ignorePackages
          );
        in
        "${pkgs.haskellPackages.packunused}/bin/packunused" + lib.optionalString (args != "") " ${args}";
    }) (appendConfigureFlag "--ghc-option=-ddump-minimal-imports" drv);