为什么堆栈不使用定义的额外依赖项?

Why is stack not using the defined extra dependency?

我提交了对 Haskell 的更改 opaleye project that I need for a project I am working on. The change is in version 0.6.7003.1, which has not propagated to the nixos repository yet (nixos.org 显示其当前版本为 0.6.7001.0)。

由于这个所需的依赖与解析器的 LTS 版本不同,我在 stack.yaml:

中标记了额外的依赖
packages:
- git@github.com:tomjaguarpaw/haskell-opaleye.git
- commit: cf3296c5ffef58d36dd6b386ae53dff519ee47e9

我也在我的 project.cabal 文件的 build-depends 中标记了这个版本:

build-depends: opaleye >= 0.6.7003.1 && < 1

当我随后尝试构建时,出现以下错误:

$ stack build

Error: While constructing the build plan, the following exceptions were encountered:

In the dependencies for taskmaster-0.1.0.0:
    opaleye must match >=0.6.7003.1 && <1, but the stack configuration has no specified version  (latest matching version is 0.6.7003.1)
needed since taskmaster is a build target.

Some different approaches to resolving this:

  * Consider trying 'stack solver', which uses the cabal-install solver to attempt to find some working build configuration. This can be convenient when dealing with many
    complicated constraint errors, but results may be unpredictable.

  * Recommended action: try adding the following to your extra-deps in /home/matthew/backup/taskmaster/taskmaster/stack.yaml:

opaleye-0.6.7003.1@sha256:914ac99c6f7ceea050df843ac31c33be0f6340bc0f05753c8fdfc18074fa9e5b

Plan construction failed.

(我不明白这个长(>40 个字符)的 sha256 散列是从哪里来的)。 我听从了建议并将以下内容添加到我的 stack.yaml.

extra-deps:
- opaleye-0.6.7003.1@sha256:914ac99c6f7ceea050df843ac31c33be0f6340bc0f05753c8fdfc18074fa9e5b

当我 运行 $ stack build 构建我的项目时,编译器尝试构建而不显示任何依赖项错误。但是,如果它使用包含我的更改的 Opaleye 版本,它不会出现类型错误。而且,当我 运行 $ stack ghci 并导入相关的 opaleye 模块时,我的更改不存在。似乎不知何故堆栈仍在使用旧的 opaleye 版本。我怎样才能让堆栈使用包含我的更改的更新版本的 opaleye? 我的尝试似乎已经用尽了 haskell-stack documentation.

中提到的选项

原来stack的extra-deps建议是不正确的。我注意到 this stack github issue 下的另一种格式,试了一下,它碰巧对我有用。下面列出了可用的 extra-deps 格式。

extra-deps:
- github: tomjaguarpaw/haskell-opaleye
  commit: cf3296c5ffef58d36dd6b386ae53dff519ee47e9

hackage 选项通常比 github extra-dep 更好。

您最初尝试的正确语法是

extra-deps:
- git: https://github.com/tomjaguarpaw/haskell-opaleye.git
  commit: cf3296c5ffef58d36dd6b386ae53dff519ee47e9

github: tomjaguarpaw/haskell-opaleye 版本只是一个快捷方式。

sha256 散列是与 opaleye 的那个版本(和修订版)对应的 cabal 文件的 sha256sum。

鉴于 opaleye 的版本是 already on hackage,您应该能够添加 stack 建议的行。您可能希望在进行更改后尝试 stack clean(尽管这不是必需的)。

如果您提供更多信息,我会更新此答案。