![](/img/trans.png)
[英]Can I replicate what nix-build does with nix-shell and cabal build?
[英]Cabal tries to build unknown package when building with alex, happy in nix-shell
我目前正在嘗試使用 nix-shell 和 cabal 構建一個 Haskell 項目,並使用 alex 和 happy 作為構建工具。 在nix-shell內部構建(有和沒有--pure
),我收到以下奇怪的錯誤消息:
cabal: Could not resolve dependencies:
[__0] trying: aoc-0.1.0.0 (user goal)
[__1] unknown package: aoc:happy:exe.happy (dependency of aoc)
[__1] fail (backjumping, conflict set: aoc, aoc:happy:exe.happy)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: aoc, aoc:happy:exe.happy
它似乎試圖滿足一些無意義的依賴aoc:happy:exe.happy
,盡管在 cabal 文件中沒有提到這樣的東西。 在 nix-shell 中,我可以直接將alex
和happy
作為可執行文件運行,因為它們是由 nix 提供的。
問題:有誰知道我可以嘗試解決這個問題嗎? 我想嘗試完全使用 nix 提供依賴項,而不是使用cabal update
從 Hackage 下載包。
可以在unhappy
here的分支中找到源代碼,其中包含感興趣的文件:
到目前為止我嘗試過的一些事情是:
我在這里發現了一個類似的錯誤,但它沒有完全解決,並且那里的 nix 版本使用了 haskell.nix 。
在進行故障排除時,我嘗試了以下其他構建方法:
使用通過ghcup安裝的 cabal/ghc 構建(cabal 3.2.0.0,ghc 8.10.2):構建成功 - 從 Hackage 獲取 alex 和 happy 並作為build-tools
成功運行。
使用nix-build 構建:構建成功運行(沒有將包提取到.cabal)。 callCabal2nix
識別出 alex 和 happy,並成功地將它們提供給 cabal。
使用cabal update
在nix-shell中構建:與 1. 相同,並且成功,因為 nix 提供的 cabal 從 Hackage 獲取包,但這不是我想要完成的。
我還嘗試使用 nix-shell 構建一個最小的示例 alex/happy 項目,使用我自己項目中相同的通用 *.nix 文件,並產生相同的錯誤。
Cabal 根本不相信alex
是由 Nixpkgs 的自定義 Haskell 環境(您正確用於 shell 的 package 上的.env
屬性)安裝的。
如果您運行cabal update
, cabal-install 將能夠安裝alex
並以它想要的方式happy
並繼續構建您的項目。
$ cabal v2-build
[... omitted ...]
[__0] trying: aoc-0.1.0.0 (user goal)
[__1] unknown package: aoc:happy:exe.happy (dependency of aoc)
[__1] fail (backjumping, conflict set: aoc, aoc:happy:exe.happy)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: aoc, aoc:happy:exe.happy
$ cabal update
Downloading the latest package list from hackage.haskell.org
$ cabal v2-build
Resolving dependencies...
Build profile: -w ghc-8.10.2 -O1
In order, the following will be built (use -v for more details):
- alex-3.2.6 (exe:alex) (requires download & build)
- happy-1.20.0 (exe:happy) (requires download & build)
- aoc-0.1.0.0 (lib) (configuration changed)
- aoc-0.1.0.0 (exe:aoc) (dependency rebuilt)
Downloading happy-1.20.0
[... omitted ...]
Configuring library for aoc-0.1.0.0..
Preprocessing library for aoc-0.1.0.0..
Building library for aoc-0.1.0.0..
[... omitted ...]
根據Cabal build-tools
文檔,該字段已被棄用並刪除。 看起來你會更好地使用build-tool-depends
。
build-tool-depends:
alex:alex >=3.2.5 && <3.3
, happy:happy >=1.20.0 && <1.21
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.