on iko/ghcjs-patch-master help sign in
Add custom errors for some missing attributes (#194)

* Add a custom error message for a missing stack resolver * Make mkCabalProjectPkgSet robust to missing Hackage patches * Add error for component prefix lookup * Add a custom error for a missing GHC

commit9d251db79ad7736c1d3d38e5005f07e5e44e86d4 authorMichael Peyton Jones <michael.peyton-jones@iohk.io> dateThu 4 Jul 2019, 01:09 (7 years ago) parentdd94c83
3 files changed+13−4
default.nix+6−2 lib/default.nix+1−1 modules/hackage.nix+6−1
default.nix+6−2
@@ -88,7 +88,10 @@ let
8888
8989 let
9090 # The Stackage release referenced in the stack config
91− pkg-def = stackage.${stack-pkgs.resolver};
91+ pkg-def = stackage.${stack-pkgs.resolver} or (throw ''
92+ This version of stackage.nix does not know about the Stackage resolver ${stack-pkgs.resolver}.
93+ You may need to update haskell.nix to one that includes a newer stackage.nix.
94+ '');
9295 # The compiler referenced in the stack config
9396 compiler = (stack-pkgs.extras hackage).compiler or (pkg-def hackage).compiler;
9497 patchesModule = ghcHackagePatches.${compiler.nix-name} or {};
@@ -109,10 +112,11 @@ let
109112 pkg-def = plan-pkgs.pkgs;
110113 # The compiler referenced in the stack config
111114 compiler = (plan-pkgs.extras hackage).compiler or (pkg-def hackage).compiler;
115+ patchesModule = ghcHackagePatches.${compiler.nix-name} or {};
112116 in self.mkPkgSet {
113117 inherit pkg-def;
114118 pkg-def-extras = [ plan-pkgs.extras ] ++ pkg-def-extras;
115− modules = [ ghcHackagePatches.${compiler.nix-name} ] ++ modules;
119+ modules = [ patchesModule ] ++ modules;
116120 };
117121
118122 # Package sets for all stackage snapshots.
lib/default.nix+1−1
@@ -43,7 +43,7 @@ with haskellLib;
4343 let
4444 comps = config.components;
4545 applyLibrary = cname: f { cname = config.package.identifier.name; ctype = "lib"; };
46− applySubComp = ctype: cname: f { inherit cname; ctype = componentPrefix.${ctype}; };
46+ applySubComp = ctype: cname: f { inherit cname; ctype = componentPrefix.${ctype} or (throw "Missing component mapping for ${ctype}."); };
4747 applyAllComp = f { cname = config.package.identifier.name; ctype = "all"; };
4848 libComp = if comps.library == null then {} else lib.mapAttrs applyLibrary (removeAttrs comps (subComponentTypes ++ [ "all" ]));
4949 subComps = lib.mapAttrs
modules/hackage.nix+6−1
@@ -66,7 +66,12 @@ in {
6666 # this should allow us to use `config` overrides
6767 # in the nixpkgs setup, and properly override the
6868 # complier as needed.
69− default = pkgs.buildPackages.haskell.compiler.${config.compiler.nix-name};
69+ default = pkgs.buildPackages.haskell.compiler.${config.compiler.nix-name} or (throw ''
70+ This version of Nixpkgs does not contain GHC ${config.compiler.version}
71+ (or it is not present at attribute '${config.compiler.nix-name})').
72+ Either switch to a version of Nixpkgs which does have this version, or use a version
73+ of GHC which the current version of Nixpkgs contains.
74+ '');
7075 defaultText = "pkgs.buildPackages.haskell.compiler.\${config.compiler.nix-name}";
7176 };
7277