Skip to content

Commit

Permalink
Add stan setting to output static analysis report (srid#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaraj-bh authored Dec 17, 2024
1 parent 760b751 commit e280b39
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions doc/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<name>.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
28 changes: 27 additions & 1 deletion nix/modules/project/settings/all.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ name, pkgs, lib, config, log, ... }:
{ name, pkgs, self, lib, config, log, ... }:
let
inherit (lib) types;
inherit (import ./lib.nix {
Expand Down Expand Up @@ -347,6 +347,32 @@ in
});
};

stan = {
type = types.bool;
description = ''
Modifies the Haskell package to generate a static analysis report using <https://github.com/kowainik/stan>.
'';
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;
Expand Down
2 changes: 2 additions & 0 deletions test/simple/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
jailbreak = true;
cabalFlags.blah = true;
};
# Test STatic ANalysis report generation
haskell-flake-test.stan = true;
};
devShell = {
tools = hp: {
Expand Down

0 comments on commit e280b39

Please sign in to comment.