ill*_*out 13 haskell hoogle nixos
我试图在Haskell开发环境中使用hoogle,就像O'Charles的wiki所描述的那样:
我已经修改shell.nix如下使用hoogleLocal,但它似乎没有为我安装hoogle二进制文件.
let
pkgs = import <nixpkgs> {};
# I'm attempting to use hoogle here, but it is not working.
haskellPackages =
let callPackage = pkgs.lib.callPackageWith haskellPackages;
in pkgs.recurseIntoAttrs (pkgs.haskellPackages.override {
extension = self: super: {
thiscurrentpackage = self.callPackage ./. {};
hoogleLocal = pkgs.haskellPackages.hoogleLocal.override {
packages = self.thiscurrentpackage;
};
};
});
in pkgs.myEnvFun {
name = haskellPackages.thiscurrentpackage.name;
buildInputs = [
(haskellPackages.ghcWithPackages (hs: ([
hs.cabalInstall
hs.ghcMod
hs.yesodBin
# This doesn't appear to install the hoogle binary?
hs.hoogleLocal
] ++ hs.thiscurrentpackage.propagatedNativeBuildInputs)))
];
}
Run Code Online (Sandbox Code Playgroud)
在生成的shell中,hoogle二进制文件不可用.
如果我包括hs.hoogle在buildInputs中,hoogle二进制安装,但无法找到数据库.以下是我尝试使用它时会发生的情况.
$ nix-shell
......
$ hoogle Monad
Could not find some databases: default
Searching in:
.
/nix/store/91y9q2y5a2ws8xgcsx1gkhfagc0f2qz6-haskell-hoogle-ghc7.8.3-4.2.36-shared/share/x86_64-linux-ghc-7.8.3/hoogle-4.2.36/databases
There are no available databases, generate them with: hoogle data
$ hoogle data
hoogle: /nix/store/91y9q2y5a2ws8xgcsx1gkhfagc0f2qz6-haskell-hoogle-ghc7.8.3-4.2.36-shared/share/x86_64-linux-ghc-7.8.3/hoogle-4.2.36/databases:
changeWorkingDirectory: does not exist (No such file or directory)
$
Run Code Online (Sandbox Code Playgroud)
如何正确使用O'Charles描述的设置?
编辑:原始shell.nix与此答案中的相同.
Wil*_*rin 13
这是我的Nix Haskell开发环境的样子
在~/.nixpkgs/config.nix:
首先,定义一个haskellEnvFun函数来构建Haskell环境:
packageOverrides = super: rec {
haskellEnvFun = { withHoogle ? false, compiler ? null, name }:
let hp = if compiler != null
then super.haskell.packages.${compiler}
else haskellPackages;
ghcWith = if withHoogle
then hp.ghcWithHoogle
else hp.ghcWithPackages;
in super.buildEnv {
name = name;
paths = [(ghcWith myHaskellPackages)];
};
Run Code Online (Sandbox Code Playgroud)
调用此函数可以定义两个环境:一个用于在更改时运行Hoogle构建器,另一个用于:
haskellEnvHoogle = haskellEnvFun {
name = "haskellEnvHoogle";
withHoogle = true;
};
haskellEnv = haskellEnvFun {
name = "haskellEnv";
withHoogle = false;
};
Run Code Online (Sandbox Code Playgroud)
定义要在本地Haskell开发环境中使用的所有包:
myHaskellPackages = hp: with hp; [
Boolean
HTTP
HUnit
MissingH
QuickCheck
SafeSemaphore
Spock
aeson
async
attoparsec
bifunctors
blaze-builder
blaze-builder-conduit
blaze-builder-enumerator
blaze-html
blaze-markup
blaze-textual
cased
cassava
cereal
comonad
comonad-transformers
directory_1_2_4_0
dlist
dlist-instances
doctest
exceptions
fingertree
foldl
free
hamlet
hashable
hspec
hspec-expectations
html
http-client
http-date
http-types
io-memoize
keys
language-c
language-javascript
language-bash
lens
lens-action
lens-aeson
lens-datetime
lens-family
lens-family-core
lifted-async
lifted-base
linear
list-extras
list-t
logict
mime-mail
mime-types
mmorph
monad-control
monad-coroutine
monad-loops
monad-par
monad-par-extras
monad-stm
monadloc
mongoDB
monoid-extras
network
newtype
numbers
optparse-applicative
parsec
parsers
pcg-random
persistent
persistent-mongoDB
persistent-template
pipes
pipes-async
pipes-attoparsec
pipes-binary
pipes-bytestring
pipes-concurrency
pipes-csv
pipes-extras
pipes-group
pipes-http
pipes-mongodb
pipes-network
pipes-parse
pipes-safe
pipes-shell
pipes-text
posix-paths
postgresql-simple
pretty-show
profunctors
random
reducers
reflection
regex-applicative
regex-base
regex-compat
regex-posix
regular
relational-record
resourcet
retry
rex
safe
sbv
scotty
semigroupoids
semigroups
shake
shakespeare
shelly
simple-reflect
speculation
split
spoon
stm
stm-chans
stm-stats
streaming
streaming-bytestring
streaming-wai
strict
stringsearch
strptime
syb
system-fileio
system-filepath
tagged
taggy
taggy-lens
tar
tardis
tasty
tasty-hspec
tasty-hunit
tasty-quickcheck
tasty-smallcheck
temporary
test-framework
test-framework-hunit
text
text-format
time
tinytemplate
transformers
transformers-base
turtle
uniplate
unix-compat
unordered-containers
uuid
vector
void
wai
wai-conduit
warp
wreq
xhtml
yaml
zippers
zlib
];
Run Code Online (Sandbox Code Playgroud)
在您~/.profile定义一对bash函数时,为了方便起见,加载这些环境:
env-type () {
envtype="$1"
shift
nix-shell -Q -p $envtype "$@"
}
haskell-env () {
env-type "haskellEnv" "$@"
}
haskell-env-hoogle () {
env-type "haskellEnvHoogle" "$@"
}
打电话给haskell-env-hoogle你的shell.这将构建所有的包+文档,并将您加载到hoogle范围内的环境中.此时我通常输入:
hoogle server --local -p 8080 &> /tmp/hoogle.log & disown
Run Code Online (Sandbox Code Playgroud)
启动一个hoogle服务器的后台.最终我希望有一个systemd服务,这样我就可以通过nixos-rebuild重新生成文档并自动启动服务器.
为Emacs我已经设置haskell-hoogle-url到http://localhost:8080/?hoogle=%s,让我可以在我的光标下取得关键字当地hoogle文档.我使用spacemacs所以我只输入, h h这个功能.
你可以在这里看到我的完整nixpkgs配置:https://github.com/jb55/nix-files/blob/659798f2ca81fb7ad0cb5a29de576024ee16eef8/nixpkgs/config.nix#L20
希望有所帮助.
Ben*_*Ben 11
haskellPackages.hoogleLocal似乎已经过时了; 它不再存在了.
William Casarin的回答似乎是假设您将使用单个"haskell开发环境",而不是使用nix-shell为不同的项目设置不同的开发环境.
我刚刚想出如何做,而不是为写我shell.nix覆盖ghc.withPackages,并ghcWithPackages要ghc.withHoogle,这样当尼克斯壳创建一个具有GHC它知道所有必需的包的环境也带来了hoogle数据库知道相同的包裹.
这是我的shell.nix 1:
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", withHoogle ? true }:
let
inherit (nixpkgs) pkgs;
f = import ./default.nix;
packageSet = (
if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler}
);
haskellPackages = (
if withHoogle
then packageSet.override {
overrides = (self: super:
{
ghc = super.ghc // { withPackages = super.ghc.withHoogle; };
ghcWithPackages = self.ghc.withPackages;
}
);
}
else packageSet
);
drv = haskellPackages.callPackage f {};
in
if pkgs.lib.inNixShell then drv.env else drv
Run Code Online (Sandbox Code Playgroud)
我对nix很新,但我相信这应该是"项目独立的"; cabal2nix . > default.nix当我更改它时,我可以用来从我的cabal文件生成一个nix包,而不必触摸shell.nix.
我还没有在实际开发中实际使用它,只是我用来试图找出如何让nogle-shell中的hoogle工作的虚拟项目.
1这个的骨架是cabal2nix --shell吐出的,特定于项目的内脏被移除并替换f = import ./default.nix而不是再次嵌入nixified cabal包.