Has anyone been able to integrate liquidhaskell with nixos?
Asked Answered
P

1

6

I'm trying to use liquidhaskell on NixOS. I can install the package (liquidhaskell-0.8.2.3), though not the cabal integration, because it requires cabal 1.18-1.25, but I have cabal 2.0.1.0 .

I have installed the liquidhaskell package as part of a ghc-with-packages setup:

[~:0]$ readlink $( type -p liquid )
/nix/store/pdbzl0p6k1klmajx969b6vvwyw9w0s6b-ghc-8.2.2-with-packages/bin/liquid

Among many others, the package text also installed in this set:

[proclib:1]$ ls -ld /nix/store/pdbzl0p6k1klmajx969b6vvwyw9w0s6b-ghc-8.2.2-with-packages/lib/ghc-8.2.2/text-1.2.2.2/
dr-xr-xr-x 3 root root 68 Jan  1  1970 /nix/store/pdbzl0p6k1klmajx969b6vvwyw9w0s6b-ghc-8.2.2-with-packages/lib/ghc-8.2.2/text-1.2.2.2/

However, liquid cannot see this:

[proclib:1]$ liquid ~/bin/h/nix.hs 
LiquidHaskell Version 0.8.2.3
Copyright 2013-18 Regents of the University of California. All Rights Reserved.

liquid: Main: Could not find module ‘Data.Text’
Perhaps you meant Data.Set (from containers-0.5.10.2)
Use -v to see a list of the files searched for.

The above is not part of a cabal package (to try to eliminate the cabal thing from the equation).

I've tried playing with nix-shell to make this work, but either nix-shell or liquid break down on language pragmas:

[~:0]$ nix-shell -p myHaskellEnv --run liquid ~/bin/h/nix.hs 
/nix/store/q1cwqhb6v8yx8vy4s5p6sxrq8s0bnqmy-nix.hs: line 5: {-#: command not found

Any help gratefully received.

Pastoralize answered 6/3, 2018 at 12:3 Comment(1)
The last error is actually from bash trying to run your haskell sources as though it were a shell script. Quoting the command should fix that: --run "liquid ~/bin/h/nix.hs"Austreng
A
1

The problem seems to be that liquid haskell ignores the ghcWithPackages wrappers, because it uses the GHC API directly. You can work around this as follows, based on this thread.

nix-shell -p 'haskellPackages.ghcWithPackages(pkgs:[pkgs.text (pkgs.liquidhaskell)])' -p z3 --run 'liquid --ghc-option="-package-db=$(ghc-pkg list | head -n 1)" ./hellotext.hs'

Or somewhat equivalently,

nix-shell -p 'haskellPackages.ghcWithPackages(pkgs:[pkgs.text])' -p z3 -p haskellPackages.liquidhaskell --run 'NIX_GHC_LIBDIR=$(ghc-pkg list | head -n 1)/.. liquid ./hellotext.hs'

which suggests that it will work out of the box when you're in a nix-shell based on a cabal2nix package.

Austreng answered 6/3, 2018 at 15:16 Comment(3)
Thank you very much. That seems to work. As a side note, the use with a cabal2nix package isn't working for me, because NIX_GHC_LIBDIR isn't being set - something seems to have changed there.Pastoralize
You're welcome. I didn't expect that, but it should work on the current unstable channel though: cd someproject; nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/cc4677c36ee8d880e881459ad114fd2224b3ac1c.tar.gz --run 'echo NIX_GHC_LIBDIR is $NIX_GHC_LIBDIR'Austreng
cheers. Actually, it wasn't the channel that was at fault; I had a rogue shell.nix; I was trynig to fix my default.nix, but blanking that i had a shell.nix that was breaking me.Pastoralize

© 2022 - 2024 — McMap. All rights reserved.