简体   繁体   English

stack --nix build抱怨ghc版本不匹配

[英]stack --nix build complains about ghc version mismatch

When building threepenny-gui on NixOS with stack --nix build , I got error saying I have the wrong version of ghc. 使用stack --nix build在NixOS上构建threepenny-gui时,我得到错误,说我的ghc版本错误。 Then I tried stack --nix setup , which doesn't run because bash is on an unexpected path on NixOS (that's expected, since the stack documentation only mentions stack --nix build not setup ). 然后我尝试了stack --nix setup ,它没有运行,因为bash在NixOS上的意外路径上(这是预期的,因为堆栈文档只提到stack --nix build not setup )。 What am I missing? 我错过了什么?

FYI, to deal with the zlib issues I have also added a shell.nix and default.nix per https://github.com/commercialhaskell/stack/issues/2130 仅供参考,为了解决zlib问题,我还添加了一个shell.nix和default.nix,每个https://github.com/commercialhaskell/stack/issues/2130

EDIT: was able to build with the method suggested by mkkeankylej from the above link, ie editing ~/.stack/config.yaml and add zlib to buildInputs in shell.nix But I'd still like to know if there's a way to do it w/o falling back to nix-shell? 编辑:能够使用mkkeankylej从上面的链接建议的方法构建,即编辑~/.stack/config.yaml并将zlib添加到buildInputs中的buildInputs但是我仍然想知道是否有办法做它没有回落到nix-shell? It sounds like stack --nix build should work as long as the nix-shell method does. 听起来像stack --nix build应该只要nix-shell方法可以工作。

First of all, threepenny-gui seems to provide no stack.yaml , ie the project isn't configured to be built with stack . 首先, threepenny-gui似乎没有提供stack.yaml ,即项目没有配置为使用stack构建。 Thus, I wonder why you even bother using stack since that is not going to be any easier than building the project with cabal-install or even Nix directly. 因此,我想知道为什么你甚至打扰使用stack因为这不比使用cabal-install甚至直接使用Nix构建项目更容易。 The easiest and fastest way is probably to configure the build by running: 最简单,最快捷的方法可能是通过运行来配置构建:

$ nix-shell "<nixpkgs>" -A haskellPackages.threepenny-gui.env --run "cabal configure"

Afterwards, you can simply "cabal build" the project and work with it (inside or outside of a nix-shell ) as you please; 之后,您可以根据需要简单地“建立”项目并使用它(在nix-shell内部或外部); the compiler and all necessary build dependencies are provided by Nix. 编译器和所有必要的构建依赖项由Nix提供。

If you don't want that, then you can use the normal cabal-install approach: 如果您不想这样,那么您可以使用正常的cabal-install方法:

$ cabal sandbox init
$ cabal install --only-dependencies
$ cabal configure
$ cabal build

That build is probably going to require system libraries, like libz , so you must make sure that those are available. 该构建可能需要系统库,如libz ,因此您必须确保这些库可用。 There's a million different ways to accomplish that, but the cleanest IMHO is the following: 有一百万种不同的方法可以实现这一目标,但最干净的恕我直言如下:

$ zlibinc=$(nix-build --no-out-link "<nixpkgs>" -A zlib.dev)
$ zliblib=$(nix-build --no-out-link "<nixpkgs>" -A zlib.out)
$ cabal install --only-dependencies --extra-include-dirs=$zlibinc --extra-lib-dirs=$zliblib

Last but not least, it's not obvious to me why your stack build --nix command won't succeed, because that command will use Nix to install the proper version of GHC automatically. 最后但并非最不重要的是,对我来说,为什么你的stack build --nix命令不会成功,这是stack build --nix ,因为该命令将使用Nix自动安装正确版本的GHC。 So if that doesn't work, then my best guess is that you're using an old version of stack where that feature doesn't work properly. 因此,如果这不起作用,那么我最好的猜测是你使用旧版本的stack ,但该功能无法正常工作。 I've tried that build using the stack binary that Nix provides, stack 1.3.2, and it can compile a current git checkout of threepenny-gui just fine: 我已经尝试使用Nix提供的stack二进制构建,堆栈1.3.2,并且它可以编译当前git checkout of threepenny-gui就好了:

$ git clone git://github.com/HeinrichApfelmus/threepenny-gui.git
Cloning into 'threepenny-gui'...
remote: Counting objects: 4102, done.        
remote: Total 4102 (delta 0), reused 0 (delta 0), pack-reused 4101        
Receiving objects: 100% (4102/4102), 1.88 MiB | 581.00 KiB/s, done.
Resolving deltas: 100% (2290/2290), done.

$ cd threepenny-gui
$ stack init
Looking for .cabal or package.yaml files to use to init the project.
Using cabal packages:
- threepenny-gui.cabal

Selecting the best among 9 snapshots...

* Partially matches lts-7.16
    websockets-snap not found
        - threepenny-gui requires >=0.8 && <0.11
    Using package flags:
        - threepenny-gui: buildexamples = False, network-uri = True, rebug = False

* Matches nightly-2017-01-17

Selected resolver: nightly-2017-01-17
Initialising configuration using resolver: nightly-2017-01-17
Total number of user packages considered: 1
Writing configuration to file: stack.yaml
All done.
$ stack build --nix --nix-packages zlib
threepenny-gui-0.7.1.0: configure (lib)
Configuring threepenny-gui-0.7.1.0...
threepenny-gui-0.7.1.0: build (lib)
Preprocessing library threepenny-gui-0.7.1.0...
[...]
Registering threepenny-gui-0.7.1.0...

This works without any specially edited config files for nix-shell , nor does it require special customization of stack . 这适用于没有任何专门编辑的nix-shell配置文件,也不需要特殊的stack定制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM