stack --nix build抱怨ghc版本不匹配 [英] stack --nix build complains about ghc version mismatch

查看:62
本文介绍了stack --nix build抱怨ghc版本不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 stack --nix build 在NixOS上构建threepenny-gui时,出现错误,提示我使用了错误的ghc版本.然后,我尝试了 stack --nix setup ,该命令没有运行,因为bash在NixOS上的意外路径上(这是预期的,因为堆栈文档只提到了 stack --nix build 不是 setup ).我想念什么?

When building threepenny-gui on NixOS with stack --nix build, I got error saying I have the wrong version of 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). What am I missing?

仅供参考,为了处理zlib问题,我还根据 https://github.com/commercialhaskell/stack/issues/2130

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

能够使用mkkeankylej从上面的链接中建议的方法进行构建,即编辑〜/.stack/config.yaml 并将zlib添加到 buildInputs 中shell.nix但是我仍然想知道是否有一种方法可以不退回到nix-shell吗?听起来只要nix-shell方法可以工作, stack --nix build 就可以正常工作.

was able to build with the method suggested by mkkeankylej from the above link, i.e. 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? It sounds like stack --nix build should work as long as the nix-shell method does.

推荐答案

首先, threepenny-gui 似乎没有提供 stack.yaml ,即该项目没有尚未配置为使用 stack 构建.因此,我想知道为什么您甚至还要麻烦使用 stack ,因为与使用 cabal-install 甚至甚至是 Nix 直接.最简单,最快的方法可能是通过运行以下命令来配置构建:

First of all, threepenny-gui seems to provide no stack.yaml, i.e. the project isn't configured to be built with 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. The easiest and fastest way is probably to configure the build by running:

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

然后,您可以根据需要轻松地整体构建"项目并使用它(在 nix-shell 内部或外部);Nix提供了编译器和所有必要的构建依赖项.

Afterwards, you can simply "cabal build" the project and work with it (inside or outside of a nix-shell) as you please; the compiler and all necessary build dependencies are provided by Nix.

如果您不想这样做,则可以使用常规的 cabal-install 方法:

If you don't want that, then you can use the normal cabal-install approach:

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

该版本可能需要系统库,例如 libz ,因此您必须确保这些库可用.有上百万种方法可以实现这一目标,但是最简洁的恕我直言如下:

That build is probably going to require system libraries, like libz, so you must make sure that those are available. 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

最后但并非最不重要的一点是,我不明白为什么您的 stack build --nix 命令不会成功,因为该命令将使用Nix自动安装正确版本的GHC.因此,如果那行不通,那么我最好的猜测是您使用的是旧版本的 stack ,该功能无法正常使用.我已经尝试使用Nix提供的 stack 二进制文件(堆栈1.3.2)进行构建,并且可以很好地编译 threepenny-gui 的当前git checkout:

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. 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. 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:

$ 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...

此功能无需 nix-shell 的任何经过特殊编辑的配置文件,也不需要 stack 的特殊自定义.

This works without any specially edited config files for nix-shell, nor does it require special customization of stack.

这篇关于stack --nix build抱怨ghc版本不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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