【问题标题】:nix-shell --command `stack build` leads to libpq-fe.h: No such file or directorynix-shell --command `stack build` 导致 libpq-fe.h:没有这样的文件或目录
【发布时间】:2016-04-14 03:27:51
【问题描述】:

我正在尝试在 nixos 上编译我的小项目(一个带有 lambdacms 的 yesod 应用程序)。但是,在使用 cabal2nix (更准确地说是 cabal2nix project-karma.cabal --sha256=0 --shell > shell.nix) 之后,我仍然缺少一个依赖 wrt。似乎是postgresql。

我的 shell.nix 文件如下所示:

{ nixpkgs ? import <nixpkgs> {}, compiler ? "default" }:

let

 inherit (nixpkgs) pkgs;

 f = { mkDerivation, aeson, base, bytestring, classy-prelude
      , classy-prelude-conduit, classy-prelude-yesod, conduit, containers
      , data-default, directory, fast-logger, file-embed, filepath
      , hjsmin, hspec, http-conduit, lambdacms-core, monad-control
      , monad-logger, persistent, persistent-postgresql
      , persistent-template, random, resourcet, safe, shakespeare, stdenv
      , template-haskell, text, time, transformers, unordered-containers
      , uuid, vector, wai, wai-extra, wai-logger, warp, yaml, yesod
      , yesod-auth, yesod-core, yesod-form, yesod-static, yesod-test
      }:
      mkDerivation {
        pname = "karma";
        version = "0.0.0";
        sha256 = "0";
        isLibrary = true;
        isExecutable = true;
        libraryHaskellDepends = [
          aeson base bytestring classy-prelude classy-prelude-conduit
          classy-prelude-yesod conduit containers data-default directory
          fast-logger file-embed filepath hjsmin http-conduit lambdacms- core
          monad-control monad-logger persistent persistent-postgresql
          persistent-template random safe shakespeare template-haskell  text
          time unordered-containers uuid vector wai wai-extra wai-logger      warp
          yaml yesod yesod-auth yesod-core yesod-form yesod-static
          nixpkgs.zlib
          nixpkgs.postgresql
          nixpkgs.libpqxx
        ];
        libraryPkgconfigDepends = [ persistent-postgresql];
        executableHaskellDepends = [ base ];
        testHaskellDepends = [
          base classy-prelude classy-prelude-yesod hspec monad-logger
          persistent persistent-postgresql resourcet shakespeare     transformers
          yesod yesod-core yesod-test
        ];
        license = stdenv.lib.licenses.bsd3;
      };

  haskellPackages = if compiler == "default"
                       then pkgs.haskellPackages
                       else pkgs.haskell.packages.${compiler};

  drv = haskellPackages.callPackage f {};

 in

  if pkgs.lib.inNixShell then drv.env else drv

输出如下:

markus@nixos ~/git/haskell/karma/karma (git)-[master] % nix-shell     --command `stack build`
postgresql-libpq-0.9.1.1: configure
ReadArgs-1.2.2: download
postgresql-libpq-0.9.1.1: build
ReadArgs-1.2.2: configure
ReadArgs-1.2.2: build
ReadArgs-1.2.2: install

--  While building package postgresql-libpq-0.9.1.1 using:
      /run/user/1000/stack31042/postgresql-libpq-0.9.1.1/.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/setup/setup --builddir=.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/ build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: /home/markus/git/haskell/karma/karma/.stack-work/logs/postgresql-libpq-0.9.1.1.log

