on iko/ghcjs-patch-master help sign in
mkStackPkgSet: filter out $locals package (#393)

I found that if I added this to my stack.yaml: ghc-options: $locals: -ddump-to-file -ddump-hi As specified in https://docs.haskellstack.org/en/stable/yaml_configuration/#ghc-options Then my build would fail to evaluate with: error: The option `packages."\$locals".package.identifier.name' is used but not defined. So to fix it, we filter out these special package globs in mkStackPkgSet. This commit also adds a regression test for that configuration option.

commitd7d24fde4b5c0ebcd704e96aba79e2a148583af7 authorRodney Lorrimar <rodney.lorrimar@iohk.io> dateThu 9 Jan 2020, 16:07 (7 years ago) parent81a6da3
3 files changed+15−3
overlays/haskell.nix+6−1 test/ghc-options/stack.nix+7−2 test/ghc-options/stack.yaml+2
overlays/haskell.nix+6−1
@@ -105,6 +105,11 @@ self: super: {
105105 # The compiler referenced in the stack config
106106 compiler = (stack-pkgs.extras hackage).compiler or (pkg-def hackage).compiler;
107107 patchesModule = ghcHackagePatches.${compiler.nix-name} or {};
108+ # Remove fake packages generated from stack keywords used in ghc-options
109+ removeStackSpecial = module: if builtins.typeOf module == "set"
110+ then module // { packages = removeSpecialPackages (module.packages or {}); }
111+ else module;
112+ removeSpecialPackages = ps: removeAttrs ps [ "$locals" "$targets" "$everything" ];
108113 in mkPkgSet {
109114 pkg-def = excludeBootPackages pkg-def;
110115 pkg-def-extras = [ stack-pkgs.extras
@@ -115,7 +120,7 @@ self: super: {
115120 # and we should trust stackage here!
116121 modules = [ { doExactConfig = true; } patchesModule ]
117122 ++ modules
118− ++ stack-pkgs.modules or [];
123+ ++ map removeStackSpecial (stack-pkgs.modules or []);
119124 };
120125
121126 # Create a Haskell package set based on a Cabal configuration.
test/ghc-options/stack.nix+7−2
@@ -8,6 +8,11 @@ let
88 };
99 packages = project.hsPkgs;
1010
11+ # Get the names of all packages. This is a test to see
12+ # whether there is a broken "$locals" package present.
13+ hasIdentifier = p: p != null && p ? identifier;
14+ packageNames = mapAttrsToList (name: p: p.identifier.name) (filterAttrs (name: hasIdentifier) packages);
15+
1116in recurseIntoAttrs {
1217 ifdInputs = {
1318 inherit (project) stack-nix;
@@ -19,7 +24,7 @@ in recurseIntoAttrs {
1924 printf "checking whether executable runs... " >& 2
2025 cat ${haskellLib.check packages.test-ghc-options.components.exes.test-ghc-options-exe}
2126
22− touch $out
27+ echo '${concatStringsSep " " packageNames}' > $out
2328 '';
2429
2530 meta.platforms = platforms.all;
@@ -29,4 +34,4 @@ in recurseIntoAttrs {
2934 inherit project packages;
3035 };
3136 };
32−}
37+}
test/ghc-options/stack.yaml+2
@@ -5,3 +5,5 @@ packages:
55
66ghc-options:
77 test-ghc-options: -DTEST_GHC_OPTION
8+ # See https://github.com/ndmitchell/weeder/issues/53
9+ $locals: -ddump-to-file -ddump-hi