1{ pkgs, haskellPackages }:
2
3let
4 # This can be regenerated by running `cabal2nix .` in the current directory.
5 pkgDef =
6 { mkDerivation, base, lib }:
7 mkDerivation {
8 pname = "haskell-setBuildTarget";
9 version = "0.1.0.0";
10 src = ./.;
11 isLibrary = false;
12 isExecutable = true;
13 executableHaskellDepends = [ base ];
14 license = lib.licenses.bsd3;
15 };
16
17 drv = haskellPackages.callPackage pkgDef {};
18
19 test = target: excluded:
20 let only = pkgs.haskell.lib.compose.setBuildTarget target drv;
21 in ''
22 if [[ ! -f "${only}/bin/${target}" ]]; then
23 echo "${target} was not built"
24 exit 1
25 fi
26
27 if [[ -f "${only}/bin/${excluded}" ]]; then
28 echo "${excluded} was built, when it should not have been"
29 exit 1
30 fi
31 '';
32
33in
34pkgs.runCommand "test haskell.lib.compose.setBuildTarget" {
35 meta = {
36 inherit (drv.meta) platforms;
37 };
38} ''
39 ${test "foo" "bar"}
40 ${test "bar" "foo"}
41 touch "$out"
42''
43