Skip to content

Commit d381b5a

Browse files
Try #1060:
2 parents 43cb0fc + cd884a6 commit d381b5a

File tree

13 files changed

+151
-54
lines changed

13 files changed

+151
-54
lines changed

ci.nix

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ dimension "Nixpkgs version" nixpkgsVersions (nixpkgsName: nixpkgs-pin:
8080
} // pkgs.lib.optionalAttrs runTests {
8181
inherit (build) tests tools maintainer-scripts maintainer-script-cache;
8282
} // pkgs.lib.optionalAttrs (ifdLevel >= 1) {
83-
iserv-proxy = pkgs.ghc-extra-packages."${compiler-nix-name}".iserv-proxy.components.exes.iserv-proxy;
83+
iserv-proxy = pkgs.ghc-extra-projects."${compiler-nix-name}".getComponent "iserv-proxy:exe:iserv-proxy";
8484
} // pkgs.lib.optionalAttrs (ifdLevel >= 3) {
85-
hello = (pkgs.haskell-nix.hackage-package { name = "hello"; version = "1.0.0.2"; inherit compiler-nix-name; }).components.exes.hello;
85+
hello = (pkgs.haskell-nix.hackage-package { name = "hello"; version = "1.0.0.2"; inherit compiler-nix-name; }).getComponent "exe:hello";
8686
});
8787
}
8888
//
@@ -102,10 +102,10 @@ dimension "Nixpkgs version" nixpkgsVersions (nixpkgsName: nixpkgs-pin:
102102
inherit (build) tests;
103103
}) // pkgs.lib.optionalAttrs (ifdLevel >= 2 && crossSystemName != "ghcjs") {
104104
# GHCJS builds its own template haskell runner.
105-
remote-iserv = pkgs.ghc-extra-packages."${compiler-nix-name}".remote-iserv.components.exes.remote-iserv;
106-
iserv-proxy = pkgs.ghc-extra-packages."${compiler-nix-name}".iserv-proxy.components.exes.iserv-proxy;
105+
remote-iserv = pkgs.ghc-extra-projects."${compiler-nix-name}".getComponent "remote-iserv:exe:remote-iserv";
106+
iserv-proxy = pkgs.ghc-extra-projects."${compiler-nix-name}".getComponent "iserv-proxy:exe:iserv-proxy";
107107
} // pkgs.lib.optionalAttrs (ifdLevel >= 3) {
108-
hello = (pkgs.haskell-nix.hackage-package { name = "hello"; version = "1.0.0.2"; inherit compiler-nix-name; }).components.exes.hello;
108+
hello = (pkgs.haskell-nix.hackage-package { name = "hello"; version = "1.0.0.2"; inherit compiler-nix-name; }).getComponent "exe:hello";
109109
})
110110
))
111111
)

compiler/ghcjs/ghcjs.nix

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ let
2424
all-ghcjs = pkgs.buildPackages.symlinkJoin {
2525
name = "ghcjs-${ghcjsVersion}-symlinked";
2626
paths = [
27-
ghcjs.components.exes.ghcjs
28-
ghcjs.components.exes.ghcjs-pkg
29-
ghcjs.components.exes.ghcjs-boot
30-
ghcjs.components.exes.ghcjs-dumparchive
27+
(ghcjs.getComponent "exe:ghcjs")
28+
(ghcjs.getComponent "exe:ghcjs-pkg")
29+
(ghcjs.getComponent "exe:ghcjs-boot")
30+
(ghcjs.getComponent "exe:ghcjs-dumparchive")
3131
] ++ (if isGhcjs88
3232
then [
33-
ghcjs.components.exes.haddock
34-
ghcjs.components.exes.private-ghcjs-run
35-
ghcjs.components.exes.private-ghcjs-unlit
36-
ghcjs.components.exes.private-ghcjs-hsc2hs
33+
(ghcjs.getComponent "exe:haddock")
34+
(ghcjs.getComponent "exe:private-ghcjs-run")
35+
(ghcjs.getComponent "exe:private-ghcjs-unlit")
36+
(ghcjs.getComponent "exe:private-ghcjs-hsc2hs")
3737
]
3838
else [
39-
ghcjs.components.exes.haddock-ghcjs
40-
ghcjs.components.exes.hsc2hs-ghcjs
41-
ghcjs.components.exes.ghcjs-run
39+
(ghcjs.getComponent "exe:haddock-ghcjs")
40+
(ghcjs.getComponent "exe:hsc2hs-ghcjs")
41+
(ghcjs.getComponent "exe:ghcjs-run")
4242
]);
4343
};
4444
libexec = "libexec/${builtins.replaceStrings ["darwin" "i686"] ["osx" "i386"] pkgs.stdenv.buildPlatform.system}-${ghc.name}/ghcjs-${ghcVersion}";
@@ -68,9 +68,9 @@ let
6868
lndir ${all-ghcjs}/bin $out/bin
6969
chmod -R +w $out/bin
7070
rm $out/bin/ghcjs-boot
71-
cp ${ghcjs.components.exes.ghcjs-boot}/bin/ghcjs-boot $out/bin
71+
cp ${ghcjs.getComponent "exe:ghcjs-boot"}/bin/ghcjs-boot $out/bin
7272
rm $out/bin/haddock
73-
cp ${ghcjs.components.exes.haddock}/bin/haddock $out/bin
73+
cp ${ghcjs.getComponent "exe:haddock"}/bin/haddock $out/bin
7474
7575
wrapProgram $out/bin/ghcjs --add-flags "-B$out/lib"
7676
wrapProgram $out/bin/haddock --add-flags "-B$out/lib"

