Skip to content

Commit c584317

Browse files
HariAmoor-professionalsridroberth
authored
Add a check for hlint; rename the HLS check option (#24)
- Add `hlintCheck.enable` option (false by default); adds a flake check to run hlint - Rename `enableHLSCheck` to `hlsCheck.enable` for consistency - Internal: dev shell check no longer redirects to `$out` (instead, it simply touches it). Co-authored-by: Sridhar Ratnakumar <[email protected]> Co-authored-by: Sridhar Ratnakumar <[email protected]> Co-authored-by: Robert Hensing <[email protected]>
1 parent e393451 commit c584317

File tree

1 file changed

+53
-22
lines changed

1 file changed

+53
-22
lines changed

flake-module.nix

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,42 @@ in
7373
default = hp: { };
7474
defaultText = ''Build tools useful for Haskell development are included by default.'';
7575
};
76-
enableHLSCheck = mkOption {
77-
type = types.bool;
78-
description = ''
79-
Whether to enable a flake check to verify that HLS works.
76+
hlsCheck = mkOption {
77+
type = types.submodule {
78+
options = {
79+
enable = mkOption {
80+
type = types.bool;
81+
description = ''
82+
Whether to enable a flake check to verify that HLS works.
8083
81-
This is equivalent to `nix develop -i -c haskell-language-server`.
84+
This is equivalent to `nix develop -i -c haskell-language-server`.
8285
83-
Note that, HLS will try to access the network through Cabal (see
84-
https://github.com/haskell/haskell-language-server/issues/3128),
85-
therefore sandboxing must be disabled when evaluating this
86-
check.
87-
'';
88-
default = false;
86+
Note that, HLS will try to access the network through Cabal (see
87+
https://github.com/haskell/haskell-language-server/issues/3128),
88+
therefore sandboxing must be disabled when evaluating this
89+
check.
90+
'';
91+
default = false;
92+
};
93+
94+
};
95+
};
96+
};
97+
hlintCheck = mkOption {
98+
type = types.submodule {
99+
options = {
100+
enable = mkOption {
101+
type = types.bool;
102+
description = "Whether to add a flake check to run hlint";
103+
default = false;
104+
};
105+
dirs = mkOption {
106+
type = types.listOf types.str;
107+
description = "Relative path strings from `root` to directories that should be checked with hlint";
108+
default = [ "." ];
109+
};
110+
};
111+
};
89112
};
90113
};
91114
});
@@ -104,6 +127,9 @@ in
104127
runCommandInSimulatedShell = devShell: projectRoot: name: attrs: command:
105128
pkgs.runCommand name (attrs // { nativeBuildInputs = devShell.nativeBuildInputs; })
106129
''
130+
# Set pipefail option for safer bash
131+
set -euo pipefail
132+
107133
# Copy project root to a mutable area
108134
# We expect "command" to mutate it.
109135
export HOME=$TMP
@@ -112,6 +138,7 @@ in
112138
pushd $HOME/project
113139
114140
${command}
141+
touch $out
115142
'';
116143
projects =
117144
lib.mapAttrs
@@ -133,22 +160,26 @@ in
133160
};
134161
buildTools = lib.attrValues (defaultBuildTools hp // cfg.buildTools hp);
135162
package = cfg.modifier (hp.callCabal2nixWithOptions cfg.name cfg.root "" { });
163+
devShell = with pkgs.haskell.lib;
164+
(addBuildTools package buildTools).envFunc { withHoogle = true; };
165+
devShellCheck = name: command:
166+
runCommandInSimulatedShell devShell cfg.root "${projectKey}-${name}-check" { } command;
136167
in
137168
rec {
138-
inherit package;
169+
inherit package devShell;
139170
app = { type = "app"; program = pkgs.lib.getExe package; };
140-
devShell = with pkgs.haskell.lib;
141-
(addBuildTools package buildTools).envFunc { withHoogle = true; };
142-
checks =
143-
lib.optionalAttrs cfg.enableHLSCheck {
171+
checks = lib.filterAttrs (_: v: v != null)
172+
{
144173
"${projectKey}-hls" =
145-
runCommandInSimulatedShell
146-
devShell
147-
cfg.root "${projectKey}-hls-check"
148-
{ }
174+
if cfg.hlsCheck.enable then
175+
devShellCheck "hls" "haskell-language-server"
176+
else null;
177+
"${projectKey}-hlint" =
178+
if cfg.hlintCheck.enable then
179+
devShellCheck "hlint" ''
180+
hlint ${lib.concatStringsSep " " cfg.hlintCheck.dirs}
149181
''
150-
haskell-language-server > $out
151-
'';
182+
else null;
152183
};
153184
}
154185
)

0 commit comments

Comments
 (0)