“nix-shell”命令“堆栈构建”导致libpq-fe。h:没有这样的文件或目录。

时间:2022-07-03 17:03:27

i am trying to compile my small project (a yesod application with lambdacms) on nixos. However, after using cabal2nix (more precisely cabal2nix project-karma.cabal --sha256=0 --shell > shell.nix) , I am still missing a dependency wrt. postgresql it seems.

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

My shell.nix file looks like this:

我的壳。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

The output is as follows:

输出如下:

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/

I assume not much is missing, so a pointer would be nice. What is also weird, that is that "nix-shell" works but following that up with "stack exec yesod devel" tells me

我假设没有太多遗漏,所以一个指针会很好。还有一个奇怪的地方,那就是“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

When using mysql instead, I am getting

使用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.

After adding pkgconfig to my global configuration, the build seems to get a little further ahead, so it seems that shell.nix is ignored somewhat.

在我的全局配置中添加了pkgconfig之后,构建似乎又向前推进了一点,所以看起来是shell。拒绝被忽略。

(Sources for what I tried so far: https://groups.google.com/forum/#!topic/haskell-stack/_ZBh01VP_fo)

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

Update: It seems like I overlooked this section of the manual http://nixos.org/nixpkgs/manual/#using-stack-together-with-nix However, the first idea that came to mind (stack --extra-lib-dirs=/nix/store/c6qy7n5wdwl164lnzha7vpc3av9yhnga-postgresql-libpq-0.9.1.1/lib build) did not work yet, most likely I need to use --extra-include-dirs or try one of the variations. It seems weird that stack is still trying to build postgresql-libpq in the very same version, though.

更新:似乎我忽略了手册的这一节:http://nixos.org/nixpkgs/manual/# us-stack- --与-nix,第一个出现在我的想法(堆栈-- -- -- -- -- -- -- -- --)-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -尽管如此,stack仍然试图在同一个版本中构建postgresql-libpq,这似乎很奇怪。

Update2: Currently trying out "stack --extra-lib-dirs=/nix/store/1xf77x47d0m23nbda0azvkvj8w8y77c7-postgresql-9.4.5/lib --extra-include-dirs=/nix/store/1xf77x47d0m23nbda0azvkvj8w8y77c7-postgresql-9.4.5/include build" which looks promising. Does not look like the nix-way, but still.

Update2:当前正在尝试“堆栈——额外的-lib-dirs=/nix/store/ 1xf77x47d0m23nbd0azvkvj8w8y77c7 -postgresql-9.4.5/lib -- - includedirs =/nix/store/1xf77x47d0m23nbda0azvkvj8w8y77c7-postgresql-9.4.5/包括构建”这看起来很有希望。看起来不像nix,但仍然。

Update3: Still getting

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

which is strange since libpq.so.5 is contained in /nix/store/1xf77x47d0m23nbda0azvkvj8w8y77c7-postgresql-9.4.5/lib. An additional

这很奇怪,因为libpqso。5载于/nix/store/ 1xf77x47d0m23nbda0azvkvj8y77c7 -postgresql-9.4.5/lib。一个额外的

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

does not help either.

不能帮助。

Update4: By the way, yesod devel does the same as stack exec yesod devel. My libraries are downloaded to /nix/store but they are not recognized. Maybe I need to make "build-nix" work and yesod devel does not work here?

Update4:顺便说一下,yesod devel和stack exec yesod devel一样。我的库被下载到/nix/store,但它们没有被识别。也许我需要做“building -nix”工作,而yesod devel不在这里工作?

Just for completeness, here is stack.yaml

为了完整性,这里是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: []

Next weekend, I will check out https://pr06lefs.wordpress.com/2014/09/27/compiling-a-yesod-project-on-nixos/ and other search results.

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

2 个解决方案

#1


2  

Funny, because I've just had a similar problem myself - solved it by adding these two lines to stack.yaml:

有趣的是,因为我自己也有过类似的问题——通过把这两条线加到stack.yaml上,解决了这个问题。

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

You may want to check first which postgresql's path from the /nix/store you should use with include/ and lib/:

您可能需要先检查从/nix/存储中应该使用的postgresql路径,包括/和lib/:

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

And BTW, why do you use nix-shell if you are going to use stack and you have project-karma.cabal available..? Have you considered migrating your project with stack init..?

顺便说一下,如果你要使用堆栈,你为什么要使用nix-shell呢?阴谋集团可用. . ?您是否考虑过用堆栈init迁移项目?

#2


0  

Looks like stack is trying to build haskellPackages.postgresql-libpq outside of the nix framework.

看起来堆栈正在尝试构建haskellPackages。在nix框架之外的postgresql-libpq。

You probably don't want that to happen. Maybe try to add postgresql-libpq to libraryHaskellDepends?

你可能不希望这样的事情发生。可能尝试添加postgresql-libpq到libraryHaskellDepends?

#1


2  

Funny, because I've just had a similar problem myself - solved it by adding these two lines to stack.yaml:

有趣的是,因为我自己也有过类似的问题——通过把这两条线加到stack.yaml上,解决了这个问题。

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

You may want to check first which postgresql's path from the /nix/store you should use with include/ and lib/:

您可能需要先检查从/nix/存储中应该使用的postgresql路径,包括/和lib/:

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

And BTW, why do you use nix-shell if you are going to use stack and you have project-karma.cabal available..? Have you considered migrating your project with stack init..?

顺便说一下,如果你要使用堆栈,你为什么要使用nix-shell呢?阴谋集团可用. . ?您是否考虑过用堆栈init迁移项目?

#2


0  

Looks like stack is trying to build haskellPackages.postgresql-libpq outside of the nix framework.

看起来堆栈正在尝试构建haskellPackages。在nix框架之外的postgresql-libpq。

You probably don't want that to happen. Maybe try to add postgresql-libpq to libraryHaskellDepends?

你可能不希望这样的事情发生。可能尝试添加postgresql-libpq到libraryHaskellDepends?