[1 of 1] Compiling Main             ( /run/user/1000/stack31042/postgresql-libpq-0.9.1.1/Setup.hs, /run/user/1000/stack31042/postgresql-libpq-0.9.1.1/.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/setup/Main.o )
Linking /run/user/1000/stack31042/postgresql-libpq-0.9.1.1/.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/setup/setup ...
Configuring postgresql-libpq-0.9.1.1...
Building postgresql-libpq-0.9.1.1...
Preprocessing library postgresql-libpq-0.9.1.1...
LibPQ.hsc:213:22: fatal error: libpq-fe.h: No such file or directory
compilation terminated.
compiling .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Database/PostgreSQL/LibPQ_hsc_make.c failed (exit code 1)
command was: /nix/store/9fbfiij3ajnd3fs1zyc2qy0ispbszrr7-gcc-wrapper-4.9.3/bin/gcc -c .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Database/PostgreSQL/LibPQ_hsc_make.c -o .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Database/PostgreSQL/LibPQ_hsc_make.o -fno-stack-protector -D__GLASGOW_HASKELL__=710 -Dlinux_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -I/run/current-system/sw/include -Icbits -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -include .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h -I/nix/store/xphvly2zcd6jsc2xklz1zmmz4y0dh3ny-ghc-7.10.2/lib/ghc-7.10.2/bytes_6elQVSg5cWdFrvRnfxTUrH/include -I/nix/store/xphvly2zcd6jsc2xklz1zmmz4y0dh3ny-ghc-7.10.2/lib/ghc-7.10.2/base_GDytRqRVSUX7zckgKqJjgw/include -I/nix/store/6ykqcjxr74l642kv9gf1ib8v9yjsgxr9-gmp-5.1.3/include -I/nix/store/xphvly2zcd6jsc2xklz1zmmz4y0dh3ny-ghc-7.10.2/lib/ghc-7.10.2/integ_2aU3IZNMF9a7mQ0OzsZ0dS/include -I/nix/store/xphvly2zcd6jsc2xklz1zmmz4y0dh3ny-ghc-7.10.2/lib/ghc-7.10.2/include -I/nix/store/xphvly2zcd6jsc2xklz1zmmz4y0dh3ny-ghc-7.10.2/lib/ghc-7.10.2/include/

我认为没有多少遗漏,所以一个指针会很好。 还有什么奇怪的,那就是“nix-shell”可以工作,但随后用“stack exec yesod devel”告诉我

Resolving dependencies... 
Configuring karma-0.0.0...
cabal: At least the following dependencies are missing:
classy-prelude >=0.10.2,
classy-prelude-conduit >=0.10.2,
classy-prelude-yesod >=0.10.2,
hjsmin ==0.1.*,
http-conduit ==2.1.*,
lambdacms-core >=0.3.0.2 && <0.4,
monad-logger ==0.3.*,
persistent >=2.0 && <2.3,
persistent-postgresql >=2.1.1 && <2.3,
persistent-template >=2.0 && <2.3,
uuid >=1.3,
wai-extra ==3.0.*,
warp >=3.0 && <3.2,
yesod >=1.4.1 && <1.5,
yesod-auth >=1.4.0 && <1.5,
yesod-core >=1.4.6 && <1.5,
yesod-form >=1.4.0 && <1.5,
yesod-static >=1.4.0.3 && <1.6

当使用 mysql 时,我得到了

pcre-light-0.4.0.4: configure
mysql-0.1.1.8: configure
mysql-0.1.1.8: build
Progress: 2/59
--  While building package mysql-0.1.1.8 using:
          /run/user/1000/stack12820/mysql-0.1.1.8/.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/setup/setup --builddir=.stack-work/dist/x86_64-    linux/Cabal-1.22.4.0/ build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: /home/markus/git/haskell/karma/karma/.stack-work/logs/mysql-0.1.1.8.log

[1 of 1] Compiling Main             ( /run/user/1000/stack12820/mysql-0.1.1.8/Setup.lhs, /run/user/1000/stack12820/mysql-0.1.1.8/.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/setup/Main.o )
Linking /run/user/1000/stack12820/mysql-0.1.1.8/.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/setup/setup ...
Configuring mysql-0.1.1.8...
Building mysql-0.1.1.8...
Preprocessing library mysql-0.1.1.8...
In file included from C.hsc:68:0:
include/mysql_signals.h:9:19: fatal error: mysql.h: No such file or directory
 #include "mysql.h"
                   ^
compilation terminated.
compiling .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Database/MySQL/Base/C_hsc_make.c failed (exit code 1)
command was: /nix/store/9fbfiij3ajnd3fs1zyc2qy0ispbszrr7-gcc-wrapper-4.9.3/bin/gcc -c .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Database/MySQL/Base/C_hsc_make.c -o .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Database/MySQL/Base/C_hsc_make.o -fno-stack-protector -D__GLASGOW_HASKELL__=710 -Dlinux_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -I/nix/store/7ppa4k2drrvjk94rb60c1df9nvw0z696-mariadb-10.0.22-lib/include -I/nix/store/7ppa4k2drrvjk94rb60c1df9nvw0z696-mariadb-10.0.22-lib/include/.. -Iinclude -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -include .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h -I/nix/store/xphvly2zcd6jsc2xklz1zmmz4y0dh3ny-ghc-7.10.2/lib/ghc-7.10.2/bytes_6elQVSg5cWdFrvRnfxTUrH/include -I/nix/store/xphvly2zcd6jsc2xklz1zmmz4y0dh3ny-ghc-7.10.2/lib/ghc-7.10.2/base_GDytRqRVSUX7zckgKqJjgw/include -I/nix/store/6ykqcjxr74l642kv9gf1ib8v9yjsgxr9-gmp-5.1.3/include -I/nix/store/xphvly2zcd6jsc2xklz1zmmz4y0dh3ny-ghc-7.10.2/lib/ghc-7.10.2/integ_2aU3IZNMF9a7mQ0OzsZ0dS/include -I/nix/store/xphvly2zcd6jsc2xklz1zmmz4y0dh3ny-ghc-7.10.2/lib/ghc-7.10.2/include -I/nix/store/xphvly2zcd6jsc2xklz1zmmz4y0dh3ny-ghc-7.10.2/lib/ghc-7.10.2/include/


--  While building package pcre-light-0.4.0.4 using:
  /home/markus/.stack/setup-exe-cache/setup-Simple-Cabal-1.22.4.0-x86_64-linux-ghc-7.10.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/ configure --with-ghc=/run/current-system/sw/bin/ghc --user --package-db=clear --package-db=global --package-db=/home/markus/.stack/snapshots/x86_64-linux/nightly-2015-11-17/7.10.2/pkgdb/ --libdir=/home/markus/.stack/snapshots/x86_64-linux/nightly-2015-11-17/7.10.2/lib --bindir=/home/markus/.stack/snapshots/x86_64-linux/nightly-2015-11-17/7.10.2/bin --datadir=/home/markus/.stack/snapshots/x86_64-linux/nightly-2015-11-17/7.10.2/share --libexecdir=/home/markus/.stack/snapshots/x86_64-linux/nightly-2015-11-17/7.10.2/libexec --sysconfdir=/home/markus/.stack/snapshots/x86_64-linux/nightly-2015-11-17/7.10.2/etc --docdir=/home/markus/.stack/snapshots/x86_64-linux/nightly-2015-11-17/7.10.2/doc/pcre-light-0.4.0.4 --htmldir=/home/markus/.stack/snapshots/x86_64-linux/nightly-2015-11-17/7.10.2/doc/pcre-light-0.4.0.4 --haddockdir=/home/markus/.stack/snapshots/x86_64-linux/nightly-2015-11-17/7.10.2/doc/pcre-light-0.4.0.4 --dependency=base=base-4.8.1.0-4f7206fd964c629946bb89db72c80011 --dependency=bytestring=bytestring-0.10.6.0-18c05887c1aaac7adb3350f6a4c6c8ed
Process exited with code: ExitFailure 1
Logs have been written to: /home/markus/git/haskell/karma/karma/.stack-work/logs/pcre-light-0.4.0.4.log

Configuring pcre-light-0.4.0.4...
setup-Simple-Cabal-1.22.4.0-x86_64-linux-ghc-7.10.2: The program 'pkg-config'
version >=0.9.0 is required but it could not be found.

将 pkgconfig 添加到我的全局配置后,构建似乎更进一步,因此似乎 shell.nix 被忽略了一些。

(到目前为止我尝试过的来源: https://groups.google.com/forum/#!topic/haskell-stack/_ZBh01VP_fo)

更新:似乎我忽略了手册的这一部分 http://nixos.org/nixpkgs/manual/#using-stack-together-with-nix 然而,第一个想到的想法 (堆栈--extra-lib-dirs=/nix/store/c6qy7n5wdwl164lnzha7vpc3av9yhnga-postgresql-libpq-0.9.1.1/lib build) 还没有工作,很可能我需要使用 --extra-include-dirs 或尝试其中一种变体。不过,stack 仍然尝试在相同版本中构建 postgresql-libpq 似乎很奇怪。

Update2:目前正在尝试“堆栈 --extra-lib-dirs=/nix/store/1xf77x47d0m23nbda0azvkvj8w8y77c7-postgresql-9.4.5/lib --extra-include-dirs=/nix/store/1xf77x47d0m23nbda0azvkvj8w8y77c7-postgresql-9.4 .5/include build”看起来很有希望。看起来不像 nix-way,但仍然。

Update3:还在更新中

<command line>: can't load .so/.DLL for: /home/markus    /.stack/snapshots/x86_64-linux/nightly-2015-11-17/7.10.2/lib/x86_64-linux-  ghc-7.10.2/postgresql-libpq-0.9.1.1-ABGs5p1J8FbEwi6uvHaiV6/libHSpostgresql-libpq-0.9.1.1-ABGs5p1J8FbEwi6uvHaiV6-ghc7.10.2.so 
(libpq.so.5: cannot open shared object file: No such file or directory) stack   build  186.99s user 2.93s system 109% cpu 2:52.76 total

这很奇怪,因为 libpq.so.5 包含在 /nix/store/1xf77x47d0m23nbda0azvkvj8w8y77c7-postgresql-9.4.5/lib 中。 额外的

$LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/nix/store/1xf77x47d0m23nbda0azvkvj8w8y77c7-postgresql-9.4.5/lib

也无济于事。

更新4: 顺便说一句,yesod devel 与 stack exec yesod devel 的作用相同。我的库已下载到 /nix/store 但无法识别。 也许我需要让“build-nix”工作,而 yesod devel 在这里不起作用?

为了完整起见,这里是 stack.yaml

resolver: nightly-2015-11-17
#run stack setup otherwise!!

# Local packages, usually specified by relative directory name
packages:
- '.'

# Packages to be pulled from upstream that are not in the resolver (e.g.,    acme-missiles-0.3)
extra-deps: [lambdacms-core-0.3.0.2 , friendly-time-0.4, lists-0.4.2,     list-extras-0.4.1.4  ]


 # Override default flag values for local packages and extra-deps
flags:
  karma:
    library-only: false
    dev: false

# Extra package databases containing global packages
extra-package-dbs: []

下周末,我去看看 https://pr06lefs.wordpress.com/2014/09/27/compiling-a-yesod-project-on-nixos/ 和其他搜索结果。

【问题讨论】:

  • 刚刚给了 nixos 另一个机会,似乎除了 stack --nix build 和下面的 extrac-include-dirs 和 extra-lib-dirs。

标签: mysql postgresql haskell nixos stackage


【解决方案1】:

看起来stack 正在尝试在nix 框架之外构建haskellPackages.postgresql-libpq

您可能不希望这种情况发生。也许尝试将postgresql-libpq 添加到libraryHaskellDepends

【讨论】:

  • 如果我这样做,我会收到错误:/home/markus/git/haskell/karma/karma/shell.nix:35:11 处的未定义变量“postgresql-libpq”。在运行“nix-shell”时,使用haskellPackages 前缀不会导致错误,但“nix-shell --command stack build”仍然不起作用,与问题中的错误相同。
  • 未定义的变量错误是由于忘记将 postgresql-libpq 添加到 f = {...} 表达式。否则,与上述相同的错误。
  • 我不会在nixos 上使用stack,所以有点超出我的深度。你可能想试试 freenode 上的#nixos IRC 频道
【解决方案2】:

很有趣,因为我自己也遇到过类似的问题 - 通过将这两行添加到 stack.yaml 来解决它:

extra-include-dirs: [/nix/store/jrdvjvf0w9nclw7b4k0pdfkljw78ijgk-postgresql-9.4.5/include/]
extra-lib-dirs: [/nix/store/jrdvjvf0w9nclw7b4k0pdfkljw78ijgk-postgresql-9.4.5/lib/]

您可能需要先检查/nix/store 中的哪个postgresql 的路径应该与include/lib/ 一起使用:

nix-build --no-out-link "<nixpkgs>" -A postgresql

顺便说一句,如果你要使用stack,为什么还要使用nix-shell 并且你有project-karma.cabal 可用..?你考虑过migrating your projectstack init..吗?

【讨论】:

  • 嗨,我现在无法检查。我认为这是最后缺少的斜线或类似的东西。
  • 这也可能与 stack.yaml 中的规定有冲突。我会将其添加到问题中以供将来的访问者使用。
  • 为了完整起见,我会将您的答案标记为正确。
猜你喜欢
  • 2015-03-03
  • 2017-04-18
  • 1970-01-01
  • 1970-01-01
  • 2022-01-15
  • 2017-07-02
  • 1970-01-01
  • 1970-01-01
  • 2015-03-30
相关资源
最近更新 更多