这是我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)];
};
定义一些环境
调用这个函数来定义两个环境:一个用于在更改时运行Hoogle构建器,另一个不用:
haskellEnvHoogle = haskellEnvFun {
name = "haskellEnvHoogle";
withHoogle = true;
};
haskellEnv = haskellEnvFun {
name = "haskellEnv";
withHoogle = false;
};
程序包
在本地的 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
];
Shell帮助程序
在您的~/.profile
文件中定义一些bash函数以方便加载这些环境:
env-type () {
envtype="$1"
shift
nix-shell -Q -p $envtype "$@"
}
haskell-env () {
env-type "haskellEnv" "$@"
}
haskell-env-hoogle () {
env-type "haskellEnvHoogle" "$@"
}
Hoogle
在您的shell中调用haskell-env-hoogle
。这将构建所有包及��文档,并将您加载到具有hoogle
作用域的环境中。此时,我通常会键入以下内容:
hoogle server --local -p 8080 &> /tmp/hoogle.log & disown
启动一个后台的 Hoogle 服务器。最终我想要为此创建一个 systemd 服务,这样我就可以只需运行 nixos-rebuild 来重新生成文档并自动启动服务器。
Emacs
对于 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
希望这有所帮助。