我已成功使用 nix-env -i ghc
安装 ghc .
我现在想安装 Haskell 库,应该如何完成?例如turtle
( https://hackage.haskell.org/package/turtle ) 库。
我已经运行了nix-env -f "<nixpkgs>" -iA haskellPackages.turtle
,但是正在运行ghci
和import Turtle
失败:
Prelude> import Turtle
<no location info>: error:
Could not find module ‘Turtle’
It is not a module in the current program, or in any known package.
ghc-pkg list
的输出:
/nix/store/fvf278s3lqsjv488ahhdi8jx6i0qzsr9-ghc-8.0.2/lib/ghc-8.0.2/package.conf.d
Cabal-1.24.2.0
array-0.5.1.1
base-4.9.1.0
binary-0.8.3.0
bytestring-0.10.8.1
containers-0.5.7.1
deepseq-1.4.2.0
directory-1.3.0.0
filepath-1.4.1.1
ghc-8.0.2
ghc-boot-8.0.2
ghc-boot-th-8.0.2
ghc-prim-0.5.0.0
ghci-8.0.2
haskeline-0.7.3.0
hoopl-3.10.2.1
hpc-0.6.0.3
integer-gmp-1.0.0.1
pretty-1.1.3.3
process-1.4.3.0
rts-1.0
template-haskell-2.11.1.0
terminfo-0.4.0.2
time-1.6.0.1
transformers-0.5.2.0
unix-2.7.2.1
xhtml-3000.2.1
最佳答案
由于纯度的原因,这在 NixOS 上的工作方式有所不同。 NixOS 的 GHC 只会查看自己的不可变安装目录以及用户使用 cabal install
安装的软件包。
您可以做的就是在您的用户配置文件中安装一个 GHC 包装器,该包装器在您运行 ghci
时提供一组不错的软件包。
创建文件my-ghc.nix
:
(import <nixpkgs> {}).haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [
lens
aeson
turtle
])
卸载您之前的尝试,以避免名称冲突:
nix-env -e ghc turtle
安装打包的 GHC:
nix-env -if my-ghc.nix
您可以在将来编辑该文件并重新运行该命令。
当我从事项目时,我更喜欢使用 cabal2nix
和 nix-shell
。 (有关介绍,请参见Oliver Charles' blog post)
关于haskell - 如何安装 Haskell 库以便通过 GHCi 和 Nixos 进行访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47377748/