2017-05-18 35 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