Skip to content

Commit

Permalink
dotCabal: Split up tarballRepos computation into tarballRepoFor
Browse files Browse the repository at this point in the history
… to improve caching (#1660)

This is relevant when using extra hackages.
Any extra hackage would cause `cabal new-update` to be run for all hackages
previously, which would take quite a long time for the main hackage.

Co-authored-by: Las Safin <[email protected]>
  • Loading branch information
hamishmack and L-as authored Sep 13, 2022
1 parent 6c7f9d0 commit 986a65b
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions overlays/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -257,37 +257,38 @@ final: prev: {
'';
};
# This is very big, and cheap to build: prefer building it locally
tarballRepos = final.runCommand dotCabalName { nativeBuildInputs = [ cabal-install dummy-ghc dummy-ghc-pkg ]; preferLocalBuild = true; } ''
tarballRepoFor = name: index: final.runCommand "tarballRepo_${name}" {
nativeBuildInputs = [ cabal-install dummy-ghc dummy-ghc-pkg ];
} ''
set -xe
mkdir -p $out/.cabal
cat <<EOF > $out/.cabal/config
${final.lib.concatStrings (
final.lib.mapAttrsToList (name: index:
''
repository ${name}
url: file:${mkLocalHackageRepo { inherit name index; }}
secure: True
root-keys:
key-threshold: 0
'') allTarballs
)}
EOF
# All repositories must be mkdir'ed before calling new-update on any repo,
# otherwise it fails.
${final.lib.concatStrings (map (name: ''
mkdir -p $out/.cabal/packages/${name}
'') (builtins.attrNames allTarballs))}
mkdir -p $out/.cabal/packages/${name}
${final.lib.concatStrings (map (name: ''
HOME=$out cabal new-update ${name}
'') (builtins.attrNames allTarballs))}
HOME=$out cabal new-update ${name}
'';
f = name: index:
let x = tarballRepoFor name index; in
''
ln -s ${x}/.cabal/packages/${name} $out/.cabal/packages/${name}
cat ${x}/.cabal/config >> $out/.cabal/config
'';
in
# Add the extra-hackage-repos where we have all the files needed.
final.runCommand dotCabalName { nativeBuildInputs = [ final.xorg.lndir ]; } ''
mkdir $out
lndir ${tarballRepos} $out
mkdir -p $out/.cabal/packages
${builtins.concatStringsSep "\n" (final.lib.mapAttrsToList f allTarballs)}
${final.lib.concatStrings (final.lib.mapAttrsToList (name: repo: ''
mkdir -p $out/.cabal/packages/${name}
Expand Down

0 comments on commit 986a65b

Please sign in to comment.