nix-shell --命令 `stack build` 导致 libpq-fe.h:没有这样的文件或目录

问题描述 投票:0回答:3

我正在尝试在 nixos 上编译我的小项目(一个带有 lambdacms 的 yesod 应用程序)。但是,在使用 cabal2nix (更准确地说 cabal2nix project-karma.cabal --sha256=0 --shell > shell.nix)之后,我仍然缺少依赖项。看来是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 构建) 还没有工作,很可能我需要使用 --extra-include-dirs 或尝试其中一种变体。不过,stack 仍然试图在相同的版本中构建 postgresql-libpq ,这似乎很奇怪。

update2:当前尝试“ stack -extra-lib-dirs =/nix/store/1xf77x47d0m23nbda0azvkvkvkvj8y7777c7-postgresql9.4.4.5/lib/lib -extra-include-include-inix =/inix =/include inix =/include inix =/store/store/store/store 1xf7777777777777777777777d0m23 ESQL-9.4.5 /include build”看起来很有希望。看起来不像尼克斯方式,但仍然如此。

更新3:仍在获取

<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/ 和其他搜索结果。

mysql postgresql haskell nixos stackage
3个回答
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/]

您可能需要首先检查从

postgresql
开始哪个
/nix/store
的路径应与
include/
lib/
一起使用:

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

顺便说一句,如果您要使用

nix-shell
并且
您有stack可用,为什么要使用
project-karma.cabal
......?您是否考虑过使用 stack init..
迁移您的项目


0
投票

看起来

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

您可能不希望这种情况发生。也许尝试将

postgresql-libpq
添加到
libraryHaskellDepends


0
投票

接受的答案解决了问题的一部分:他们手动添加来自

postgresql
包的include/lib路径,该包是因为您运行服务器而安装的。

这不是最好的做事方式。相反,将

postgresql
包添加到您的 shell 中。 Nix shell 的工作方式是,它们已经添加您的 shell 的路径。

从历史上看,

nix-shell
旨在支持派生的开发和调试。这就是为什么它们表现为开发 shell

这个特殊情况有点令人困惑的原因是大多数包将开发输出与服务/二进制输出分开。许多 nix 软件包将开发输出拆分为

.dev
下,例如
libxml2.dev
curl.dev
。 Postgres 没有做出区分,但您仍然需要在 shell 中注入编译器标志。

我今天制作的

default.nix
示例(我遇到了缺失的
libpq-fe.h
问题):

{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
  # nativeBuildInputs is usually what you want -- tools you need to run
  nativeBuildInputs = with pkgs.buildPackages; [
    ruby_3_3
    ruby_3_3.devdoc
    rubyfmt
    openssl.dev
    readline.dev
    libyaml.dev
    sqlite.dev
    libxml2.dev
    curl.dev
    libffi.dev
    #
    rbenv
    postgresql
  ];
}
© www.soinside.com 2019 - 2024. All rights reserved.