我如何安装Haskell库以通过带有Nixos的GHCi访问? [英] How can I install a Haskell library to be accessible via GHCi with Nixos?

查看:104
本文介绍了我如何安装Haskell库以通过带有Nixos的GHCi访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法用nix-env -i ghc安装ghc.

我现在想安装Haskell库,该怎么办?例如turtle( https://hackage.haskell.org/package/turtle )库.

I'd like to install a Haskell library now, how should this be done? For example the turtle (https://hackage.haskell.org/package/turtle) library.

我已经运行nix-env -f "<nixpkgs>" -iA haskellPackages.turtle,但是运行ghciimport Turtle失败:

I've run nix-env -f "<nixpkgs>" -iA haskellPackages.turtle, however running ghci and import Turtle fails:

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安装的软件包.

This works differently on NixOS because of purity. NixOS' GHC will only look at its own immutable installation directory and the packages that have been installed by the user with cabal install.

您可以做的是在用户配置文件中安装GHC包装器,当您运行ghci时,该包装器会提供一组不错的软件包.

What you can do is install into your user profile a GHC wrapper that supplies a nice set of packages when you run ghci.

创建文件my-ghc.nix:

(import <nixpkgs> {}).haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [
    lens
    aeson
    turtle
])

卸载先前的尝试,以避免名称冲突:

Uninstall your previous attempt, to avoid name collisions:

nix-env -e ghc turtle

安装包装好的GHC:

nix-env -if my-ghc.nix

您将来可能会编辑该文件,然后重新运行该命令.

You may edit the file in the future and re-run that command.

在处理项目时,我更喜欢使用cabal2nixnix-shell. (有关简介,请参见 Oliver查尔斯的博客文章)

When I am working on a project, I prefer to use cabal2nix and nix-shell. (For an introduction, see Oliver Charles' blog post)

这篇关于我如何安装Haskell库以通过带有Nixos的GHCi访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