lib/call-cabal-project-to-nix.nix

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,10 @@ let
425425
export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
426426
export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
427427
428-
echo "Using index-state ${index-state-found}"
429-
HOME=${
428+
mkdir -p $out
429+
430+
echo "Using index-state ${index-state-found}" | tee -a cabal-configure.out
431+
if (HOME=${
430432
# This creates `.cabal` directory that is as it would have
431433
# been at the time `cached-index-state`. We may include
432434
# some packages that will be excluded by `index-state-found`
@@ -451,9 +453,7 @@ let
451453
--enable-benchmarks \
452454
${pkgs.lib.optionalString (ghc.targetPrefix == "js-unknown-ghcjs-")
453455
"--ghcjs --with-ghcjs=js-unknown-ghcjs-ghc --with-ghcjs-pkg=js-unknown-ghcjs-ghc-pkg"} \
454-
${configureArgs}
455-
456-
mkdir -p $out
456+
${configureArgs} 2>&1 | tee -a cabal-configure.out); then
457457
458458
# ensure we have all our .cabal files (also those generated from package.yaml) files.
459459
# otherwise we'd need to be careful about putting the `cabal-generator = hpack` into
@@ -491,6 +491,16 @@ let
491491
492492
# move pkgs.nix to default.nix ensure we can just nix `import` the result.
493493
mv $out${subDir'}/pkgs.nix $out${subDir'}/default.nix
494+
else
495+
# When cabal configure fails copy the output that we captured above and
496+
# use `failed-cabal-configure.nix` to make a suitable derviation with.
497+
cp cabal-configure.out $out
498+
cp ${./failed-cabal-configure.nix} $out/default.nix
499+
500+
# Theere is not much we can do here for JSON, but this output is only used
501+
# for diagnosing issues (so a human readable error should be ok).
502+
echo "Cabal configure failed see $out/cabal-configure.out for details" > $json
503+
fi
494504
'');
495505
in {
496506
projectNix = plan-nix;

lib/default.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ in {
6262
benchmarks = "bench";
6363
};
6464

65+
# For looking up the components attribute based on the cabal component type
66+
prefixComponent =
67+
lib.listToAttrs (
68+
lib.mapAttrsToList (value: name: { inherit name value; })
69+
componentPrefix);
70+
6571
applyComponents = f: config:
6672
let
6773
comps = config.components;

lib/failed-cabal-configure.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let
2+
configurationError = ./cabal-configure.out;
3+
in
4+
# Trace the error output to make sure the user has a chance to see it
5+
# (even if the choose not to build anything from the project)
6+
__trace ''
7+
ERROR: cabal configure failed with:
8+
${__readFile configurationError}
9+
'' { inherit configurationError; }

overlays/bootstrap.nix

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ in {
581581
cabal-install = final.evalPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name};
582582
nix-tools = final.evalPackages.haskell-nix.nix-tools-unchecked.${compiler-nix-name};
583583
materialized = ../materialized + "/${compiler-nix-name}/cabal-install";
584-
} // args)).components.exes.cabal;
584+
} // args)).getComponent "exe:cabal";
585585
nix-tools-set = { compiler-nix-name, ... }@args:
586586
let
587587
project =
@@ -617,7 +617,22 @@ in {
617617
];
618618
}];
619619
} // args);
620-
exes = project.nix-tools.components.exes // project.hpack.components.exes;
620+
exes =
621+
let
622+
package = project.getPackage "nix-tools";
623+
in (builtins.map (name: package.getComponent "exe:${name}") [
624+
"cabal-to-nix"
625+
"hashes-to-nix"
626+
"plan-to-nix"
627+
"hackage-to-nix"
628+
"lts-to-nix"
629+
"stack-to-nix"
630+
"truncate-index"
631+
"stack-repos"
632+
"cabal-name"
633+
]) ++ [
634+
(project.getComponent "hpack:exe:hpack")
635+
];
621636
tools = [
622637
final.buildPackages.nix
623638
# Double buildPackages is intentional, see comment in lib/default.nix for details.
@@ -626,7 +641,7 @@ in {
626641
in
627642
final.symlinkJoin {
628643
name = "nix-tools";
629-
paths = builtins.attrValues exes;
644+
paths = exes;
630645
buildInputs = [ final.makeWrapper ];
631646
meta.platforms = final.lib.platforms.all;
632647
# We wrap the -to-nix executables with the executables from `tools` (e.g. nix-prefetch-git)
@@ -774,7 +789,7 @@ in {
774789
version = "1.24.4";
775790
inherit ghcOverride nix-tools cabal-install index-state;
776791
materialized = ../materialized/bootstrap + "/${buildBootstrapper.compilerNixName}/hscolour";
777-
} // args)).components.exes.HsColour;
792+
} // args)).getComponent "exe:HsColour";
778793
hscolour = bootstrap.packages.hscolour-tool {};
779794
hscolour-unchecked = bootstrap.packages.hscolour-tool { checkMaterialization = false; };
780795
};

overlays/haskell.nix

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ final: prev: {
457457
hackage-package =
458458
{ name, compiler-nix-name, ... }@args':
459459
let args = { caller = "hackage-package"; } // args';
460-
in (hackage-project args).hsPkgs.${name};
460+
in (hackage-project args).getPackage name;
461461
hackage-project =
462462
{ name
463463
, compiler-nix-name
@@ -500,11 +500,19 @@ final: prev: {
500500
let
501501
args = { caller = "cabalProject'"; } // args';
502502
callProjectResults = callCabalProjectToNix args;
503-
in let pkg-set = mkCabalProjectPkgSet
504-
{ inherit compiler-nix-name;
505-
plan-pkgs = importAndFilterProject {
506-
inherit (callProjectResults) projectNix sourceRepos src;
503+
plan-pkgs = importAndFilterProject {
504+
inherit (callProjectResults) projectNix sourceRepos src;
505+
};
506+
pkg-set = if plan-pkgs ? configurationError
507+
then {
508+
inherit (plan-pkgs) configurationError;
509+
config = {
510+
compiler.nix-name = compiler-nix-name;
511+
hsPkgs = {};
507512
};
513+
}
514+
else mkCabalProjectPkgSet
515+
{ inherit compiler-nix-name plan-pkgs;
508516
pkg-def-extras = args.pkg-def-extras or [];
509517
modules = (args.modules or [])
510518
++ final.lib.optional (args ? ghcOverride || args ? ghc)
@@ -514,7 +522,7 @@ final: prev: {
514522
extra-hackages = args.extra-hackages or [];
515523
};
516524

517-
project = addProjectAndPackageAttrs rec {
525+
project = addProjectAndPackageAttrs rec {
518526
inherit (pkg-set.config) hsPkgs;
519527
inherit pkg-set;
520528
plan-nix = callProjectResults.projectNix;
@@ -535,7 +543,7 @@ final: prev: {
535543
final.lib.fix (project':
536544
let project = project' // { recurseForDerivations = false; };
537545
in rawProject // rec {
538-
hsPkgs = final.lib.mapAttrs (n: package':
546+
hsPkgs = final.lib.mapAttrs (packageName: package':
539547
if package' == null
540548
then null
541549
else
@@ -548,6 +556,16 @@ final: prev: {
548556
) package'.components;
549557
inherit project;
550558

559+
# Look up a component in the package based on ctype:name
560+
getComponent = componentName:
561+
let m = builtins.match "(lib|flib|exe|test|bench):([^:]*)" componentName;
562+
in
563+
assert final.lib.asserts.assertMsg (m != null)
564+
"Invalid package component name ${componentName}. Expected it to start with one of lib: flib: exe: test: or bench:";
565+
if builtins.elemAt m 0 == "lib" && builtins.elemAt m 1 == packageName
566+
then components.library
567+
else components.${haskellLib.prefixComponent.${builtins.elemAt m 0}}.${builtins.elemAt m 1};
568+
551569
coverageReport = haskellLib.coverageReport (rec {
552570
name = package.identifier.name + "-" + package.identifier.version;
553571
library = if components ? library then components.library else null;
@@ -568,6 +586,48 @@ final: prev: {
568586
rawProject.projectFunction pkgs.haskell-nix rawProject.projectArgs
569587
) final.pkgsCross) // { recurseForDerivations = false; };
570588

589+
# Like `.hsPkgs.${packageName}` but when compined with `getComponent` any
590+
# cabal configure errors are defered until the components derivation builds.
591+
getPackage = packageName:
592+
if rawProject.pkg-set ? configurationError
593+
then
594+
# A minimal proxy for a package when cabal configure failed
595+
let package = {
596+
# Including the project so that things like:
597+
# (p.getPackage "hello").project.tool "hlint" "latest"
598+
# will still work even if "hello" failed to configure.
599+
inherit project;
600+
601+
# Defer configure time errors for the library component
602+
# (p.getPackage "hello").components.library
603+
components.library = package.getComponent "lib:${packageName}";
604+
605+
# This procide a derivation (even though the component may
606+
# not exist at all). The derivation will never build
607+
# and simple outputs the result of cabal configure.
608+
getComponent = componentName:
609+
final.evalPackages.runCommand "cabal-configure-error" {
610+
passthru = {
611+
inherit project package;
612+
};
613+
} ''
614+
cat ${rawProject.pkg-set.configurationError}
615+
echo Unable to find component ${packageName}:${componentName} \
616+
due to the above cabal configuration error
617+
exit 1
618+
'';
619+
};
620+
in package
621+
else project.hsPkgs.${packageName};
622+
623+
# Look a component in the project based on `pkg:ctype:name`
624+
getComponent = componentName:
625+
let m = builtins.match "([^:]*):(lib|flib|exe|test|bench):([^:]*)" componentName;
626+
in
627+
assert final.lib.asserts.assertMsg (m != null)
628+
"Invalid package component name ${componentName}. Expected package:ctype:component (where ctype is one of lib, flib, exe, test, or bench)";
629+
(getPackage (builtins.elemAt m 0)).getComponent "${builtins.elemAt m 1}:${builtins.elemAt m 2}";
630+
571631
# Helper function that can be used to make a Nix Flake out of a project
572632
# by including a flake.nix. See docs/tutorials/getting-started-flakes.md
573633
# for an example flake.nix file.

overlays/tools.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ in { haskell-nix = prev.haskell-nix // {
6666
{ configureArgs = "--disable-benchmarks --disable-tests"; }
6767
// args
6868
// { name = final.haskell-nix.toolPackageName.${name} or name; }))
69-
.components.exes."${final.haskell-nix.packageToolName.${name} or name}";
69+
.getComponent "exe:${final.haskell-nix.packageToolName.${name} or name}";
7070

7171
tool = compiler-nix-name: name: versionOrArgs:
7272
let

scripts/check-compiler-materialization/default.nix

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
let
55
eval = (import ../../. {}).pkgs;
66
linux = (import ../../. { checkMaterialization = true; system = "x86_64-linux"; }).pkgs;
7-
darwin = (import ../../. { checkMaterialization = true; system = "x86_64-darwin"; }).pkgs;
7+
darwin = (import ../../. { checkMaterialization = true; system = "x86_64-darwin"; }).pkgs-unstable;
88
in eval.linkFarm "check-${compiler-nix-name}" [
99
# This set of derivations should be enough to ensure all the materialized files for a
1010
# given GHC version are checked.
11-
{ name = "linux-cabal-install"; path = linux.haskell-nix.cabal-install.${compiler-nix-name}; }
12-
# { name = "darwin-cabal-install"; path = darwin.haskell-nix.cabal-install.${compiler-nix-name}; }
13-
{ name = "linux-nix-tools"; path = linux.haskell-nix.nix-tools.${compiler-nix-name}; }
14-
{ name = "linux"; path = linux.ghc-extra-projects.${compiler-nix-name}.plan-nix; }
11+
# { name = "linux-cabal-install"; path = linux.haskell-nix.cabal-install.${compiler-nix-name}; }
12+
{ name = "darwin-cabal-install"; path = darwin.haskell-nix.cabal-install.${compiler-nix-name}; }
13+
# { name = "linux-nix-tools"; path = linux.haskell-nix.nix-tools.${compiler-nix-name}; }
14+
# { name = "linux"; path = linux.ghc-extra-projects.${compiler-nix-name}.plan-nix; }
1515
# In some cased you may need comment out one or more of these if the GHC version needed cannot be built.
16-
{ name = "musl"; path = linux.pkgsCross.musl64.ghc-extra-projects.${compiler-nix-name}.plan-nix; }
17-
{ name = "windows"; path = linux.pkgsCross.mingwW64.ghc-extra-projects.${compiler-nix-name}.plan-nix; }
18-
{ name = "arm"; path = linux.pkgsCross.aarch64-multiplatform.ghc-extra-projects.${compiler-nix-name}.plan-nix; }
16+
# { name = "musl"; path = linux.pkgsCross.musl64.ghc-extra-projects.${compiler-nix-name}.plan-nix; }
17+
# { name = "windows"; path = linux.pkgsCross.mingwW64.ghc-extra-projects.${compiler-nix-name}.plan-nix; }
18+
# { name = "arm"; path = linux.pkgsCross.aarch64-multiplatform.ghc-extra-projects.${compiler-nix-name}.plan-nix; }
1919
]
2020

test/cabal-simple-prof/default.nix

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ let
2121
inherit modules;
2222
};
2323

24-
packages = project.hsPkgs;
25-
2624
in recurseIntoAttrs {
2725
ifdInputs = {
2826
inherit (project) plan-nix;
@@ -31,7 +29,7 @@ in recurseIntoAttrs {
3129
name = "cabal-simple-prof-test";
3230

3331
buildCommand = ''
34-
exe="${packages.cabal-simple.components.exes.cabal-simple.exePath}"
32+
exe="${(project.getComponent "cabal-simple:exe:cabal-simple").exePath}"
3533
3634
size=$(command stat --format '%s' "$exe")
3735
printf "size of executable $exe is $size. \n" >& 2
@@ -41,7 +39,7 @@ in recurseIntoAttrs {
4139
# Curiosity: cross compilers prodcing profiling with `+RTS -p -h` lead to the following cryptic message:
4240
# cabal-simple: invalid heap profile option: -h*
4341
# Hence we pass `-hc`.
44-
${toString packages.cabal-simple.components.exes.cabal-simple.config.testWrapper} $exe +RTS -p -hc
42+
${toString (project.getComponent "cabal-simple:exe:cabal-simple").config.testWrapper} $exe +RTS -p -hc
4543
4644
touch $out
4745
'';
@@ -54,7 +52,7 @@ in recurseIntoAttrs {
5452

5553
passthru = {
5654
# Used for debugging with nix repl
57-
inherit project packages;
55+
inherit project;
5856
};
5957
};
6058
}

test/haskell-language-server/cabal.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ in recurseIntoAttrs {
55
ifdInputs = {
66
inherit (project) plan-nix;
77
};
8-
build = project.hsPkgs.haskell-language-server.components.exes.haskell-language-server;
8+
build = project.getComponent "haskell-language-server:exe:haskell-language-server";
99
}

test/index-state/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ with lib;
66
let
77
# The hackage-security 0.6.0.1 was uploaded at 2020-04-06T20:54:35Z
88
# See https://hackage.haskell.org/package/hackage-security-0.6.0.1
9-
version-used-at = index-state: (tool compiler-nix-name "cabal" {
9+
version-used-at = index-state: ((tool compiler-nix-name "cabal" {
1010
version = "3.2.0.0";
1111
inherit index-state;
1212
cabalProject = ''
@@ -15,7 +15,7 @@ let
1515
package cabal-install
1616
flags: -native-dns
1717
'';
18-
}).project.hsPkgs.hackage-security.components.library.version;
18+
}).project.getPackage "hackage-security").components.library.version;
1919
version-before = version-used-at "2020-04-06T20:54:34Z";
2020
version-after = version-used-at "2020-04-06T20:54:35Z";
2121

0 commit comments

Comments
 (0)