mhe*_*rzl 8 nixos haskell-stack
我正在尝试在NixOS上构建我的haskell项目.
运行$ stack build会出现以下错误.
$ stack build
error: attribute ‘ghc822’ missing, at (string):1:53
(use ‘--show-trace’ to show detailed location information)
Run Code Online (Sandbox Code Playgroud)
这个错误意味着什么,我该怎么办?当我$ stack build --show-trace按照建议运行时,我得到以下输出,我也不明白.
$ stack build --show-trace
Invalid option `--show-trace'
Usage: stack build [TARGET] [--dry-run] [--pedantic] [--fast]
[--ghc-options OPTIONS] [--flag PACKAGE:[-]FLAG]
([--dependencies-only] | [--only-snapshot] |
[--only-dependencies]) ([--file-watch] | [--file-watch-poll])
[--exec CMD [ARGS]] [--only-configure] [--trace] [--profile]
[--no-strip] [--[no-]library-profiling]
[--[no-]executable-profiling] [--[no-]library-stripping]
[--[no-]executable-stripping] [--[no-]haddock]
[--haddock-arguments HADDOCK_ARGS] [--[no-]open]
[--[no-]haddock-deps] [--[no-]haddock-internal]
[--[no-]haddock-hyperlink-source] [--[no-]copy-bins]
[--[no-]copy-compiler-tool] [--[no-]prefetch]
[--[no-]keep-going] [--[no-]force-dirty] [--[no-]test]
[--[no-]rerun-tests] [--ta|--test-arguments TEST_ARGS]
[--coverage] [--no-run-tests] [--[no-]bench]
[--ba|--benchmark-arguments BENCH_ARGS] [--no-run-benchmarks]
[--[no-]reconfigure] [--[no-]cabal-verbose]
[--[no-]split-objs] [--skip ARG] [--help]
Build the package(s) in this directory/configuration
Run Code Online (Sandbox Code Playgroud)
我尝试将通道nixos-17.09改为nixos-unstable(并运行nix-channel --update),但仍然得到相同的错误.
输出$ nix-channel --list如下所示.
$ nix-channel --list
stack https://nixos.org/channels/nixos-17.09
nixos https://nixos.org/channels/nixos-17.09
Run Code Online (Sandbox Code Playgroud)
$ nix-env -qaPA 'nixos.haskell.compiler'显示的输出显示ghc822.
$ nix-env -qaPA 'nixos.haskell.compiler'
warning: name collision in input Nix expressions, skipping ‘/home/matthew/.nix-defexpr/channels_root/nixos’
nixos.haskell.compiler.ghc6102Binary ghc-6.10.2-binary
nixos.haskell.compiler.ghc704 ghc-7.0.4
nixos.haskell.compiler.ghc704Binary ghc-7.0.4-binary
nixos.haskell.compiler.ghc7102 ghc-7.10.2
nixos.haskell.compiler.integer-simple.ghc7102 ghc-7.10.2
nixos.haskell.compiler.ghc7103 ghc-7.10.3
nixos.haskell.compiler.integer-simple.ghc7103 ghc-7.10.3
nixos.haskell.compiler.integer-simple.ghc742 ghc-7.4.2
nixos.haskell.compiler.ghc742 ghc-7.4.2
nixos.haskell.compiler.ghc742Binary ghc-7.4.2-binary
nixos.haskell.compiler.ghc763 ghc-7.6.3
nixos.haskell.compiler.ghc783 ghc-7.8.3
nixos.haskell.compiler.integer-simple.ghc783 ghc-7.8.3
nixos.haskell.compiler.ghc784 ghc-7.8.4
nixos.haskell.compiler.integer-simple.ghc784 ghc-7.8.4
nixos.haskell.compiler.ghc801 ghc-8.0.1
nixos.haskell.compiler.integer-simple.ghc801 ghc-8.0.1
nixos.haskell.compiler.ghc802 ghc-8.0.2
nixos.haskell.compiler.integer-simple.ghc802 ghc-8.0.2
nixos.haskell.compiler.integer-simple.ghc821 ghc-8.2.1
nixos.haskell.compiler.ghc821 ghc-8.2.1
nixos.haskell.compiler.integer-simple.ghc822 ghc-8.2.2
nixos.haskell.compiler.ghc822 ghc-8.2.2
nixos.haskell.compiler.integer-simple.ghcHEAD ghc-8.3.20170808
nixos.haskell.compiler.ghcHEAD ghc-8.3.20170808
nixos.haskell.compiler.ghcjs ghcjs-0.2.0
nixos.haskell.compiler.ghcjsHEAD ghcjs-0.2.020170323
nixos.haskell.compiler.jhc jhc-0.8.2
nixos.haskell.compiler.uhc uhc-1.1.9.4
Run Code Online (Sandbox Code Playgroud)
我安装了ghc8.2.2via $ nix-env -iA nixos.haskell.compiler.ghc822,$ ghc --version现在返回
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.2.2
Run Code Online (Sandbox Code Playgroud)
但是,我仍然error: attribute ‘ghc822’ missing, at (string):1:54在尝试运行时收到错误$ stack build.
此外,我试图在安装后查看ghc我stack正在使用的版本,这导致了同样的attribute ‘ghc822’ missing错误.
$ stack ghc -- --version
error: attribute ‘ghc822’ missing, at (string):1:54
(use ‘--show-trace’ to show detailed location information)
Run Code Online (Sandbox Code Playgroud)
看起来你的堆栈想要检索haskell.packages.ghc822属性,或者可能haskell.compiler.ghc822是你的版本中没有的<nixpkgs>.
请使用sudo nix-channel --list(NixOS)或检查您的频道配置nix-channel --list.版本17.03及更早版本没有此属性.17.09和不稳定应该没问题.要将默认值切换<nixpkgs>为17.09,请记下通道的名称并运行
nix-channel --add https://nixos.org/channels/nixos-17.09 <NAME>
Run Code Online (Sandbox Code Playgroud)
同时运行nix-channel --update以确保您有最新版本.GHC 8.2.2于10月31日增加.
如果您不想更改频道配置,我想您可以设置NIX_PATH环境变量
NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz stack build
Run Code Online (Sandbox Code Playgroud)
另一种选择是使用shell.nix. nixos-18.03带有ghc 8.2.2,所以你可以创建一个shell.nix喜欢的:
with import (builtins.fetchGit {
url = https://github.com/NixOS/nixpkgs-channels;
ref = "nixos-18.03";
rev = "cb0e20d6db96fe09a501076c7a2c265359982814";
}) {};
haskell.lib.buildStackProject {
name = "my-project";
buildInputs = [ ghc <otherlibs-here> ];
}
Run Code Online (Sandbox Code Playgroud)
并将以下内容添加到您的stack.yaml:
nix:
shell-file: shell.nix
Run Code Online (Sandbox Code Playgroud)
然后stack build像往常一样。
正如 palik 评论的那样,更改解析器版本 - 在我的例子中更改
resolver: lts-11.3
到
resolver: lts-9.1
instack.yaml是一个解决方法。我不知道更深层次的问题是什么,但有兴趣知道。
更新:这篇文章提供了关于如何协同使用 stackage 和 nix 的详尽解释,以及出色的提示,包括如何在 stack 解析器和 nix 通道的包版本之间达成一致。
如何知道在 stack.yaml 中指定哪个解析器?
转到此网址,其中显示包含 ghc 的堆栈快照: https: //www.stackage.org/package/ghc/snapshots
这将告诉您与您拥有的 ghc 版本相对应的解析器。例如,我有 ghc 8.10.7,
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.7
Run Code Online (Sandbox Code Playgroud)
在该页面上查找“8.10.7”显示对应于LTS Haskell 18.28 (ghc-8.10.7). 所以我会resolver: lts-18.28在我的stack.yaml.
(如何找到给定包的解析器可以在此处的答案中找到。)
| 归档时间: |
|
| 查看次数: |
1320 次 |
| 最近记录: |