Skip to content
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

ghcWithPackages environment doesn't build with integer-simple #153319

Closed
cdepillabout opened this issue Jan 3, 2022 · 13 comments · Fixed by #166548
Closed

ghcWithPackages environment doesn't build with integer-simple #153319

cdepillabout opened this issue Jan 3, 2022 · 13 comments · Fixed by #166548
Labels

Comments

@cdepillabout
Copy link
Member

cdepillabout commented Jan 3, 2022

Describe the bug

ghcWithPackages doesn't appear to work with integer-simple.

On 4acff2b, I get an error with the following command:

$ nix-shell -I nixpkgs=./. -p 'haskell.packages.integer-simple.ghc8107.ghcWithPackages (p: [p.random])'
this derivation will be built:
  /nix/store/8xw19mncwzyavib9rdwibyz4sh28mljh-ghc-integer-simple-8.10.7-with-packages.drv
building '/nix/store/8xw19mncwzyavib9rdwibyz4sh28mljh-ghc-integer-simple-8.10.7-with-packages.drv'...
/nix/store/7w5cdwwmcccmr5bb8qxayn7969sv743w-random-1.2.0/nix-support:
propagated-build-inputs: /nix/store/7mas5p1hd3xyw8bmgqkkwr1h2jabagpn-splitmix-0.1.0.4/nix-support/propagated-build-inputs
rm: cannot remove '/nix/store/48xd2pxvbi00ph96qr5ba6mwn1ypx9iy-ghc-integer-simple-8.10.7-with-packages/lib/ghc-integer-simple-8.10.7/package.conf.d/package.cache.lock': No such file or direc
tory

This command works correctly with non-integer-simple:

$ nix-shell -I nixpkgs=./. -p 'haskell.packages.ghc8107.ghcWithPackages (p: [p.random])'
$ runghc <<< $'import System.Random\nmain = (randomIO :: IO Int) >>= print'
6838749691054437585

My guess is that this is caused by the code block in pkgs/development/haskell-modules/with-packages-wrapper.nix right here:

${lib.optionalString hasLibraries ''
# GHC 8.10 changes.
# Instead of replacing package.cache[.lock] with the new file,
# ghc-pkg is now trying to open the file. These file are symlink
# to another nix derivation, so they are not writable. Removing
# them allow the correct behavior of ghc-pkg recache
# See: https://github.com/NixOS/nixpkgs/issues/79441
rm $out/lib/${ghc.name}/package.conf.d/package.cache.lock
rm $out/lib/${ghc.name}/package.conf.d/package.cache

The rm command fails with the error: rm: cannot remove '/nix/store/48xd2pxvbi00ph96qr5ba6mwn1ypx9iy-ghc-integer-simple-8.10.7-with-packages/lib/ghc-integer-simple-8.10.7/package.conf.d/package.cache.lock': No such file or directory

This error can be worked around with a change like the following:

diff --git a/pkgs/development/haskell-modules/with-packages-wrapper.nix b/pkgs/development/haskell-modules/with-packages-wrapper.nix
index e5fe60a0ae5..72cf37f8277 100644
--- a/pkgs/development/haskell-modules/with-packages-wrapper.nix
+++ b/pkgs/development/haskell-modules/with-packages-wrapper.nix
@@ -136,8 +136,8 @@ symlinkJoin {
      # to another nix derivation, so they are not writable.  Removing
      # them allow the correct behavior of ghc-pkg recache
      # See: https://github.com/NixOS/nixpkgs/issues/79441
-     rm $out/lib/${ghc.name}/package.conf.d/package.cache.lock
-     rm $out/lib/${ghc.name}/package.conf.d/package.cache
+     rm ${packageCfgDir}/package.cache.lock
+     rm ${packageCfgDir}/package.cache
 
      $out/bin/${ghcCommand}-pkg recache
      ''}

If you look at the definition of packageCfgDir, it appears that ghc.name is being used where ${ghcCommand}-${ghc.version} should be used.

However, even with this change, the resulting environment is not correct. The environment does not correctly contain the random package:

$ nix-shell -I nixpkgs=./. -p 'haskell.packages.integer-simple.ghc8107.ghcWithPackages (p: [p.random])'
this derivation will be built:
  /nix/store/5k5fk87zjcdkjz1blrqmf0dvca9vsqwf-ghc-integer-simple-8.10.7-with-packages.drv
building '/nix/store/5k5fk87zjcdkjz1blrqmf0dvca9vsqwf-ghc-integer-simple-8.10.7-with-packages.drv'...
/nix/store/7w5cdwwmcccmr5bb8qxayn7969sv743w-random-1.2.0/nix-support:
propagated-build-inputs: /nix/store/7mas5p1hd3xyw8bmgqkkwr1h2jabagpn-splitmix-0.1.0.4/nix-support/propagated-build-inputs
$ runghc <<< $'import System.Random\nmain = (randomIO :: IO Int) >>= print'

/run/user/1000/runghcXXXX3395958-0.hs:1:1: error:
    Could not find module ‘System.Random’
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
1 | import System.Random
  | ^^^^^^^^^^^^^^^^^^^^

My guess is that this is because the ghcWithPackages environment is created with symlinkJoin, but the path to the package config directory is different for integer-simple packages and the integer-simple GHC.

Here's what the paths look like for normal GHC:

$ nix-build ./. -A haskell.compiler.ghc8107
/nix/store/ch0a40krsc4zaa9wv8qd1i56pswjzwx0-ghc-8.10.7
$ ls /nix/store/ch0a40krsc4zaa9wv8qd1i56pswjzwx0-ghc-8.10.7/lib/ghc-8.10.7/package.conf.d/
...
$ nix-build ./. -A haskell.packages.ghc8107.random
/nix/store/qamvzkgcl3qcafjc3kngirdvwxhdpqj6-random-1.2.0
$ ls /nix/store/qamvzkgcl3qcafjc3kngirdvwxhdpqj6-random-1.2.0/lib/ghc-8.10.7/package.conf.d/
random-1.2.0-4yTZ53A8d79AtqKspztz45.conf

You can see that random's package.conf file ends up in lib/ghc-8.10.7/package.conf.d/.

Here's what the paths look like for the integer-simple GHC:

$ nix-build ./. -A haskell.compiler.integer-simple.ghc8107
/nix/store/dbi6hx9fa4lsd3bilq62bqxz0sm41fwb-ghc-integer-simple-8.10.7
$ ls /nix/store/dbi6hx9fa4lsd3bilq62bqxz0sm41fwb-ghc-integer-simple-8.10.7/lib/ghc-8.10.7/package.conf.d/
...
$ nix-build ./. -A haskell.packages.integer-simple.ghc8107.random
/nix/store/7w5cdwwmcccmr5bb8qxayn7969sv743w-random-1.2.0
$ ls /nix/store/7w5cdwwmcccmr5bb8qxayn7969sv743w-random-1.2.0/lib/ghc-integer-simple-8.10.7/package.conf.d/
random-1.2.0-4yTZ53A8d79AtqKspztz45.conf

You can see here that haskell.compiler.integer-simple.ghc8107 has it's package.conf.d in lib/ghc-8.10.7/package.conf.d/, but random has it's .conf file in lib/ghc-integer-simple-8.10.7/package.conf.d/. So this .conf file doesn't end up in the right place in the symlinkJoin in with-packages-wrapper.nix.

Possible Solution

I'm not sure what would be the best solution for this, but I imagine we have to be very careful to make sure GHC and our Nix scripts are looking at the right place for the package conf dir in the following files:

  • pkgs/development/haskell-modules/generic-builder.nix
  • pkgs/development/haskell-modules/with-packages-wrapper.nix
  • pkgs/development/compilers/ghc/*.nix

The packageCfgDir variable that is currently defined in with-packages-wrapper.nix should likely be an attribute exported by the GHC derivations, and reused in the other files.

Notify maintainers

@NixOS/haskell

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.81, NixOS, 21.11 (Porcupine)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.5pre20211126_55275fc`
 - channels(root): `"nixos-21.11.334247.573095944e7"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/overriding-ghc-only-for-final-package/16953/2

@pranaysashank
Copy link
Contributor

pranaysashank commented Mar 31, 2022

I had the same issue, but with musl and integer-gmp instead. So it's similar to what is described above except ghc-integer-simple-8.10.7 is replaced with ghc-musl-8.10.7. I worked around this by changing the derivation to not add a variant suffix.

@sternenseemann
Copy link
Member

I'll look into fixing this finally, sorry this fell through the cracks. Since the workaround is so simple it should be quite easy to track down all uses of ghc.name that remain.

sternenseemann added a commit to sternenseemann/nixpkgs that referenced this issue Mar 31, 2022
This is an incorrectness pointed out in NixOS#153319 which we already have
a proper solution for.
@sternenseemann
Copy link
Member

sternenseemann commented Apr 5, 2022

In addition to the testing in the linked PR, I tested both examples from the issue again, which now work correctly in haskell-updates.

@cdepillabout
Copy link
Member Author

Great, thanks for looking into this!

@sternenseemann
Copy link
Member

This will be closed automatically when the fix is in master, let's keep it open until then.

@locallycompact
Copy link
Contributor

I'm getting this error again using ghcHEAD.withPackages.

       > propagated-build-inputs: /nix/store/0dfk2vhxr3m1rsd42nlbl6gb67frqvdc-lens-5.2/nix-support/propagated-build-inputs
     > /nix/store/vxsirk4xqaj4m7sij4gshz8gcss03zmi-adjunctions-4.4.2/nix-support:
     > propagated-build-inputs: /nix/store/0dfk2vhxr3m1rsd42nlbl6gb67frqvdc-lens-5.2/nix-support/propagated-build-inputs
     > /nix/store/66v6g3xy5xw58z08cgl7bagj9adazkxi-invariant-0.6/nix-support:
     > propagated-build-inputs: /nix/store/0dfk2vhxr3m1rsd42nlbl6gb67frqvdc-lens-5.2/nix-support/propagated-build-inputs
     > /nix/store/rdga81w7k42j01y4sf400bgxp7shicwp-primitive-0.7.4.0/nix-support:
     > propagated-build-inputs: /nix/store/0dfk2vhxr3m1rsd42nlbl6gb67frqvdc-lens-5.2/nix-support/propagated-build-inputs
     > /nix/store/zjzwf9c738nngmb3y2qjydcm16lbwy6k-vector-stream-0.1.0.0/nix-support:
     > propagated-build-inputs: /nix/store/0dfk2vhxr3m1rsd42nlbl6gb67frqvdc-lens-5.2/nix-support/propagated-build-inputs
     > rm: cannot remove '/nix/store/d6rf4q2v5xm5fdi9x9vl98s9xw87i9lr-ghc-9.7.20221224-with-packages/lib/ghc-9.7.20221224/package.conf.d/package.cache.lock': No such file or directory

@sternenseemann
Copy link
Member

What is the precise expression you are using?

@locallycompact
Copy link
Contributor

https://gitlab.homotopic.tech/horizon/horizon-core

nix run .#procex

I also tried it with your 9.6.1 branch and I get the same. There's a withPackages expression in shell/

@sternenseemann
Copy link
Member

@locallycompact It'd be nice if you could try narrowing down the issue further in the future! In this case it's a piece of cake, as it affects all ghcWithPackages environments that are not “empty” using a hadrian-built GHC: #211608.

@locallycompact
Copy link
Contributor

Thanks for finding it. I don't really get it but I'll take a look.

@sternenseemann
Copy link
Member

No worries, I'll take care of it.

@locallycompact
Copy link
Contributor

FYI I think this may have changed once more. Using latest commit of haskell-updates with GHC 9.8.1-release.

nix develop git+https://gitlab.horizon-haskell.net/package-sets/horizon-core#aeson.env
error: builder for '/nix/store/8whjnslj9pmf3b5hplxxh5n0pdvn07d9-ghc-9.8-with-packages.drv' failed with exit code 1;
       last 10 log lines:
       > propagated-build-inputs: /nix/store/a98mnbsv91qlgvlm8rnygvav80ivxd1v-data-fix-0.3.2/nix-support/propagated-build-inputs
       > /nix/store/0i9p75nxsvs9ljxciypbwrnl0zjg9xy8-transformers-compat-0.7.2/nix-support:
       > propagated-build-inputs: /nix/store/a98mnbsv91qlgvlm8rnygvav80ivxd1v-data-fix-0.3.2/nix-support/propagated-build-inputs
       > /nix/store/0i9p75nxsvs9ljxciypbwrnl0zjg9xy8-transformers-compat-0.7.2/nix-support:
       > propagated-build-inputs: /nix/store/a98mnbsv91qlgvlm8rnygvav80ivxd1v-data-fix-0.3.2/nix-support/propagated-build-inputs
       > /nix/store/siq0cq13mympkzqf3fqmi125v82vad4y-StateVar-1.2.2/nix-support:
       > propagated-build-inputs: /nix/store/a98mnbsv91qlgvlm8rnygvav80ivxd1v-data-fix-0.3.2/nix-support/propagated-build-inputs
       > /nix/store/siq0cq13mympkzqf3fqmi125v82vad4y-StateVar-1.2.2/nix-support:
       > propagated-build-inputs: /nix/store/a98mnbsv91qlgvlm8rnygvav80ivxd1v-data-fix-0.3.2/nix-support/propagated-build-inputs
       > rm: cannot remove '/nix/store/v0c2wwlw3zb1p2j774msadv4yg8njszi-ghc-9.8-with-packages/lib/ghc-9.8/lib/package.conf.d/package.cache.lock': No such file or directory
       For full logs, run 'nix log /nix/store/8whjnslj9pmf3b5hplxxh5n0pdvn07d9-ghc-9.8-with-packages.drv'.
error: 1 dependencies of derivation '/nix/store/a0yf3di39y5flirjw2rh0m8fhqrr4g9b-ghc-shell-for-aeson-2.2.1.0-env.drv' failed to build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants