【问题标题】:Can't build hzk (haskell zookeeper) with nix in stack project无法在堆栈项目中使用 nix 构建 hzk(haskell zookeeper)
【发布时间】:2020-07-22 20:32:23
【问题描述】:

我正在尝试将我雇主的大型 Haskell 堆栈项目移植到 nix 上,但它对 zookeeper_mt 表示不满。在 stack.yaml 中,我启用了 nix 构建,并且已经添加了一些 nix 包,如 zlib 来解决构建错误,但即使使用 zookeeper_mt,我也得到:

hzk                             > configure
hzk                             > Configuring hzk-2.1.0...
hzk                             > Warning: 'ghc-options: -rtsopts' has no effect for libraries. It should only
hzk                             > be used for executables.
hzk                             > build
hzk                             > Preprocessing library for hzk-2.1.0..
hzk                             > /run/user/1000/stack-4c469d140762b8b0/hzk-2.1.0/CApi.hsc:76:10: fatal error: zookeeper.h: No such file or directory
hzk                             > compilation terminated.
hzk                             > compiling .stack-work/dist/x86_64-linux-nix/Cabal-3.0.1.0/build/Database/Zookeeper/CApi_hsc_make.c failed (exit code 1)
hzk                             > command was: /nix/store/za1rr3fxmgfbfl6nbigqi819m3m7nkgi-gcc-wrapper-9.3.0/bin/cc -c .stack-work/dist/x86_64-linux-nix/Cabal-3.0.1.0/build/Database/Zookeeper/CApi_hsc_make.c -o .stack-work/dist/x86_64-linux-nix/Cabal-3.0.1.0/build/Database/Zookeeper/CApi_hsc_make.o -fuse-ld=gold -D__GLASGOW_HASKELL__=808 -Dlinux_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -I/usr/include/zookeeper -I/nix/store/fn0kwfwaf53638xm37wl94la8dxlbjaq-zlib-1.2.11-dev/include -I/nix/store/in9vak3zphkx9c635iz639iabgrib2fl-postgresql-11.8/include -I/nix/store/qsarmp3rsyvhb7m22xl0fdpsnaf3lv6b-pcre-8.44-dev/include -I/nix/store/87w0n6hix0had2lp58i5rgmrr5dn3ghf-pkg-config-wrapper-0.29.2/include -I/nix/store/v1v3flnwxs3n5lhfrfrs16rcygjzzhmy-zookeeper-3.4.13/include -I/nix/store/grng8b5wmrppx2rmcsqkmjyq23bj1j38-zookeeper_mt-3.4.13/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/include -I/nix/store/pj43dfd5k4zb0ivafkyqpr1blzd616ry-git-2.27.0/include -I/nix/store/za1rr3fxmgfbfl6nbigqi819m3m7nkgi-gcc-wrapper-9.3.0/include -I/nix/store/00lmw45jlcm9ln2vi1rxxdz7cblwk3y6-gmp-6.2.0-dev/include -I/usr/include/zookeeper -I/nix/store/fn0kwfwaf53638xm37wl94la8dxlbjaq-zlib-1.2.11-dev/include -I/nix/store/in9vak3zphkx9c635iz639iabgrib2fl-postgresql-11.8/include -I/nix/store/qsarmp3rsyvhb7m22xl0fdpsnaf3lv6b-pcre-8.44-dev/include -I/nix/store/87w0n6hix0had2lp58i5rgmrr5dn3ghf-pkg-config-wrapper-0.29.2/include -I/nix/store/v1v3flnwxs3n5lhfrfrs16rcygjzzhmy-zookeeper-3.4.13/include -I/nix/store/grng8b5wmrppx2rmcsqkmjyq23bj1j38-zookeeper_mt-3.4.13/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/include -I/nix/store/pj43dfd5k4zb0ivafkyqpr1blzd616ry-git-2.27.0/include -I/nix/store/za1rr3fxmgfbfl6nbigqi819m3m7nkgi-gcc-wrapper-9.3.0/include -I/nix/store/00lmw45jlcm9ln2vi1rxxdz7cblwk3y6-gmp-6.2.0-dev/include -I.stack-work/dist/x86_64-linux-nix/Cabal-3.0.1.0/build/autogen -I.stack-work/dist/x86_64-linux-nix/Cabal-3.0.1.0/build/global-autogen -include .stack-work/dist/x86_64-linux-nix/Cabal-3.0.1.0/build/autogen/cabal_macros.h -I/nix/store/fn0kwfwaf53638xm37wl94la8dxlbjaq-zlib-1.2.11-dev/include -I/nix/store/in9vak3zphkx9c635iz639iabgrib2fl-postgresql-11.8/include -I/nix/store/qsarmp3rsyvhb7m22xl0fdpsnaf3lv6b-pcre-8.44-dev/include -I/nix/store/87w0n6hix0had2lp58i5rgmrr5dn3ghf-pkg-config-wrapper-0.29.2/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/include -I/nix/store/pj43dfd5k4zb0ivafkyqpr1blzd616ry-git-2.27.0/include -I/nix/store/za1rr3fxmgfbfl6nbigqi819m3m7nkgi-gcc-wrapper-9.3.0/include -I/nix/store/00lmw45jlcm9ln2vi1rxxdz7cblwk3y6-gmp-6.2.0-dev/include -I/nix/store/fn0kwfwaf53638xm37wl94la8dxlbjaq-zlib-1.2.11-dev/include -I/nix/store/in9vak3zphkx9c635iz639iabgrib2fl-postgresql-11.8/include -I/nix/store/qsarmp3rsyvhb7m22xl0fdpsnaf3lv6b-pcre-8.44-dev/include -I/nix/store/87w0n6hix0had2lp58i5rgmrr5dn3ghf-pkg-config-wrapper-0.29.2/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/include -I/nix/store/pj43dfd5k4zb0ivafkyqpr1blzd616ry-git-2.27.0/include -I/nix/store/za1rr3fxmgfbfl6nbigqi819m3m7nkgi-gcc-wrapper-9.3.0/include -I/nix/store/00lmw45jlcm9ln2vi1rxxdz7cblwk3y6-gmp-6.2.0-dev/include -I/home/ad/.stack/snapshots/x86_64-linux-nix/dd8fbb08ccfb9e77e9ffdb798576edd8f70b7edca799105b5bc2de70a44535a1/8.8.3/lib/x86_64-linux-ghc-8.8.3/vector-0.12.1.2-AWRYcz9jfa25Avs2q9Jg9V/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/lib/ghc-8.8.3/time-1.9.3/include -I/nix/store/fn0kwfwaf53638xm37wl94la8dxlbjaq-zlib-1.2.11-dev/include -I/nix/store/in9vak3zphkx9c635iz639iabgrib2fl-postgresql-11.8/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/include -I/nix/store/pj43dfd5k4zb0ivafkyqpr1blzd616ry-git-2.27.0/include -I/nix/store/za1rr3fxmgfbfl6nbigqi819m3m7nkgi-gcc-wrapper-9.3.0/include -I/nix/store/00lmw45jlcm9ln2vi1rxxdz7cblwk3y6-gmp-6.2.0-dev/include -I/home/ad/.stack/snapshots/x86_64-linux-nix/dd8fbb08ccfb9e77e9ffdb798576edd8f70b7edca799105b5bc2de70a44535a1/8.8.3/lib/x86_64-linux-ghc-8.8.3/primitive-0.7.0.1-CN4ea3Jrhra6yENuqrDg51/include -I/nix/store/fn0kwfwaf53638xm37wl94la8dxlbjaq-zlib-1.2.11-dev/include -I/nix/store/in9vak3zphkx9c635iz639iabgrib2fl-postgresql-11.8/include -I/nix/store/qsarmp3rsyvhb7m22xl0fdpsnaf3lv6b-pcre-8.44-dev/include -I/nix/store/87w0n6hix0had2lp58i5rgmrr5dn3ghf-pkg-config-wrapper-0.29.2/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/include -I/nix/store/pj43dfd5k4zb0ivafkyqpr1blzd616ry-git-2.27.0/include -I/nix/store/za1rr3fxmgfbfl6nbigqi819m3m7nkgi-gcc-wrapper-9.3.0/include -I/nix/store/00lmw45jlcm9ln2vi1rxxdz7cblwk3y6-gmp-6.2.0-dev/include -I/nix/store/fn0kwfwaf53638xm37wl94la8dxlbjaq-zlib-1.2.11-dev/include -I/nix/store/in9vak3zphkx9c635iz639iabgrib2fl-postgresql-11.8/include -I/nix/store/qsarmp3rsyvhb7m22xl0fdpsnaf3lv6b-pcre-8.44-dev/include -I/nix/store/87w0n6hix0had2lp58i5rgmrr5dn3ghf-pkg-config-wrapper-0.29.2/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/include -I/nix/store/pj43dfd5k4zb0ivafkyqpr1blzd616ry-git-2.27.0/include -I/nix/store/za1rr3fxmgfbfl6nbigqi819m3m7nkgi-gcc-wrapper-9.3.0/include -I/nix/store/00lmw45jlcm9ln2vi1rxxdz7cblwk3y6-gmp-6.2.0-dev/include -I/nix/store/fn0kwfwaf53638xm37wl94la8dxlbjaq-zlib-1.2.11-dev/include -I/nix/store/in9vak3zphkx9c635iz639iabgrib2fl-postgresql-11.8/include -I/nix/store/qsarmp3rsyvhb7m22xl0fdpsnaf3lv6b-pcre-8.44-dev/include -I/nix/store/87w0n6hix0had2lp58i5rgmrr5dn3ghf-pkg-config-wrapper-0.29.2/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/include -I/nix/store/pj43dfd5k4zb0ivafkyqpr1blzd616ry-git-2.27.0/include -I/nix/store/za1rr3fxmgfbfl6nbigqi819m3m7nkgi-gcc-wrapper-9.3.0/include -I/nix/store/00lmw45jlcm9ln2vi1rxxdz7cblwk3y6-gmp-6.2.0-dev/include -I/nix/store/fn0kwfwaf53638xm37wl94la8dxlbjaq-zlib-1.2.11-dev/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/include -I/nix/store/pj43dfd5k4zb0ivafkyqpr1blzd616ry-git-2.27.0/include -I/nix/store/za1rr3fxmgfbfl6nbigqi819m3m7nkgi-gcc-wrapper-9.3.0/include -I/nix/store/00lmw45jlcm9ln2vi1rxxdz7cblwk3y6-gmp-6.2.0-dev/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/lib/ghc-8.8.3/bytestring-0.10.10.0/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/include -I/nix/store/pj43dfd5k4zb0ivafkyqpr1blzd616ry-git-2.27.0/include -I/nix/store/za1rr3fxmgfbfl6nbigqi819m3m7nkgi-gcc-wrapper-9.3.0/include -I/nix/store/00lmw45jlcm9ln2vi1rxxdz7cblwk3y6-gmp-6.2.0-dev/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/lib/ghc-8.8.3/base-4.13.0.0/include -I/nix/store/00lmw45jlcm9ln2vi1rxxdz7cblwk3y6-gmp-6.2.0-dev/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/lib/ghc-8.8.3/integer-gmp-1.0.2.0/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/lib/ghc-8.8.3/include -I/nix/store/l9xqrgxn4z795jivmrmjyanlb6jjq66k-libffi-3.3-dev/include -I/nix/store/qqra09ff0q8vwqicjs20fn1rvn00k6fy-ghc-8.8.3/lib/ghc-8.8.3/include/

