问题描述
我目前有一个在NixOS上开发的Yesod Web应用程序。我正在使用 default.nix
文件,如O'Charles':
I currently have a Yesod web application that I am developing on NixOS. I am using a default.nix
file like described in O'Charles' blog post:
{ haskellPackages ? (import <nixpkgs> {}).haskellPackages }:
haskellPackages.cabal.mkDerivation (self: {
pname = "myblog";
version = "0.0.0";
src = ./.;
isLibrary = true;
isExecutable = true;
buildDepends = with haskellPackages; [
aeson bson conduit dataDefault fastLogger hjsmin
httpConduit monadControl monadLogger mongoDB persistent
#persistentMongoDB
persistentTemplate poolConduit shakespeare text
waiExtra waiLogger warp yaml yesod yesodAuth
yesodCore yesodDefault yesodForm yesodStatic
];
testDepends = with haskellPackages; [
hspec monadLogger persistent
#persistentMongoDB
resourcet transformers yesod yesodCore yesodTest
];
buildTools = with haskellPackages; [
cabalInstall ghcMod yesodBin
];
jailbreak = true;
})
此运作良好。我可以像平常一样使用 yesod
二进制文件和 cabal
二进制文件。但是,我遇到了一个问题。运行 cabal haddock
时,出现以下错误:
This is working very well. I can use the yesod
binary and cabal
like normal. However, I am running into one problem. When running cabal haddock
, I am getting the following error:
Running Haddock for mycoolblog-0.0.0...
Preprocessing library mycoolblog-0.0.0...
Warning: The documentation for the following packages are not installed. No
links will be generated to these packages: persistent-mongoDB-2.1.1
<command line>: cannot satisfy -package-id aeson-0.8.0.2-9e93bdd6f8e68379314dd5f31414f87f
(use -v for more information)
对此进行谷歌搜索会显示以下链接:。似乎是在说应该使用ghcWithPackages。
Googling about this brings up the following link: github: cabal haddock 'cannot satisfy -package-id' #2468. It seems like it is saying that ghcWithPackages should be used.
谷歌搜索 ghcWithPackages
会弹出O'Charles'(个人?)。它有一个使用 ghcWithPackages
来开发已经存在于nixpkgs中的软件包的示例,但是我无法使其与不在nixpkgs中的软件包一起使用(我的cms / blog)。
Googling about ghcWithPackages
brings up O'Charles' (personal?) wiki on Nix. It has an example of using ghcWithPackages
to develop a package that is already in nixpkgs, but I can't get it to work with a package that is not already in nixpkgs (my cms/blog).
按照O'Charles维基上的描述进行设置并运行 nix-shell -v
,出现以下错误:
Setting it up like described on O'Charles' wiki and running nix-shell -v
, I get the following error:
evaluating file `/nix/store/an4sg7cxi1ii3vids8417kajl3ss13vd-nix-1.7/share/nix/corepkgs/derivation.nix'
error: cannot auto-call a function that has an argument without a default value (`cabal')
为什么会出现上述错误?如何为不在nixpkgs中的Haskell项目编写 default.nix
和 shell.nix
?理想情况下,它将使用 ghcWithPackages
,以便 cabal haddock
起作用。
Why am I getting the above error? How can I write a default.nix
and shell.nix
for a Haskell project that's not already in nixpkgs? Ideally it would be using ghcWithPackages
so that cabal haddock
works.
推荐答案
使用。我尚未确定为什么此方法以前无法使用。
I was able to get this working after using the method on O'Charles' Nix wiki. I have not determined why this method was not working before.
基本上,首先运行 cabal2nix
。然后创建一个通用的shell.nix(可以在所有Haskell软件包之间共享)。
Basically, first run cabal2nix
. Then create a generic shell.nix (that can be shared between all Haskell packages).
$ cabal2nix --jailbreak --sha256=X ./$cabal > default.nix
$ sed -i 's#sha = .*#src = builtins.filterSource (path: type: type != "unknown") ./.;#' default.nix
$ cat - > shell.nix <<EOF
let
pkgs = import <nixpkgs> {};
haskellPackages = pkgs.haskellPackages.override {
extension = self: super: {
thispackage = self.callPackage ./. {};
};
};
in pkgs.myEnvFun {
name = haskellPackages.thispackage.name;
buildInputs = [
(haskellPackages.ghcWithPackages (hs: ([
hs.cabalInstall
hs.hscolour
hs.ghcMod
] ++ hs.thispackage.propagatedNativeBuildInputs)))
];
}
EOF
$ nix-shell
这篇关于使用cabal2nix为不在nixpkgs中的软件包创建本地nix环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!