···464464 installPhase = ''
465465 runHook preInstall
466466467467- ${if !isLibrary then "${setupCommand} install" else ''
467467+ ${if !isLibrary && buildTarget == "" then "${setupCommand} install"
468468+ # ^^ if the project is not a library, and no build target is specified, we can just use "install".
469469+ else if !isLibrary then "${setupCommand} copy ${buildTarget}"
470470+ # ^^ if the project is not a library, and we have a build target, then use "copy" to install
471471+ # just the target specified; "install" will error here, since not all targets have been built.
472472+ else ''
468473 ${setupCommand} copy
469474 local packageConfDir="$out/lib/${ghc.name}/package.conf.d"
470475 local packageConfFile="$packageConfDir/${pname}-${version}.conf"
+10
pkgs/development/haskell-modules/lib.nix
···196196 appendPatch = drv: x: appendPatches drv [x];
197197 appendPatches = drv: xs: overrideCabal drv (drv: { patches = (drv.patches or []) ++ xs; });
198198199199+ /* Set a specific build target instead of compiling all targets in the package.
200200+ * For example, imagine we have a .cabal file with a library, and 2 executables "dev" and "server".
201201+ * We can build only "server" and not wait on the compilation of "dev" by useing setBuildTarget as follows:
202202+ *
203203+ * setBuildTarget (callCabal2nix "thePackageName" thePackageSrc {}) "server"
204204+ *
205205+ */
206206+ setBuildTargets = drv: xs: overrideCabal drv (drv: { buildTarget = lib.concatStringsSep " " xs; });
207207+ setBuildTarget = drv: x: setBuildTargets drv [x];
208208+199209 doHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = true; });
200210 dontHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = false; });
201211
···11+{ pkgs, haskellPackages }: with pkgs.haskell.lib;
22+33+44+let
55+ drv = haskellPackages.callCabal2nix "haskell-setBuildTarget" ./. {};
66+ test = target: excluded:
77+88+ let only = setBuildTarget drv target;
99+ in ''
1010+ if [[ ! -f "${only}/bin/${target}" ]]; then
1111+ echo "${target} was not built"
1212+ exit 1
1313+ fi
1414+1515+ if [[ -f "${only}/bin/${excluded}" ]]; then
1616+ echo "${excluded} was built, when it should not have been"
1717+ exit 1
1818+ fi
1919+ '';
2020+2121+in pkgs.runCommand "test haskell.lib.setBuildTarget" {} ''
2222+ ${test "foo" "bar"}
2323+ ${test "bar" "foo"}
2424+ touch "$out"
2525+''
2626+