Skip to content

Commit e280b39

Browse files
authored
Add stan setting to output static analysis report (#384)
1 parent 760b751 commit e280b39

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- Enhancements
66
- Support `meta.description` in flake apps. Requires newer version of flake-parts.
7+
- `settings` module:
8+
- #384: Add `stan`
79

810
## 0.5.0 (Jun 24, 2024)
911

doc/settings.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,13 @@ Newer versions of [nixpkgs] provide `buildFromSdist` to build your package from
7070
> If you encounter issues with `buildFromSdist` you can disable it by setting `settings.<name>.buildFromSdist` to `true`.
7171
7272
[nixpkgs]: https://nixos.asia/en/nixpkgs
73+
74+
### `stan`
75+
76+
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.
77+
78+
> [!note] stan configuration
79+
> This setting looks for a `.stan.toml` file in the root of the package source. See a sample [.stan.toml] configuration for reference.
80+
81+
[stan]: https://github.com/kowainik/stan
82+
[.stan.toml]: https://github.com/kowainik/stan/blob/main/.stan.toml

nix/modules/project/settings/all.nix

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ name, pkgs, lib, config, log, ... }:
1+
{ name, pkgs, self, lib, config, log, ... }:
22
let
33
inherit (lib) types;
44
inherit (import ./lib.nix {
@@ -347,6 +347,32 @@ in
347347
});
348348
};
349349

350+
stan = {
351+
type = types.bool;
352+
description = ''
353+
Modifies the Haskell package to generate a static analysis report using <https://github.com/kowainik/stan>.
354+
'';
355+
impl = enable: drv:
356+
let
357+
inherit (pkgs.haskell.lib.compose) appendConfigureFlags addBuildTool;
358+
in
359+
if enable then
360+
lib.pipe drv [
361+
(appendConfigureFlags [ "--ghc-options=-fwrite-ide-info" "--ghc-options=-hiedir=.hie" ])
362+
(addBuildTool self.stan)
363+
(drv:
364+
drv.overrideAttrs (old: {
365+
postInstall = (old.postInstall or "") + ''
366+
echo "Generating stan.html"
367+
cd $out
368+
stan report --hiedir $OLDPWD --config-file $OLDPWD/.stan.toml
369+
echo "Finished generating stan.html"
370+
'';
371+
}))
372+
]
373+
else drv;
374+
};
375+
350376
# When none of the above settings is suitable:
351377
custom = {
352378
type = types.functionTo types.package;

test/simple/flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
jailbreak = true;
5252
cabalFlags.blah = true;
5353
};
54+
# Test STatic ANalysis report generation
55+
haskell-flake-test.stan = true;
5456
};
5557
devShell = {
5658
tools = hp: {

0 commit comments

Comments
 (0)