代码之家  ›  专栏  ›  技术社区  ›  mherzl

堆栈生成错误:缺少属性ghc822,位于(字符串):1:53

  •  12
  • mherzl  · 技术社区  · 8 年前

    跑步 $ 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
    

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

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

    然而,我仍然得到了错误 error: attribute ‘ghc822’ missing, at (string):1:54 尝试运行时 $堆栈构建 .

    我还想看看 ghc 版本我的 stack 安装后正在使用,这导致了相同的 attribute ‘ghc822’ missing 错误

    $ stack ghc -- --version
    error: attribute ‘ghc822’ missing, at (string):1:54
    (use ‘--show-trace’ to show detailed location information)
    
    5 回复  |  直到 8 年前
        1
  •  7
  •   Robert Hensing Nguyen Hoang Hiep    7 年前

    看起来您的堆栈想要检索 haskell.packages.ghc822 属性或可能 haskell.compiler.ghc822 ,您的版本中不存在 <nixpkgs> .

    请使用检查频道配置 sudo nix-channel --list (尼克松)或 nix-channel --list <nixpkgs> 至17.09,记下频道名称并运行

    nix-channel --add https://nixos.org/channels/nixos-17.09 <NAME>
    

    同时运行 nix-channel --update 以确保您拥有最新版本。10月31日增加了GHC 8.2.2。

    如果您不想更改频道配置,我想您可以设置 NIX_PATH 环境变量

    NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz stack build
    
        2
  •  5
  •   Steve Chavez    7 年前

    另一种选择是使用 shell.nix . 尼克松-18.03 随附 ghc 8.2.2 ,以便您可以创建 例如:

    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
  •  3
  •   Răzvan Flavius Panda    6 年前

    您可以使用 shell.nix 文件放置在项目根目录中:

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

    使用来自的tar url https://github.com/NixOS/nixpkgs/releases 对于包含所需GHC版本的nixpkgs版本。

    然后运行 nix-shell stack build 成功,因为它可以访问正确的GHC版本。

        4
  •  1
  •   mherzl    4 年前

    正如palik所评论的,更改解析器版本——在我的例子中,更改

    resolver: lts-11.3

    resolver: lts-9.1

    在里面 stack.yaml 是一种变通方法。我不知道更深层次的问题是什么,但我很想知道。


    更新: this post 提供了有关如何协调使用堆栈和nix的详细说明和优秀提示,包括如何在堆栈解析器的包版本和nix通道之间达成一致。


    如何知道在堆栈中指定哪个解析器。亚马尔?

    转到此url,其中显示包含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
    

    在该页面上查找“8.10.7”显示 LTS Haskell 18.28 (ghc-8.10.7) . 所以我要具体说明 resolver: lts-18.28 在我的 堆栈亚马尔 .

    (如何查找给定包的解析程序在答案中找到 here .)

        5
  •  0
  •   srghma    7 年前

    基于@steve chvez答案

    堆栈亚马尔

    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/默认值。尼克斯

    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/更新。上海

    #!/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
    

    壳尼克斯

    {
      #
      # 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 ];
    }
    
    推荐文章