我试图在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构建)
尚无法使用,很可能我需要使用
--extra-include-dirs或尝试其中一种。不过,看起来堆栈仍在尝试使用相同版本构建postgresql-libpq似乎很奇怪。

Update2:当前正在尝试“堆栈--extra-lib-dirs = / nix / store / 1xf77x47d0m23nbda0azvkvj8w8y77c7-postgresql-9.4.5 / lib --extra-include-dirs = / nix / store / 1xf77x47d0m23nbda0azvkvj8w8y77c7。包括构建”,看起来很有希望。看起来不像尼克斯路,但还是。

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与堆栈执行程序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/
和其他搜索结果。

最佳答案

有趣,因为我自己也遇到了类似的问题-通过在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?您是否考虑过将migrating your projectstack init ..

关于mysql - nix-shell --command`stack build`导致libpq-fe.h:没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34694130/

10-11 20:58