@@ -189,7 +189,7 @@ final: prev: {
189189 hackageTarball = { index-state, sha256, nix-tools ? final.haskell-nix.nix-tools, ... }:
190190 assert sha256 != null;
191191 let at = builtins.replaceStrings [":"] [""] index-state; in
192− { "hackage.haskell.org-at-${at}" = final.evalPackages.fetchurl {
192+ { "hackage.haskell.org-at-${at}" = final.fetchurl {
193193 name = "01-index.tar.gz-at-${at}";
194194 url = "https://hackage.haskell.org/01-index.tar.gz";
195195 downloadToTemp = true;
@@ -211,7 +211,7 @@ final: prev: {
211211 # dotCabalName anyway.
212212 dotCabalName = "dot-cabal-" + allNames;
213213 # This is very big, and cheap to build: prefer building it locally
214− tarballRepos = final.evalPackages.runCommand dotCabalName { nativeBuildInputs = [ cabal-install ]; preferLocalBuild = true; } ''
214+ tarballRepos = final.runCommand dotCabalName { nativeBuildInputs = [ cabal-install ]; preferLocalBuild = true; } ''
215215 mkdir -p $out/.cabal
216216 cat <<EOF > $out/.cabal/config
217217 ${final.lib.concatStrings (
@@ -239,7 +239,7 @@ final: prev: {
239239 '';
240240 in
241241 # Add the extra-hackage-repos where we have all the files needed.
242− final.evalPackages.runCommand dotCabalName { nativeBuildInputs = [ final.evalPackages.xorg.lndir ]; } ''
242+ final.runCommand dotCabalName { nativeBuildInputs = [ final.xorg.lndir ]; } ''
243243 mkdir $out
244244 lndir ${tarballRepos} $out
245245
@@ -261,10 +261,9 @@ final: prev: {
261261
262262 # Helps materialize the output of derivations
263263 materialize = import ../lib/materialize.nix {
264− inherit (final.evalPackages) nix;
264+ pkgs = final;
265+ inherit (final) nix runCommand writeShellScript;
265266 inherit (final.haskell-nix) checkMaterialization;
266− pkgs = final.evalPackages.pkgs;
267− inherit (final.evalPackages.pkgs) runCommand writeShellScript;
268267 };
269268
270269 update-index-state-hashes = import ../scripts/update-index-state-hashes.nix {
@@ -275,11 +274,7 @@ final: prev: {
275274 };
276275
277276 # Function to call stackToNix
278− callStackToNix = import ../lib/call-stack-to-nix.nix {
279− pkgs = final.evalPackages.pkgs;
280− inherit (final.evalPackages.pkgs) runCommand;
281− inherit (final.evalPackages.haskell-nix) mkCacheFile materialize haskellLib;
282− };
277+ callStackToNix = import ../lib/call-stack-to-nix.nix;
283278
284279 # given a source location call `cabal-to-nix` (from nix-tools) on it
285280 # to produce the nix representation of it.
@@ -325,7 +320,7 @@ final: prev: {
325320 # pkgs.fetchgit doesn't have any way of fetching from a given
326321 # ref.
327322 assert isNull ref;
328− final.evalPackages.fetchgit {
323+ final.fetchgit {
329324 url = url;
330325 rev = rev;
331326 sha256 = sha256;
@@ -382,10 +377,7 @@ final: prev: {
382377 }
383378 '';
384379
385− genStackCache = import ../lib/stack-cache-generator.nix {
386− inherit (final.evalPackages) pkgs;
387− inherit (final.evalPackages.haskell-nix) haskellLib;
388− };
380+ genStackCache = import ../lib/stack-cache-generator.nix;
389381
390382 mkCacheModule = cache:
391383 # for each item in the `cache`, set
@@ -414,7 +406,7 @@ final: prev: {
414406 final.buildPackages.lib.optionalAttrs (ref != null) { inherit ref; }
415407 )
416408 else
417− final.evalPackages.fetchgit { inherit url rev sha256; };
409+ final.fetchgit { inherit url rev sha256; };
418410 } // final.buildPackages.lib.optionalAttrs (subdir != null && subdir != ".") { postUnpack = "sourceRoot+=/${subdir}; echo source root reset to $sourceRoot"; };
419411 };
420412
@@ -428,11 +420,9 @@ final: prev: {
428420 # Resulting nix files are added to nix-plan subdirectory.
429421 callCabalProjectToNix = import ../lib/call-cabal-project-to-nix.nix {
430422 index-state-hashes = import indexStateHashesPath;
431− inherit (final.buildPackages.haskell-nix) haskellLib materialize;
423+ inherit (final.buildPackages.haskell-nix) haskellLib;
432424 pkgs = final.buildPackages.pkgs;
433− inherit (final) evalPackages;
434− inherit (final.evalPackages.haskell-nix) dotCabal;
435− inherit (final.buildPackages.pkgs) runCommand symlinkJoin cacert;
425+ inherit (final.buildPackages.pkgs) runCommand cacert;
436426 };
437427
438428 # Loads a plan and filters the package directories using cleanSourceWith
@@ -455,60 +445,22 @@ final: prev: {
455445 # the index-state-hashes is used. This guarantees reproducibility wrt
456446 # to the haskell.nix revision. If reproducibility beyond haskell.nix
457447 # is required, a specific index-state should be provided!
458− hackage-package =
459− { name, compiler-nix-name, ... }@args':
460− let args = { caller = "hackage-package"; } // args';
461− in (hackage-project args).getPackage name;
462− hackage-project =
463− { name
464− , compiler-nix-name
465− , version ? "latest"
466− , revision ? "default"
467− , ... }@args':
468− let version' = if version == "latest"
469− then builtins.head (
470− builtins.sort
471− (a: b: builtins.compareVersions a b > 0)
472− (builtins.attrNames hackage.${name}))
473− else version;
474− args = { caller = "hackage-project"; } // args';
475− tarball = final.pkgs.fetchurl {
476− url = "mirror://hackage/${name}-${version'}.tar.gz";
477− inherit (hackage.${name}.${version'}) sha256; };
478− rev = hackage.${name}.${version'}.revisions.${revision};
479− cabalFile = final.pkgs.fetchurl {
480− url = "https://hackage.haskell.org/package/${name}-${version'}/revision/${toString rev.revNum}.cabal";
481− inherit (rev) sha256;
482− };
483− revSuffix = final.lib.optionalString (rev.revNum > 0) "-r${toString rev.revNum}";
484− in let src = final.buildPackages.pkgs.runCommand "${name}-${version'}${revSuffix}-src" {} (''
485− tmp=$(mktemp -d)
486− cd $tmp
487− tar xzf ${tarball}
488− mv "${name}-${version'}" $out
489− '' + final.lib.optionalString (rev.revNum > 0) ''
490− cp ${cabalFile} $out/${name}.cabal
491− '') // {
492− # TODO remove once nix >=2.4 is widely adopted (will trigger rebuilds of everything).
493− # Disable filtering keeps pre ond post nix 2.4 behaviour the same. This means that
494− # the same `alex`, `happy` and `hscolour` are used to build GHC. It also means that
495− # that `tools` in the shell will be built the same.
496− filterPath = { path, ... }: path;
497− };
498− in cabalProject' ({
499− # Avoid readDir and readFile IFD functions looking for these files in the hackage source
500− cabalProject = null; cabalProjectLocal = null; cabalProjectFreeze = null;
501− } // final.haskell-nix.hackageQuirks { inherit name; version = version'; } //
502− builtins.removeAttrs args [ "version" "revision" ] // { inherit src; });
448+ hackage-package = projectModule:
449+ let project = hackage-project projectModule;
450+ in project.getPackage project.args.name;
451+ hackage-project = projectModule:
452+ cabalProject' ([
453+ (import ../modules/hackage-project.nix)
454+ ] ++ (import ../modules/hackage-quirks.nix)
455+ ++ (if builtins.isList projectModule then projectModule else [projectModule]));
503456
504457 # This function is like `cabalProject` but it makes the plan-nix available
505458 # separately from the hsPkgs. The advantage is that the you can get the
506459 # plan-nix without building the project.
507460 cabalProject' =
508461 projectModule: haskellLib.evalProjectModule ../modules/cabal-project.nix projectModule (
509− { src, compiler-nix-name, ... }@args':
462+ { src, compiler-nix-name, evalPackages, ... }@args:
510463 let
511− args = { caller = "cabalProject'"; } // args';
512464 callProjectResults = callCabalProjectToNix args;
513465 plan-pkgs = importAndFilterProject {
514466 inherit (callProjectResults) projectNix sourceRepos src;
@@ -522,6 +474,7 @@ final: prev: {
522474 config = {
523475 compiler.nix-name = compiler-nix-name;
524476 hsPkgs = {};
477+ inherit evalPackages;
525478 };
526479 }
527480 else mkCabalProjectPkgSet
@@ -531,7 +484,10 @@ final: prev: {
531484 ++ (args.modules or [])
532485 ++ final.lib.optional (args.ghcOverride != null || args.ghc != null)
533486 { ghc.package = if args.ghcOverride != null then args.ghcOverride else args.ghc; }
534− ++ [ { compiler.nix-name = final.lib.mkForce args.compiler-nix-name; } ];
487+ ++ [ {
488+ compiler.nix-name = final.lib.mkForce args.compiler-nix-name;
489+ evalPackages = final.lib.mkDefault evalPackages;
490+ } ];
535491 extra-hackages = args.extra-hackages or [] ++ callProjectResults.extra-hackages;
536492 };
537493
@@ -708,7 +664,7 @@ final: prev: {
708664 # not exist at all). The derivation will never build
709665 # and simple outputs the result of cabal configure.
710666 getComponent = componentName:
711− final.evalPackages.runCommand "cabal-configure-error" {
667+ final.rawProject.config.evalPackages.runCommand "cabal-configure-error" {
712668 passthru = {
713669 inherit project package;
714670 };
@@ -807,7 +763,7 @@ final: prev: {
807763
808764 stackProject' =
809765 projectModule: haskellLib.evalProjectModule ../modules/stack-project.nix projectModule (
810− { src, ... }@args:
766+ { src, evalPackages, ... }@args:
811767 let callProjectResults = callStackToNix (args
812768 // final.lib.optionalAttrs (args.cache == null) { inherit cache; });
813769 generatedCache = genStackCache args;
@@ -824,7 +780,8 @@ final: prev: {
824780 ++ (args.modules or [])
825781 ++ final.lib.optional (args.ghc != null) { ghc.package = args.ghc; }
826782 ++ final.lib.optional (args.compiler-nix-name != null)
827− { compiler.nix-name = final.lib.mkForce args.compiler-nix-name; };
783+ { compiler.nix-name = final.lib.mkForce args.compiler-nix-name; }
784+ ++ [ { evalPackages = final.lib.mkDefault evalPackages; } ];
828785 };
829786
830787 project = addProjectAndPackageAttrs {
@@ -860,6 +817,7 @@ final: prev: {
860817 (import ../modules/stack-project.nix)
861818 (import ../modules/cabal-project.nix)
862819 (import ../modules/project.nix)
820+ {_module.args.pkgs = final;} # Needed to make `src = config.evalPackages.haskell-nix.haskellLib.cleanGit ...` work
863821 ] ++ projectModule';
864822 }).config) src projectFileName;
865823 dir = __readDir (src.origSrcSubDir or src);
@@ -881,12 +839,12 @@ final: prev: {
881839 if final.lib.hasSuffix ".yaml" selectedFileName
882840 then stackProject' ([
883841 (import ../modules/project.nix)
884− { caller = "project'"; stackYaml = selectedFileName; }
842+ { stackYaml = selectedFileName; }
885843 ] ++ projectModule'
886844 )
887845 else cabalProject' ([
888846 (import ../modules/project.nix)
889− { caller = "project'"; cabalProjectFileName = selectedFileName; }
847+ { cabalProjectFileName = selectedFileName; }
890848 ] ++ projectModule');
891849
892850 # This is the same as the `cabalPackage` and `stackPackage` wrappers