2017-05-18 44 views
2

可能是因为missing module在nix-shell中找不到模块

$ nix-shell -p haskellPackages.ghc -p haskellPackages.random 

给予以下shell

[nix-shell:~]$ ghci 
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help 
Loaded GHCi configuration from /data/works/dotfiles/ghci 
Prelude> import System.Random 

<no location info>: error: 
    Could not find module ‘System.Random’ 
    It is not a module in the current program, or in any known package. 

而且什么是安装和使用哈斯克尔包nix方式?

我以为nixos.haskellPackages.<package>会自动注册为ghc,但它似乎并非如此。

在壳内重新安装random不要修复它。

[nix-shell:~]$ nix-env -iA nixos.haskellPackages.random 
installing ‘random-1.1’ 

[nix-shell:~]$ ghc-pkg list | grep -i random 
+0

使用开发包的尼克斯方式的确是要经过'尼克斯,shell'样你做到了。 Haskell可能存在特定的问题:我建议您阅读nixpkgs手册的[Haskell部分](https://nixos.org/nixpkgs/manual/#users-guide-to-the-haskell-infrastructure)以学到更多。 –

回答

3

我不知道为什么这不起作用的原因。但你可以试试这个命令:

nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [random])" 

适合我。现在ghci看到System.Random包。

UPDATE:

这篇文章是在他们的nix + haskell冒险初学者非常有帮助:

http://alpmestan.com/posts/2017-09-06-quick-haskell-hacking-with-nix.html

+1

此方法仅适用于'ghc',但不适用于'ghc-mod'; '$ nix-shell -p“haskellPackages.ghcWithPackages(self:with self; [random ghc-mod])”';我对nixos haskell系统非常混淆。 – wizzup

+1

我为另一个问题写了一个答案,我解释了为什么它不起作用:https://stackoverflow.com/a/45023011/450128(问题本身并不严格是重复的) – Ben