Skip to content

dotCabal: Split up tarballRepos computation into tarballRepoFor to improve caching #1660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realised I forgot to remove this comment (it's also quite slow for the main hackage)

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