|
73 | 73 | default = hp: { }; |
74 | 74 | defaultText = ''Build tools useful for Haskell development are included by default.''; |
75 | 75 | }; |
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. |
80 | 83 | |
81 | | - This is equivalent to `nix develop -i -c haskell-language-server`. |
| 84 | + This is equivalent to `nix develop -i -c haskell-language-server`. |
82 | 85 |
|
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 | + }; |
89 | 112 | }; |
90 | 113 | }; |
91 | 114 | }); |
|
104 | 127 | runCommandInSimulatedShell = devShell: projectRoot: name: attrs: command: |
105 | 128 | pkgs.runCommand name (attrs // { nativeBuildInputs = devShell.nativeBuildInputs; }) |
106 | 129 | '' |
| 130 | + # Set pipefail option for safer bash |
| 131 | + set -euo pipefail |
| 132 | +
|
107 | 133 | # Copy project root to a mutable area |
108 | 134 | # We expect "command" to mutate it. |
109 | 135 | export HOME=$TMP |
|
112 | 138 | pushd $HOME/project |
113 | 139 |
|
114 | 140 | ${command} |
| 141 | + touch $out |
115 | 142 | ''; |
116 | 143 | projects = |
117 | 144 | lib.mapAttrs |
|
133 | 160 | }; |
134 | 161 | buildTools = lib.attrValues (defaultBuildTools hp // cfg.buildTools hp); |
135 | 162 | 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; |
136 | 167 | in |
137 | 168 | rec { |
138 | | - inherit package; |
| 169 | + inherit package devShell; |
139 | 170 | 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 | + { |
144 | 173 | "${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} |
149 | 181 | '' |
150 | | - haskell-language-server > $out |
151 | | - ''; |
| 182 | + else null; |
152 | 183 | }; |
153 | 184 | } |
154 | 185 | ) |
|
0 commit comments