Skip to content

shellFor: provide build tools for all packages when exactDeps = false. Fix #1753. #1769

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
Nov 8, 2022

Conversation

jbgi
Copy link
Contributor

@jbgi jbgi commented Nov 4, 2022

This fix #1753.

also only depends on hsc2hs from ghcEnv to avoid collisions when using devshell (haskellLib.devshellFor).

@jbgi jbgi requested review from hamishmack and michaelpj November 4, 2022 14:34
@jbgi jbgi mentioned this pull request Nov 4, 2022
10 tasks
@@ -167,7 +167,9 @@ in
buildInputs = systemInputs
++ mkDrvArgs.buildInputs or [];
nativeBuildInputs = [ ghcEnv ]
++ nativeBuildInputs
# We remove hsc2hs from dependencies provided by packages `build-tools`
# since it is already provided by `ghcEnv` (avoid collisions).
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is safe because... hsc2hs comes with GHC, so we can't end up in a situation where packages depend on multiple different versions? or what?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes hsc2hs comes with GHC, and ghcEnv binaries are first in PATH so hsc2hs from ghcEnv has always been the one used anyway.

@michaelpj
Copy link
Collaborator

Interesting. I'm kind of surprised we don't get a collision error in shellFor itself, if it's pulling in multiple copied of hsc2hs. Do you know why that isn't happening @jbgi ?

I'd like an opinion from @hamishmack on this one also.

@jbgi
Copy link
Contributor Author

jbgi commented Nov 4, 2022

I'm kind of surprised we don't get a collision error in shellFor itself, if it's pulling in multiple copied of hsc2hs. Do you know why that isn't happening @jbgi ?

yes because shellFor does not try to copy all binaries into a single output, so multiple hsc2hs are available from $PATH in this case (but the first one is from ghcEnv).

@jbgi jbgi force-pushed the nonExactDeps-need-all-build-tools branch from fbfd86f to c699866 Compare November 4, 2022 15:35
@michaelpj
Copy link
Collaborator

yes because shellFor does not try to copy all binaries into a single output, so multiple hsc2hs are available from $PATH in this case (but the first one is from ghcEnv).

Ah I see. I wonder if this is something we should also check for? Presumably such cases of PATH shadowing might lead to bugs? More generally, I guess we might behave badly if we have two packages that need to be built locally which need different versions of a build tool!

@jbgi jbgi force-pushed the nonExactDeps-need-all-build-tools branch from c699866 to 01f822f Compare November 4, 2022 16:41
@michaelpj
Copy link
Collaborator

I just happened to spot this in cardano-node, perhaps we will be able to remove it after this PR? https://github.com/input-output-hk/cardano-node/blob/master/nix/haskell.nix#L188

@jbgi
Copy link
Contributor Author

jbgi commented Nov 4, 2022

I just happened to spot this in cardano-node, perhaps we will be able to remove it after this PR?

If this was done only for the nix-shell then yes, but probably not, need to test.

@jbgi
Copy link
Contributor Author

jbgi commented Nov 4, 2022

If this was done only for the nix-shell then yes, but probably not, need to test.

if not then maybe instead of my patch we need to filter out hsc2hs at the component level.

jbgi added 2 commits November 5, 2022 19:15
 When not using `exactDeps` cabal may try to build arbitrary dependencies
 so in this case we need to provide the build tools for all of hsPkgs.
 since it is provided by ghc env, which is first in PATH.
 This avoid possible collisions when using eg. devshells, which
 fuse all binaries into a single output directory.
@jbgi jbgi force-pushed the nonExactDeps-need-all-build-tools branch from 01f822f to 9289103 Compare November 5, 2022 18:29
@jbgi
Copy link
Contributor Author

jbgi commented Nov 5, 2022

I moved the filtering-out of hsc2hs to comp-builder in last commit. However I'm not totally sure:
this old comment by @angerman points to the ability to use a patched version of hsc2hs via build-tools (ability that would be removed, if it existed, by my commit): #214 (comment)

