|
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 = ''Whether to enable a flake check to verify if HLS works (equivalent of `nix develop -i -c haskell-language-server`).''; |
| 79 | + default = true; |
| 80 | + }; |
76 | 81 | }; |
77 | 82 | }); |
78 | 83 | }; |
|
81 | 86 | config = { |
82 | 87 | perSystem = { config, self', inputs', pkgs, ... }: |
83 | 88 | 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 | + ''; |
84 | 107 | projects = |
85 | 108 | lib.mapAttrs |
86 | | - (_key: cfg: |
| 109 | + (projectKey: cfg: |
87 | 110 | let |
88 | 111 | inherit (pkgs.lib.lists) optionals; |
89 | 112 | hp = cfg.haskellPackages; |
|
94 | 117 | ghcid |
95 | 118 | hlint; |
96 | 119 | }; |
97 | | - buildTools = lib.attrValues (defaultBuildTools // cfg.buildTools hp); |
| 120 | + buildTools' = defaultBuildTools // cfg.buildTools hp; |
| 121 | + buildTools = lib.attrValues buildTools'; |
98 | 122 | mkProject = { returnShellEnv ? false, withHoogle ? false }: |
99 | 123 | hp.developPackage { |
100 | 124 | inherit returnShellEnv withHoogle; |
|
109 | 133 | package = mkProject { }; |
110 | 134 | app = { type = "app"; program = pkgs.lib.getExe package; }; |
111 | 135 | 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 | + }; |
112 | 147 | } |
113 | 148 | ) |
114 | 149 | config.haskellProjects; |
|
122 | 157 | lib.mapAttrs |
123 | 158 | (_: project: project.app) |
124 | 159 | projects; |
| 160 | + checks = |
| 161 | + lib.mkMerge |
| 162 | + (lib.mapAttrsToList |
| 163 | + (_: project: project.checks) |
| 164 | + projects); |
125 | 165 | devShells = |
126 | 166 | lib.mapAttrs |
127 | 167 | (_: project: project.devShell) |
|
0 commit comments