devbox icon indicating copy to clipboard operation
devbox copied to clipboard

devbox add ghc && devbox add haskellPackages.aeson does not add aeson to ghc package database

Open ParetoOptimalDev opened this issue 3 years ago • 2 comments

$ devbox add ghc
$ devbox add haskellPackages.aeson
$ devbox shell
$ ghc-pkg list | grep aeson

That should show a package listed. Compare to the nix equivalent:

$ ghc-pkg list | grep aeson
    aeson-1.5.6.0

This lets it be used by ghci for instance:

$ ghci 
GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
Prelude> import Data.Aeson
Prelude Data.Aeson> :t parseJSON
parseJSON
  :: FromJSON a =>
     Value -> aeson-1.5.6.0:Data.Aeson.Types.Internal.Parser a

I kind of expected this not to work, but figured I'd make an issue since I think it'd be nice if people could do this. Especially for things like the lens library with tons of dependencies which really make use of binary caching.

ParetoOptimalDev avatar Aug 28 '22 08:08 ParetoOptimalDev

Thanks for reporting, let me take a look this coming week and see if we can easily fix it.

loreto avatar Aug 28 '22 11:08 loreto

Thanks for reporting, let me take a look this coming week and see if we can easily fix it.

Sure, if it helps my first thought was "Can devbox add haskellPackages.aeson just always rewrite to implicitly be equivalent to nix-shell -p "haskellPackages.ghcWithPackages (p: [p.aeson])" rather than what I'm assuming it's now equivalent to nix-shell -p haskellPackages.aeson.

For haskell in particular this is very useful because the built packages are cached. For things like the cryptonite library that take a long time to compile, this can save you hours.

Where as with the binary cache of cryptonite I can get ghci with cryptonite available in 3.8s:

$ time nix-shell -p "haskellPackages.ghcWithPackages (p: [p.cryptonite])" --run exit
... snip ... 
copying path '/nix/store/nkhj0j7vnvv0810g8zg15fpabvkwlzwy-memory-0.15.0' from 'https://cache.nixos.org'...
copying path '/nix/store/lyll680sx4cpbm2ivabq3abmhyc4z13q-cryptonite-0.29' from 'https://cache.nixos.org'...
building '/nix/store/dw00lxfnhhjnyfip8p6kd20ypcc4248s-ghc-8.10.7-with-packages.drv'...

ParetoOptimalDev avatar Aug 28 '22 21:08 ParetoOptimalDev

Confirmed this is still an issue. I think @ParetoOptimalDev is right that the solution is to rewrite haskellPackages to haskellPackages.ghcWithPackages. I think the implementation would be similar to what we do for PHP Extensions:

https://github.com/hezhizhen/devbox/blob/d71daf33f52a83ce33cf66d7461d59030403b49f/internal/planner/languages/php/php_v2_planner.go#L40

Lagoja avatar Mar 15 '23 17:03 Lagoja