Skip to content

Commit ec8e55a

Browse files
authored
Add HLS check (#20)
1 parent 1ca2be3 commit ec8e55a

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

flake-module.nix

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ 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 = ''Whether to enable a flake check to verify if HLS works (equivalent of `nix develop -i -c haskell-language-server`).'';
79+
default = true;
80+
};
7681
};
7782
});
7883
};
@@ -81,9 +86,27 @@ in
8186
config = {
8287
perSystem = { config, self', inputs', pkgs, ... }:
8388
let
89+
# Like pkgs.runCommand but runs inside nix-shell with a mutable project directory.
90+
#
91+
# It currenty respects only the nativeBuildInputs (and no shellHook for
92+
# instance), which seems sufficient for our purposes. We also set $HOME and
93+
# make the project root mutable, because those are expected when running
94+
# something in a project shell (it is indeed the case with HLS).
95+
runCommandInSimulatedShell = devShell: projectRoot: name: attrs: command:
96+
pkgs.runCommand name (attrs // { nativeBuildInputs = devShell.nativeBuildInputs; })
97+
''
98+
# Copy project root to a mutable area
99+
# We expect "command" to mutate it.
100+
export HOME=$TMP
101+
cp -R ${projectRoot} $HOME/project
102+
chmod -R a+w $HOME/project
103+
pushd $HOME/project
104+
105+
${command}
106+
'';
84107
projects =
85108
lib.mapAttrs
86-
(_key: cfg:
109+
(projectKey: cfg:
87110
let
88111
inherit (pkgs.lib.lists) optionals;
89112
hp = cfg.haskellPackages;
@@ -94,7 +117,8 @@ in
94117
ghcid
95118
hlint;
96119
};
97-
buildTools = lib.attrValues (defaultBuildTools // cfg.buildTools hp);
120+
buildTools' = defaultBuildTools // cfg.buildTools hp;
121+
buildTools = lib.attrValues buildTools';
98122
mkProject = { returnShellEnv ? false, withHoogle ? false }:
99123
hp.developPackage {
100124
inherit returnShellEnv withHoogle;
@@ -109,6 +133,17 @@ in
109133
package = mkProject { };
110134
app = { type = "app"; program = pkgs.lib.getExe package; };
111135
devShell = mkProject { returnShellEnv = true; withHoogle = true; };
136+
checks =
137+
lib.optionalAttrs cfg.enableHLSCheck {
138+
"${projectKey}-hls" =
139+
runCommandInSimulatedShell
140+
devShell
141+
cfg.root "${projectKey}-hls-check"
142+
{ }
143+
''
144+
haskell-language-server > $out
145+
'';
146+
};
112147
}
113148
)
114149
config.haskellProjects;
@@ -122,6 +157,11 @@ in
122157
lib.mapAttrs
123158
(_: project: project.app)
124159
projects;
160+
checks =
161+
lib.mkMerge
162+
(lib.mapAttrsToList
163+
(_: project: project.checks)
164+
projects);
125165
devShells =
126166
lib.mapAttrs
127167
(_: project: project.devShell)

0 commit comments

Comments
 (0)