@@ -62,7 +62,13 @@ let
6262 };
6363 stackage = import stackageSrc;
6464
65− packages = self: ({
65+ packages = pkgs: self: (rec {
66+ inherit pkgs; # Make pkgs available (it is the underlying nixpkgs)
67+
68+ # Packages built to run on the build platform, not the host platform
69+ buildPackages = pkgs.buildPackages.lib.makeScope pkgs.buildPackages.newScope
70+ (packages pkgs.buildPackages);
71+
6672 # Utility functions for working with the component builder.
6773 haskellLib = let hl = import ./lib { inherit (pkgs) lib; haskellLib = hl; }; in hl;
6874
@@ -125,17 +131,20 @@ let
125131 haskellPackages = self.snapshots."lts-13.26";
126132
127133 # Programs for generating Nix expressions from Cabal and Stack
128− # files. We need to make sure we build this from the buildPackages,
129− # we never want to actually cross compile nix-tools on it's own.
130− nix-tools = pkgs.buildPackages.callPackage ./nix-tools {
134+ # files. This version of nix-tools may be cross compiled.
135+ # We probably never want to actually cross compile nix-tools on
136+ # it's own.
137+ nix-tools-cross-compiled = pkgs.callPackage ./nix-tools {
131138 inherit fetchExternal cleanSourceHaskell;
132− hpack = pkgs.buildPackages.haskell.lib.justStaticExecutables
133− (pkgs.buildPackages.haskellPackages.hpack);
139+ hpack = pkgs.haskell.lib.justStaticExecutables
140+ (pkgs.haskellPackages.hpack);
134141 inherit (self) mkCabalProjectPkgSet;
135142 };
136−
137− # Function to call stackToNix
138− callStackToNix = self.callPackage ./call-stack-to-nix.nix {};
143+ # While `nix-tools-cross-compiled` may be cross compiled,
144+ # getting it from `buildPackages` we should get
145+ # nix-tools suitable for running on the build system.
146+ nix-tools = buildPackages.nix-tools-cross-compiled;
147+ # TODO perhaps there is a cleaner way to get a suitable nix-tools.
139148
140149 # Snapshots of Hackage and Stackage, converted to Nix expressions,
141150 # regularly updated.
@@ -180,15 +189,22 @@ let
180189
181190 update-index-state-hashes = self.callPackage ./scripts/update-index-state-hashes.nix {};
182191
192+ # Function to call stackToNix
193+ callStackToNix = import ./lib/call-stack-to-nix.nix {
194+ pkgs = buildPackages.pkgs;
195+ inherit (buildPackages.pkgs) runCommand;
196+ inherit (buildPackages) nix-tools;
197+ };
198+
183199 # Takes a haskell src directory runs cabal new-configure and plan-to-nix.
184200 # Resulting nix files are added to nix-plan subdirectory.
185− callCabalProjectToNix = import ./lib/cabalProjectToNix.nix {
201+ callCabalProjectToNix = import ./lib/call-cabal-project-to-nix.nix {
186202 index-state-hashes = import indexStateHashesPath;
187− inherit (self) dotCabal;
188− inherit pkgs;
189− inherit (pkgs) runCommand cabal-install ghc symlinkJoin cacert;
190− inherit (pkgs.haskellPackages) hpack;
191− inherit (self) nix-tools;
203+ inherit (buildPackages) dotCabal;
204+ pkgs = buildPackages.pkgs; # buildPackages;
205+ inherit (buildPackages.pkgs.haskellPackages) hpack;
206+ inherit (buildPackages.pkgs) runCommand cabal-install ghc symlinkJoin cacert;
207+ inherit (buildPackages) nix-tools;
192208 };
193209
194210 # References to the unpacked sources, for caching in a Hydra jobset.
@@ -198,4 +214,4 @@ let
198214 });
199215
200216in
201− pkgs.lib.makeScope pkgs.newScope packages
217+ pkgs.lib.makeScope pkgs.newScope (packages pkgs)