diff --git a/CHANGELOG.md b/CHANGELOG.md index be1701f6..590f9977 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Enhancements - Support `meta.description` in flake apps. Requires newer version of flake-parts. + - `settings` module: + - #384: Add `stan` ## 0.5.0 (Jun 24, 2024) diff --git a/doc/settings.md b/doc/settings.md index 5478c9c6..d9dad650 100644 --- a/doc/settings.md +++ b/doc/settings.md @@ -70,3 +70,13 @@ Newer versions of [nixpkgs] provide `buildFromSdist` to build your package from > If you encounter issues with `buildFromSdist` you can disable it by setting `settings..buildFromSdist` to `true`. [nixpkgs]: https://nixos.asia/en/nixpkgs + +### `stan` + +Run **ST**atic **AN**alysis on the package using [stan] and generate an HTML report. The report is created in the `/nix/store` path alongside your package outputs. + +> [!note] stan configuration +> This setting looks for a `.stan.toml` file in the root of the package source. See a sample [.stan.toml] configuration for reference. + +[stan]: https://github.com/kowainik/stan +[.stan.toml]: https://github.com/kowainik/stan/blob/main/.stan.toml diff --git a/nix/modules/project/settings/all.nix b/nix/modules/project/settings/all.nix index e6730fe1..09943618 100644 --- a/nix/modules/project/settings/all.nix +++ b/nix/modules/project/settings/all.nix @@ -1,4 +1,4 @@ -{ name, pkgs, lib, config, log, ... }: +{ name, pkgs, self, lib, config, log, ... }: let inherit (lib) types; inherit (import ./lib.nix { @@ -347,6 +347,32 @@ in }); }; + stan = { + type = types.bool; + description = '' + Modifies the Haskell package to generate a static analysis report using . + ''; + impl = enable: drv: + let + inherit (pkgs.haskell.lib.compose) appendConfigureFlags addBuildTool; + in + if enable then + lib.pipe drv [ + (appendConfigureFlags [ "--ghc-options=-fwrite-ide-info" "--ghc-options=-hiedir=.hie" ]) + (addBuildTool self.stan) + (drv: + drv.overrideAttrs (old: { + postInstall = (old.postInstall or "") + '' + echo "Generating stan.html" + cd $out + stan report --hiedir $OLDPWD --config-file $OLDPWD/.stan.toml + echo "Finished generating stan.html" + ''; + })) + ] + else drv; + }; + # When none of the above settings is suitable: custom = { type = types.functionTo types.package; diff --git a/test/simple/flake.nix b/test/simple/flake.nix index 25214b21..eacf7b2d 100644 --- a/test/simple/flake.nix +++ b/test/simple/flake.nix @@ -51,6 +51,8 @@ jailbreak = true; cabalFlags.blah = true; }; + # Test STatic ANalysis report generation + haskell-flake-test.stan = true; }; devShell = { tools = hp: {