【问题标题】:stack build error: attribute ‘ghc822’ missing, at (string):1:53堆栈构建错误:缺少属性“ghc822”,在(字符串):1:53
【发布时间】:2018-06-03 15:17:02
【问题描述】:

我正在尝试在 NixOS 上构建我的 haskell 项目。

运行$ stack build 会出现以下错误。

$ stack build
error: attribute ‘ghc822’ missing, at (string):1:53
(use ‘--show-trace’ to show detailed location information)

此错误是什么意思,我该如何继续?当我按照建议运行$ 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

我尝试将我的频道更改为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

$ 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

我通过$ nix-env -iA nixos.haskell.compiler.ghc822 安装了ghc8.2.2$ ghc --version 现在返回

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.2.2

但是,我在尝试运行 $ stack build 时仍然收到错误 error: attribute ‘ghc822’ missing, at (string):1:54

此外,我试图查看我的stack 在安装后使用的ghc 版本,这导致了同样的attribute ‘ghc822’ missing 错误。

$ stack ghc -- --version
error: attribute ‘ghc822’ missing, at (string):1:54
(use ‘--show-trace’ to show detailed location information)

【问题讨论】:

  • 尝试运行nix-env -qaPA 'nixos.haskell.compiler',看看是否找到8.2.2。我正在使用nixos-unstable,我有ghc822
  • @wizzup 该命令的输出确实显示ghc822(已编辑问题以显示该命令的输出)。
  • 那我就不知道了。您可以尝试将--nix 添加到堆栈命令中。例如,stack --nix build

标签: haskell-stack nixos


【解决方案1】:

您的堆栈似乎想要检索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>

同时运行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

【讨论】:

  • 我的 nix-channelnixos-unstable。为了更好地衡量,我按照这些说明将其更改为nixos-17.09(并运行nix-channel --update),但仍然出现相同的错误。
  • nix-env -qaP '*' --description的结果中搜索ghc我没有看到ghc-8.2.2(只有ghc-8.0.2)。
  • 也许对nixpkgs的引用是通过其他方式进行的,比如stack.yaml中的nix/path变量,或者nix/shell-file?见github.com/commercialhaskell/stack/blob/master/doc/…
  • 我在stack.yaml 中将resolver: lts-10.2 替换为lts-9.1 以解决此问题。
【解决方案2】:

另一种选择是使用shell.nixnixos-18.03 自带 ghc 8.2.2,所以你可以创建一个shell.nix like:

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> ];
}

并将以下内容添加到您的stack.yaml

nix:
  shell-file: shell.nix

然后像往常一样stack build

【讨论】:

    【解决方案3】:

    您可以使用项目根目录中的 shell.nix 文件位置提供旧 GHC 版本:

    with import (fetchTarball https://github.com/NixOS/nixpkgs/archive/83b35508c6491103cd16a796758e07417a28698b.tar.gz) {};
    let ghc = haskell.compiler.ghc802;
    in haskell.lib.buildStackProject {
        inherit ghc;
        name = "myEnv";
        buildInputs = [ pcre ];
    }
    

    使用来自https://github.com/NixOS/nixpkgs/releases 的 tar url 获取包含您需要的 GHC 版本的 nixpkgs 版本。

    然后在项目的根目录下运行nix-shell。这将使您进入一个 shell,您可以在其中成功执行 stack build,因为它可以访问正确的 GHC 版本。

    【讨论】:

      【解决方案4】:

      正如 palik 评论的那样,更改解析器版本——在我的情况下更改

      resolver: lts-11.3

      resolver: lts-9.1

      stack.yaml 是一种解决方法。我不知道更深层次的问题是什么,但我很想知道。

      【讨论】:

      • 我遇到了类似的问题,和你一样,将我的 resolver 从我的情况下的 nightly-2018-05-21 更改为 lts-11.15 也修复了它。谢谢!
      • 如果您无法确定要设置的解析器,您可以尝试stack config set resolver lts,如下所述:docs.haskellstack.org/en/stable/faq/…
      【解决方案5】:

      基于@steve-chávez 的回答

      stack.yaml

      resolver: lts-13.19
      system-ghc: true
      install-ghc: false
      
      nix:
        enable: true
        path: [nixpkgs=./nix/nixpkgs/default.nix]
        shell-file: shell.nix
      

      nix/nixpkgs/default.nix

      let
        spec = builtins.fromJSON (builtins.readFile ./revision.json);
      
        src = import <nix/fetchurl.nix> {
          url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz";
          inherit (spec) sha256;
        };
        nixcfg = import <nix/config.nix>;
      
        nixpkgs = builtins.derivation {
          system = builtins.currentSystem;
          name = "${src.name}-unpacked";
          builder = builtins.storePath nixcfg.shell;
          inherit src;
          args = [
            (builtins.toFile "builder" ''
              $coreutils/mkdir $out
              cd $out
              $gzip -d < $src | $tar -x --strip-components=1
            '')
          ];
          coreutils = builtins.storePath nixcfg.coreutils;
          tar = builtins.storePath nixcfg.tar;
          gzip = builtins.storePath nixcfg.gzip;
        };
      in
        import nixpkgs
      

      nix/nixpkgs/update.sh

      #!/usr/bin/env nix-shell
      #!nix-shell -i bash -p nix curl jq
      
      SCRIPT_DIR=$(dirname "$(readlink -f "$BASH_SOURCE")")
      
      owner="nixos"
      repo="nixpkgs-channels"
      rev="nixos-unstable"
      
      full_rev=$(curl --silent https://api.github.com/repos/$owner/$repo/git/refs/heads/$rev | jq -r .object.sha)
      
      echo "full_rev=$full_rev"
      
      expected_sha=$(nix-prefetch-url https://github.com/$owner/$repo/archive/$full_rev.tar.gz)
      
      cat >"$SCRIPT_DIR/revision.json" <<EOL
      {
        "owner":  "$owner",
        "repo":   "$repo",
        "rev":    "$full_rev",
        "sha256": "$expected_sha"
      }
      EOL
      

      shell.nix

      {
        #
        # there are 2 ways of using stack with nix
        # - define custom packages in `stack.yaml` `packages` option (https://docs.haskellstack.org/en/stable/nix_integration/#additions-to-your-stackyaml)
        # - define custom package in `shell.nix` AND `shell-file: ...` in `stack.yaml` (https://docs.haskellstack.org/en/stable/nix_integration/#additions-to-your-stackyaml)
        #
        # we are using second option
      
        ghc # stack expect this file to define a function of exactly one argument that should be called ghc
      }:
      
      
      let
        # pkgs = import ./nix/nixpkgs/default.nix {}
        pkgs = import <nixpkgs> {};
      in
      
      with pkgs;
      
      haskell.lib.buildStackProject {
        inherit ghc;
        name = "myEnv";
        buildInputs = [ cabal-install ];
      }
      

      【讨论】:

        猜你喜欢
        • 2018-05-29
        • 2021-10-16
        • 1970-01-01
        • 1970-01-01
        • 2023-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-26
        相关资源
        最近更新 更多