However I doubt this ability still exists: ghc-env is always first in nativeBuildInputs, hence also first in PATH (so that the one from build-tools would never be used):

nativeBuildInputs =
[shellWrappers buildPackages.removeReferencesTo]
++ executableToolDepends;

And in any case, this config flag indicates that, at least for cross-compile, only the hsc2hs from ghc is intended to be used:

"--with-hsc2hs=${ghc.targetPrefix}hsc2hs"

@angerman
Copy link
Collaborator

angerman commented Nov 6, 2022

That's an interesting obersavtion. Should (explicitly specified) build-tools have precedence over the things that are shipped with GHC? That might actually be the correct thing to do.

As for the cross case. Thats mostly because we want tooling consistency and GHC's build system will prefix all produced binaries with the target prefix. I believe you could even plug in another hsc2hs just fine.

@hamishmack
Copy link
Collaborator

bors try

iohk-bors bot added a commit that referenced this pull request Nov 7, 2022
@hamishmack
Copy link
Collaborator

I guess in the future we could try removing hsc2hs from the GHC derivation and try to remove its special treatment from comp-builder.nix.

Perhaps shell-for.nix could somehow pick the tool with the most recent .version in the case of clashes. That might be tricky.

There is a similar problem with pkg-config versions in that different packages could require different versions, but I think we can only easily provide one.

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 7, 2022

try

Timed out.

@michaelpj
Copy link
Collaborator

I don't quite understand the issue here, could someone make a ticket for this so we don't forget?

@michaelpj
Copy link
Collaborator

bors try

@michaelpj michaelpj closed this Nov 7, 2022
iohk-bors bot added a commit that referenced this pull request Nov 7, 2022
@michaelpj michaelpj reopened this Nov 7, 2022
@michaelpj
Copy link
Collaborator

bors try

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 7, 2022

try

Already running a review

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 7, 2022

try

Timed out.

@jbgi
Copy link
Contributor Author

jbgi commented Nov 7, 2022

bors try

iohk-bors bot added a commit that referenced this pull request Nov 7, 2022
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 8, 2022

try

Timed out.

@hamishmack hamishmack merged commit cebbb6d into master Nov 8, 2022
@iohk-bors iohk-bors bot deleted the nonExactDeps-need-all-build-tools branch November 8, 2022 02:24
@hamishmack
Copy link
Collaborator

I added an issue for supporting build-tool-depends: hsc2hs:hsc2hs better #1772

hamishmack added a commit that referenced this pull request Nov 29, 2022
#1769 added all the tool dependencies of the hsPkgs in a project to the shell.  This is great for cabal projects where the set of packages will be limited to those in the plan.  It allows these packages to be rebuilt by cabal.

For stack projects however this set is much larger (all of stackage), likely to include unwanted tools and tools that may be broken.

This change adds `shell.allDeps` and defaults it to `false` for stack projects.

Fixes #1793
hamishmack added a commit that referenced this pull request Nov 29, 2022
#1769 added all the tool dependencies of the hsPkgs in a project to the shell.  This is great for cabal projects where the set of packages will be limited to those in the plan.  It allows these packages to be rebuilt by cabal.

For stack projects however this set is much larger (all of stackage), likely to include unwanted tools and tools that may be broken.

This change adds `shell.allDeps` and defaults it to `false` for stack projects.

Fixes #1793
hamishmack added a commit that referenced this pull request Dec 1, 2022
* Add `shell.allDeps` as a fix for #1793

#1769 added all the tool dependencies of the hsPkgs in a project to the shell.  This is great for cabal projects where the set of packages will be limited to those in the plan.  It allows these packages to be rebuilt by cabal.

For stack projects however this set is much larger (all of stackage), likely to include unwanted tools and tools that may be broken.

This change adds `shell.allDeps` and defaults it to `false` for stack projects.

Fixes #1793

* Added comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pkg-config issue on cabal.project with no source-repository-package stanzas
4 participants