-
-
Save angerman/209fcac0b84a3243b0b312beb2e70ea8 to your computer and use it in GitHub Desktop.
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 is a tiny bit better than doJailbreak. | |
# | |
# We essentially *know* the dependencies, and with the | |
# full cabal file representation, we also know all the | |
# flags. As such we can sidestep the solver. | |
# | |
# Pros: | |
# - no need for doJailbreak | |
# - no need for jailbreak-cabal to be built with | |
# Cabal2 if the cabal file requires it. | |
# - no reliance on --allow-newer, which only made | |
# a very short lived appearance in Cabal. | |
# (Cabal-2.0.0.2 -- Cabal-2.2.0.0) | |
# | |
# Cons: | |
# - automatic flag resolution won't happen and will | |
# have to be hard coded. | |
# | |
# Ideally we'd just inspect the haskell*Depends fields | |
# we feed the builder. However because we null out the | |
# lirbaries ghc ships (e.g. base, ghc, ...) this would | |
# result in an incomplete --dependency=<name>=<name>-<version> | |
# set and not lead to the desired outcome. | |
# | |
# If we could still have base, etc. not nulled, but | |
# produce some virtual derivation, that might allow us | |
# to just use the haskell*Depends fields to extract the | |
# name and version for each dependency. | |
# | |
# Ref: https://github.com/haskell/cabal/issues/3163#issuecomment-185833150 | |
# --- | |
# ghc-pkg should be ${ghcCommand}-pkg; and --package-db | |
# should better be --${packageDbFlag}; but we don't have | |
# those variables in scope. | |
doExactConfig = pkg: pkgs.haskell.lib.overrideCabal pkg (drv: { | |
# TODO: need to run `ghc-pkg field <pkg> id` over all `--dependency` | |
# values. Should we encode the `id` in the nix-pkg as well? | |
preConfigure = pkgs.lib.traceSeq deps (drv.preConfigure or "") + '' | |
configureFlags+=" --exact-configuration" | |
globalPackages=$(ghc-pkg list --global --simple-output) | |
localPackages=$(ghc-pkg --package-db="$packageConfDir" list --simple-output) | |
for pkg in $globalPackages; do | |
if [ "''${pkg%-*}" != "rts" ]; then | |
configureFlags+=" --dependency="''${pkg%-*}=$pkg | |
fi | |
done | |
for pkg in $localPackages; do | |
configureFlags+=" --dependency="''${pkg%-*}=$pkg | |
done | |
#echo "<<< <<< <<<" | |
#echo ''${configureFlags} | |
configureFlags=$(for flag in ''${configureFlags};do case "X''${flag}" in | |
X--dependency=*) echo ''${flag%=*}=$(ghc-pkg --package-db="$packageConfDir" --global field ''${flag##*=} id | awk -F': ' '{ print $2 }');; | |
*) echo ''${flag};; | |
esac; done) | |
#echo "--- --- ---" | |
#echo ''${configureFlags} | |
#echo ">>> >>> >>>" | |
''; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment