Skip to content

Upgrading to GHC 9.2.4 / cabal 3.8.1.0 causes package.db issues #1608

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

Open
ramirez7 opened this issue Aug 22, 2022 · 8 comments
Open

Upgrading to GHC 9.2.4 / cabal 3.8.1.0 causes package.db issues #1608

ramirez7 opened this issue Aug 22, 2022 · 8 comments
Labels
bug Something isn't working preserved Keep stale bot away

Comments

@ramirez7
Copy link
Contributor

ramirez7 commented Aug 22, 2022

I first got this error:

The exception was:
/home/armando/.cabal/store/ghc-9.2.4/package.db/:
openBinaryTempFileWithDefaultPermissions: does not exist (No such file or
directory)

I tried manually created the package db in my nix-shell:

ghc-pkg init /home/armando/.cabal/store/ghc-9.2.4/package.db

But then I run into issues with my source-repository-packages in my cabal.project file:

Error: cabal: The following package dependencies were requested
--dependency='cute-c2=cute-c2-0.1.0.0-c68517fccf44774ff378ef2178405e2f04adfafeada4fc2372bea909782bd710'
--dependency='cute-sound=cute-sound-0.1.0.0-97e5ddd48614f40e2cb39689806143dbb2f0175f6f6d8a439d495cead7a6b0a5'
--dependency='sdl-gpu=sdl-gpu-0.1.0.0-2d34404b479c2527c59e8d2900583b93c98fb8d3ac6c8eb82c94a865e649db3c'
however the given installed package instance does not exist.

My cabal versions are different pre- and post-upgrade fwiw:

9.2.3

$ cabal --version
cabal-install version 3.6.2.0
compiled using version 3.6.3.0 of the Cabal library

vs 9.2.4

$ cabal --version
cabal-install version 3.8.1.0
compiled using version 3.8.1.0 of the Cabal library

This is the extent of my changes:

diff --git a/default.nix b/default.nix
index 4353cf3..c5d2882 100644
--- a/default.nix
+++ b/default.nix
@@ -10,5 +10,5 @@ in pkgs.haskell-nix.project {
   # We may need this someday for hint
   #modules = [{ reinstallableLibGhc = true; }];
 
-  compiler-nix-name = "ghc923";
+  compiler-nix-name = "ghc924";
 }
diff --git a/nix/sources.json b/nix/sources.json
index 5428fc0..66ea5e1 100644
--- a/nix/sources.json
+++ b/nix/sources.json
@@ -5,10 +5,10 @@
         "homepage": "",
         "owner": "input-output-hk",
         "repo": "hackage.nix",
-        "rev": "b63711c848a8d2ec8ae189ad291ce54bb041874d",
-        "sha256": "0qfcd7k4hdhfbc6377rr7fgnlakwfasy9djmvkszd463rla6k6gn",
+        "rev": "14df7a1e633059997ecd3182d8272a1f13e99c62",
+        "sha256": "01h5l3fgdpji6ckr8bpq5m03x8xj8yjx8qkcvy1g4r1lyrfdpr79",
         "type": "tarball",
-        "url": "https://github.com/input-output-hk/hackage.nix/archive/b63711c848a8d2ec8ae189ad291ce54bb041874d.tar.gz",
+        "url": "https://github.com/input-output-hk/hackage.nix/archive/14df7a1e633059997ecd3182d8272a1f13e99c62.tar.gz",
         "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
     },
     "haskellNix": {
@@ -17,10 +17,10 @@
         "homepage": "https://input-output-hk.github.io/haskell.nix",
         "owner": "input-output-hk",
         "repo": "haskell.nix",
-        "rev": "c6a44a799bc36fa063045bbe816f29d6c7594f39",
-        "sha256": "0rqglk7sr4kx5z70h47rzdzbinjpp13n6f4w0kfqfb1sg42m0gfq",
+        "rev": "e36a34c4abc02287ec79bf88a0c993f6b66f9945",
+        "sha256": "1s2qmrfipj6qks981pr7j2qk8j965as529z9g2ay2n83zqmf49jh",
         "type": "tarball",
-        "url": "https://github.com/input-output-hk/haskell.nix/archive/c6a44a799bc36fa063045bbe816f29d6c7594f39.tar.gz",
+        "url": "https://github.com/input-output-hk/haskell.nix/archive/e36a34c4abc02287ec79bf88a0c993f6b66f9945.tar.gz",
         "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
     },
     "niv": {

If I revert to my old version (using GHC 9.2.3) it works fine even despite blowing everything away. It seems to have no trouble re-generating a valid package.db (whereas the 9.2.4 bump never even creates those files). So I can stick with that in the interim.

I also checked out my upgrade branch on my laptop to see if it was my computer's environment specifically. This laptop did have some ghc 9.2.4 stuff already in ~/.cabal (unrelated to haskell.nix). When I tried to cabal repl, I got the The following package dependencies were requested error from above. So from that, I think I can say that haskell.nix at this version w/ghc 9.2.4 breaks my build for some reason 🤨

I'm not sure if this is a haskell.nix issue or a cabal issue tbh.

@ramirez7
Copy link
Contributor Author

I will try to create a minimal repro in my bug repro project tomorrow so anyone can try to reproduce easily.

@ramirez7
Copy link
Contributor Author

Setting exactDeps = false; allows me to work around the issue. I'd prefer to not skirt Nix though :)

@ramirez7
Copy link
Contributor Author

Here is a minimal repro

@hamishmack
Copy link
Collaborator

Ok so. It looks like we need a way to get the correct cabal store package db path into the cabal.config file.

For instance if I run this in the nix-shell it works:

cabal build --package-db=/Users/hamish/.cabal/store/ghc-9.2.4/package.db

Also if I copy the $CABAL_CONFIG file and modify it to add the same path that also works:

[nix-shell:~/iohk/bug-repros/haskell.nix/2022/08/924-packagedb-1608]$ cat $CABAL_CONFIG
package-db: clear
package-db: global
package-db: /nix/store/w1hy5nrhl0cgj9bsrf5rfplgnd0dmkl0-ghc-shell-for-packages-config/lib/ghc-9.2.4/package.conf.d
write-ghc-environment-files: never

[nix-shell:~/iohk/bug-repros/haskell.nix/2022/08/924-packagedb-1608]$ cat cabal.config
package-db: clear
package-db: global
package-db: /Users/hamish/.cabal/store/ghc-9.2.4/package.db
package-db: /nix/store/w1hy5nrhl0cgj9bsrf5rfplgnd0dmkl0-ghc-shell-for-packages-config/lib/ghc-9.2.4/package.conf.d
write-ghc-environment-files: never

[nix-shell:~/iohk/bug-repros/haskell.nix/2022/08/924-packagedb-1608]$ CABAL_CONFIG=cabal.config cabal build
Up to date

I think we should try to find a good way to add this cabal store path to the generated CABAL_CONFIG file. We might need to do it in the shellHook though since it will depend on $HOME (and we can't get this in a nix derivation).

It's not pretty, but try adding this to the shellHook:

OLD_CABAL_CONFIG=$CABAL_CONFIG
export CABAL_CONFIG=$(mktemp -d)/cabal.config
cp $OLD_CABAL_CONFIG $CABAL_CONFIG
chmod +w $CABAL_CONFIG
echo package-db: $HOME/.cabal/store/ghc-$(ghc --numeric-version)/package.db >> $CABAL_CONFIG

@ramirez7
Copy link
Contributor Author

That does work. The main downside is it does slowly but surely leak tmp files with each nix-shell.

I rigged up this shell.nix that seems to fix it but puts the HOME-dependent cabal.config file in the Nix store so it is cached:

https://gitlab.com/ramirez7/bug-repros/-/blob/26235b76a16ed78a3e1b894f2959ac085d4888e7/haskell.nix/2022/08/924-packagedb-1608/shell.nix

It's a little weird since I didn't know a good way to get my hands on where the original config file was. I ended up creating a default shellFor, derive the new cabal config from its configFiles, and then make a new shellFor that used this file in its shellHook. It felt like a case where an override of some kind would make sense, but I didn't see one that would work in the resulting derivation.

@hamishmack
Copy link
Collaborator

Another option is to exclude monad-fault from the list of packages to be built in the shell. Then in the shell use a .project file that does not include the source-repository-package so that cabal will pick the version in the haskell.nix provided package db.

diff --git a/haskell.nix/2022/08/924-packagedb-1608/shell.nix b/haskell.nix/2022/08/924-packagedb-1608/shell.nix
index ac495d7..1e9da95 100644
--- a/haskell.nix/2022/08/924-packagedb-1608/shell.nix
+++ b/haskell.nix/2022/08/924-packagedb-1608/shell.nix
@@ -7,4 +7,5 @@ in (import ./default.nix).shellFor {
   };
   inherit exactDeps;
   withHoogle = false;
+  packages = p: [p.ghc924-package-db1608];
 }

Then:

nix-shell
echo 'packages: .' > nix-shell.project
cabal build --project-file=nix-shell.project

@yvan-sraka yvan-sraka added the bug Something isn't working label Sep 20, 2022
@hamishmack hamishmack added the preserved Keep stale bot away label Sep 30, 2022
@janvogt
Copy link
Contributor

janvogt commented Sep 23, 2023

I encountered the same issue with the current version of haskell.nix. The proposed workarounds do work, however they require everyone who clones the repo to do manual work instead of relying on nix and direnv to get a working development environment. This is obviously very unfortunate. Beeing able to develop using cabal and getting the same result when building with nix was a core selling point of haskell.nix to me.

Are there any new developments regarding this? How do others solve working with source-repository-package? I somehow can't imagine beeing only second to encounter this. Am I doing something wrong?

@janvogt
Copy link
Contributor

janvogt commented Sep 23, 2023

This seems to be the core problem: #1367

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working preserved Keep stale bot away
Projects
None yet
Development

No branches or pull requests

4 participants