我可以在nix-shell -p zookeeper_mt 中看到 zookeeper.h 最终在 ${zookeeper}/include/zookeeper/ 中,但这就像 ubuntu 包也有 /usr/include 的这个 zookeeper 子目录,并且该项目在非 nix 中运行良好安装了该 ubuntu 包的堆栈构建。

我在错误消息-I/nix/store/grng8b5wmrppx2rmcsqkmjyq23bj1j38-zookeeper_mt-3.4.13/include 中看到没有额外的/zookeeper,但我不确定系统的哪个部分对此负责或如何修复它,因为我对nix 很陌生。是 nix 包的问题,​​堆栈的问题,还是其他问题?

【问题讨论】:

    标签: haskell apache-zookeeper nix nixos


    【解决方案1】:

    hzk.cabal 有这样的行

      include-dirs:        /usr/include/zookeeper
    

    这对符合 FHS 的系统很有帮助,只要系统分发包含 zookeeper 库。在/usr/local/opt/* 的本地安装会导致同样的问题。

    Nixpkgs 像 https://github.com/NixOS/nixpkgs/blob/a8a0dfa047d9a96f832ff2be30d004ad5544bd7e/pkgs/development/haskell-modules/configuration-nix.nix#L117-L120 这样解决它,但这并不能转化为 Stack。

    为了让它在堆栈中工作,我们可以使用它的 nix-shell 集成。

    stack.yaml:

    nix:
      packages: [] # Note that specifying both packages: and a shell-file: results in an error.
      shell-file: stack-shell.nix
    

    stack-shell.nix:

    {ghc}:
    let pkgs = import <nixpkgs> {};
    # (side note)
    # If you're pinning nixpkgs, You should probably set
    # NIX_PATH=nixpkgs=... in your real `shell.nix`
    # because that's where stack gets its ghc.
    in
    pkgs.haskell.lib.buildStackProject {
      inherit ghc;
      name = "myEnv";
      buildInputs = [ pkgs.zookeeper_mt ];
      shellHook = ''
        NIX_CFLAGS_COMPILE="-I ${pkgs.zookeeper_mt}/include/zookeeper $NIX_CFLAGS_COMPILE"
      '';
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-25
      • 2019-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-05
      • 1970-01-01
      相关资源
      最近更新 更多