Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stan setting to output static analysis report #384

Merged
merged 8 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of hardcoding here. I guess we could eliminate this by making the stan setting a submodule (providing an option to configure custom configuration path) instead of just a boolean, but I doubt that’s necessary.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed these instructions and added .stan.toml to the root:

juspay/vira@53a42bf

However, it doesn't seem to be used, because the generated report still doesn't exclude the StrictData suggestion:

image

It'd be good to demonstrate this in a sample repo, like https://github.com/srid/haskell-template - along with .stan.toml.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


[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