Haskell/cabal 包的变通方法与 Nix 和 Cabal 的约束?

Workarounds for Haskell / cabal packages with constraints with Nix and Cabal?

我最近开始使用 reflex-platform, with some extra configuration similar to what is described in the excellent reflex-project-skeleton 进行开发。

现在我遇到了无法解决的程序包冲突。 我使用与 reflex-project-skeleton 相同的 cabal 脚本,它在非交互模式下使用 cabal 命令调用 nix-shell

如果我尝试

./cabal new-build --allow-newer all

我明白了

these derivations will be built:
  /nix/store/d6ji516i7pry5l6gv18y6hpj9k1bvgg5-heist-1.0.1.0.drv
  /nix/store/zj1clks7mzq8gn91ahhwa3nvpi5rwra9-snap-1.0.0.2.drv
  /nix/store/mx861972jnjabn7yxyr3y3q1yhf25jfq-snaplet-acid-state-0.2.7.drv
  /nix/store/grhp4dhavmpi6bgns5a6vdzg8ny2bsf8-hoogle-local-0.1.drv
  /nix/store/y3sszsj58f6ad3r06540w0mlr1pncd59-ghc-8.0.2-with-packages.drv

...

Configuring heist-1.0.1.0...
Setup: Encountered missing dependencies:
aeson >=0.6 && <1.2

builder for '/nix/store/d6ji516i7pry5l6gv18y6hpj9k1bvgg5-heist-1.0.1.0.drv' failed with exit code 1
cannot build derivation '/nix/store/y3sszsj58f6ad3r06540w0mlr1pncd59-ghc-8.0.2-with-packages.drv': 1 dependencies couldn't be built

有问题的包似乎是 snaplet-acid-state,所以我尝试从 nix-shell:

中安装它
cabal install snaplet-acid-state
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: snaplet-acid-state-0.2.7 (user goal)
trying: base-4.9.1.0/installed-4.9... (dependency of snaplet-acid-state-0.2.7)
next goal: mtl (dependency of snaplet-acid-state-0.2.7)
rejecting: mtl-2.2.1/installed-BLK... (conflict: mtl =>
transformers==0.5.2.0/installed-0.5..., snaplet-acid-state =>
transformers>=0.3.0.0 && <0.5)
trying: mtl-2.2.2
next goal: transformers (dependency of snaplet-acid-state-0.2.7)
rejecting: transformers-0.5.2.0/installed-0.5..., transformers-0.5.5.0,
transformers-0.5.4.0, transformers-0.5.2.0, transformers-0.5.1.0,
transformers-0.5.0.1, transformers-0.5.0.0 (conflict: snaplet-acid-state =>
transformers>=0.3.0.0 && <0.5)
rejecting: transformers-0.4.3.0, transformers-0.4.2.0 (conflict:
base==4.9.1.0/installed-4.9..., transformers => base>=2 && <4.9)
rejecting: transformers-0.4.1.0 (conflict: base==4.9.1.0/installed-4.9...,
transformers => base>=2 && <4.8 || >=1.0 && <2)
rejecting: transformers-0.3.0.0 (conflict: mtl => transformers>=0.4 && <0.6)
rejecting: transformers-0.2.2.1, transformers-0.2.1.0, transformers-0.2.0.0,
transformers-0.1.4.0, transformers-0.1.3.0, transformers-0.1.1.0,
transformers-0.1.0.1, transformers-0.0.1.0, transformers-0.0.0.0,
transformers-0.5.3.1, transformers-0.5.3.0, transformers-0.5.0.2 (conflict:
snaplet-acid-state => transformers>=0.3.0.0 && <0.5)
rejecting: transformers-0.4.0.0 (conflict: base==4.9.1.0/installed-4.9...,
transformers => base>=2 && <4.8 || >=1.0 && <2)
rejecting: transformers-0.2.2.0, transformers-0.1.0.0 (conflict:
snaplet-acid-state => transformers>=0.3.0.0 && <0.5)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: transformers, snap, base,
snaplet-acid-state, mtl

尝试在 cabal 文件中指定版本约束等,但没有效果。

有线索吗?我什至不确定确切的问题是什么。为什么aeson第一次安装失败,第二次snaplet-acid-state和mtl有冲突?

cabal2nix 工作流发生的情况是,基本上依赖项解决程序被迫只考虑 Nixpkgs 提供的包,或者在本例中为 reflex-platform + Nixpkgs。通过取消选择多个版本之一的自由,Cabal 依赖项解决程序被简化为依赖项 checker.

现在,如果版本绑定太严格,你可以考虑 Nixpkgs 中所谓的 'jailbreaking':从 cabal 文件中删除所有版本绑定。另一个选项是更改包版本。

加布里埃尔·冈萨雷斯 (Gabriel Gonzalez) 撰写了 a good explanation of version management with Nixpkgs' Haskell infrastructure. You may also check out this thread。它有点冗长,但它讨论了非常有用的 callHackagecallCabal2nix 函数。