-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround for cabal trying to build dependencies in nix-shell
For source-repository-package's, cabal tries to build them on its own, even when all dependencies are already provided by Nix. Relevant issues: - haskell/cabal#6049 - IntersectMBO/ouroboros-network#645 - haskell/cabal#5586 (comment) This seems to be a problem even with a cabal that includes haskell/cabal#6917 (see input-output-hk/haskell.nix#720 (comment) for how to test a cabal-install 3.4) The only known workaround is to remove the source-repository-package sections from cabal.project, but this should only be done for cabal when used from a nix-shell, not from cabal without a nix-shell, and not outside the nix-shell. To make this work smoothly, the script `scripts/nix-setup` can be used, which splits the source-repository-package sections into cabal.project.srcs, which is then again included from here (to make the Nix setup still work). Running the script again undoes it.
- Loading branch information
Showing
4 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
tmp=$(mktemp -d) | ||
trap 'rm -rf "$tmp"' exit | ||
|
||
if [[ ! -f cabal.project.srcs ]]; then | ||
# We later mark cabal.project as not having any changes, since we remove | ||
# source-repository-package sections from it but don't want the user to commit that | ||
# But if the user already has changes to it, that would make them not commit their own changes too | ||
# So make the user either stage or commit the changes to prevent this | ||
if ! git diff --exit-code --quiet cabal.project; then | ||
echo "cabal.project has unstaged changes. Stage or commit them first to use this script" >&2 | ||
exit 1 | ||
fi | ||
echo "Setting up cabal.project to work with nix-shell" >&2 | ||
|
||
# Splits the file at the first occurence of source-repository-package | ||
csplit -s -f "$tmp/cabal.project.split." cabal.project /source-repository-package/ | ||
mv "$tmp/cabal.project.split.00" cabal.project | ||
mv "$tmp/cabal.project.split.01" cabal.project.srcs | ||
|
||
# Prevent modification of these files since we later mark them as not having any changes | ||
chmod -w cabal.project cabal.project.srcs | ||
|
||
# In order to prevent the user from committing the changes to cabal.project, tell git that it should assume it wasn't changed | ||
git update-index --assume-unchanged cabal.project | ||
else | ||
echo "Undoing cabal.project setup for nix-shell" >&2 | ||
|
||
# Combine the split files into one again | ||
cat cabal.project cabal.project.srcs > "$tmp/cabal.project" | ||
chmod +w cabal.project cabal.project.srcs | ||
rm cabal.project.srcs | ||
mv "$tmp/cabal.project" cabal.project | ||
|
||
# Tell git to track changes to cabal.project again | ||
git update-index --no-assume-unchanged cabal.project | ||
fi |