-
Notifications
You must be signed in to change notification settings - Fork 247
exactDeps
has bad interaction with source-repository-package
and shellFor
#1637
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
Comments
This is fundamentally incompatible with using `source-repository-package` on a transitive dependency: input-output-hk/haskell.nix#1637
Another option FTR if one wants to use
Also see here and here for how this looks in practice. In my experience, this works fairly well, but YMMV. |
This ticket is partly a result of getting rid of the cabal wrapper :) You missed a step: you also have to hack up your |
Right, thanks for catching that, I guess I performatively proved the point that the situation here could be improved 😄 Concretely, for a shell for all components, one has to add packages = ps:
lib.attrValues (pkgs.haskell-nix.haskellLib.selectProjectPackages ps); to the args to |
If you add the stanzas in |
We can make a wrapper for |
But just fixing it upstream seems easier. |
Given that the goal of |
This is fundamentally incompatible with using `source-repository-package` on a transitive dependency: input-output-hk/haskell.nix#1637
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Still relevant |
For anyone wanting to implement this take a look at this related issue with commentary from Cabal developers: |
Whenever we want to use `source-repository-package`, we need to disable this. See: input-output-hk/haskell.nix#1637
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
If that may help anyone, here's my understanding and what I came up with, rediscovering @amesgen workarounds: project.shellFor {
# Force cabal-install (by setting CABAL_CONFIG=)
# to use the packages selected by project.plan-nix.
exactDeps = true;
# Provision (in `ghc-pkg list`) the **dependencies** of the packages selected here,
# which are not also selected here.
# By default haskell.nix selects here all _local_ packages
# (packages from both the packages and the source-repository-package stanzas)
# which therefore excludes source-repository-packages from being provisioned.
# Hence select only the _project_ packages (packages from the packages stanza).
packages = ps: lib.attrValues (pkgs.haskell-nix.haskellLib.selectProjectPackages ps);
nativeBuildInputs = [
# Wraps cabal-install to remove source-repository-package stanzas,
# otherwise it would download an use them,
# likely because it does not know that those packages provisioned
# in `ghc-pkg list` must be used in priority.
(let cabal-install = project.tool "cabal" {
version = "latest";
#inherit index-state;
modules = [
{
# Preserve Bash completion for cabal.
packages.cabal-install.components.exes.cabal.postInstall = ''
mkdir -p $out/share/bash-completion
mv bash-completion $out/share/bash-completion/completions
'';
}
];
};
in
# symlinkJoin cabal-install to preserve share/bash-completion/
pkgs.symlinkJoin {
name = "cabal-install";
paths = [ cabal-install ];
nativeBuildInputs = [ pkgs.makeWrapper ];
# Wrap cabal-install to make it use the local cabal.project.flake.
postBuild = ''
rm "$out"/bin/cabal
makeWrapper \
${cabal-install}/bin/cabal \
"$out"/bin/cabal \
--add-flags --project-file=cabal.project.flake
'';
})
];
# cabal.project.flake must be in the same directory than the original cabal.project
# for the relative paths in the packages stanza to point to the correct subdirs.
shellHook = ''
ln -sf ${pkgs.runCommandLocal "cabal.project" {
nativeBuildInputs = with pkgs; [ gawk ];
}
# Strips source-repository-package stanzas from cabal.project.
''
awk '/^[^ ]/{f=/^source-repository-package/} !f' >$out ${./cabal.project}
''
} cabal.project.flake
'';
}; |
I've observed what I think is the following interaction:
Project P has
exactDeps
setsource-repository-package
stanza patching C which is a dependency of BIn this scenario, cabal will always want to rebuild B. There is no way to convince it to take a prebuilt B from a package-db short of removing the
source-repository-package
stanza. But settingexactDeps
says "we don't want cabal to build anything", and indeed this will "work": cabal will decide it wants to build B, but fail because it has no repositories ("unknown package B").(In fact, we're clever enough to not even bother putting our prebuilt B into the shell, because we know cabal will ignore it. This can seem a little surprising if you're not expecting B to be missing!)
I think this is inescapable: cabal will absolutely insist on building B, and
exactDeps
won't let it. If we just wantedexactDeps
to say "don't let cabal hit the network", then we could point it at a local repository instead, perhaps.My preferred solution: don't use
exactDeps
.The text was updated successfully, but these errors were encountered: