Skip to content

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

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -211,37 +211,38 @@ final: prev: {
# dotCabalName anyway.
dotCabalName = "dot-cabal-" + allNames;
# This is very big, and cheap to build: prefer building it locally
tarballRepos = final.runCommand dotCabalName { nativeBuildInputs = [ cabal-install ]; preferLocalBuild = true; } ''
tarballRepoFor = name: index: final.runCommand "tarballRepo_${name}" {
nativeBuildInputs = [ cabal-install ];
} ''
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