From 3a375d23d4ead841954aa605b82c34b0c196cb67 Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Mon, 29 Jan 2024 16:44:02 +0000 Subject: [PATCH] Use all-cabal-hashes directly rather than extracting individual components This gives us a significant speed-up, since all we need to do as part of the IFD is run cabal2nix. --- nix/build-support/stacklock2nix/default.nix | 25 +++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/nix/build-support/stacklock2nix/default.nix b/nix/build-support/stacklock2nix/default.nix index 6c1e3f5..58b8045 100644 --- a/nix/build-support/stacklock2nix/default.nix +++ b/nix/build-support/stacklock2nix/default.nix @@ -6,6 +6,7 @@ , runCommand , stdenv , path +, all-cabal-hashes }@topargs: { # The path to your stack.yaml file. @@ -82,7 +83,7 @@ # (instead of something like `fetchurl`) so that the repository is unzipped # and untarred. stacklock2nix can still work with an all-cabal-hashes that is # a tarball, but building will be faster with a plain directory.) - all-cabal-hashes ? null + all-cabal-hashes ? topargs.all-cabal-hashes , callPackage ? topargs.callPackage , # Path to Nixpkgs. # @@ -306,15 +307,25 @@ let # # This takes care of replaces the `.cabal` file from Hackage with the correct revision # specified in the Hackage lock info. - pkgHackageInfoToNixHaskPkg = pkgHackageInfo: hfinal: + pkgHackageInfoToNixHaskPkg = {name, version, cabalFileHash, ...}: hfinal: let - additionalArgs = getAdditionalCabal2nixArgs pkgHackageInfo.name pkgHackageInfo.version; + additionalArgs = getAdditionalCabal2nixArgs name version; in overrideCabalFileRevision - pkgHackageInfo.name - pkgHackageInfo.version - pkgHackageInfo.cabalFileHash - (hfinal.callHackage pkgHackageInfo.name pkgHackageInfo.version additionalArgs); + name + version + cabalFileHash + # Like callHackage from nixpkgs, + # but we don't call all-cabal-hashes-component + # to avoid excessive IFD + (hfinal.callPackage + (hfinal.haskellSrc2nix { + name = "${name}-${version}"; + src = "${all-cabal-hashes}/${name}/${version}/${name}.cabal"; + sha256 =''$(sed -e 's/.*"SHA256":"//' -e 's/".*$//' "${all-cabal-hashes}/${name}/${version}/${name}.json")''; + }) + additionalArgs + ); # Return a derivation for a Haskell package for the given Haskell package # lock info.