git.iko.soy/typeable/cabal2nix
on master help sign in
doc: greatly extended user-guide.md
commit3bfdd1c52f139d893602849a37f6ce6aca0d7074 authorPeter Simons <simons@cryp.to> dateSun 17 May 2015, 16:39 (11 years ago) parentb0eec6a
1 file changed+189−15
doc/user-guide.md+189−15
doc/user-guide.md+189−15
@@ -6,14 +6,45 @@
66
77# What can Nix do for you?
88
9−1) Install a Haskell compiler
9+1) Install any Haskell package known to Hackage.
1010
11−2) Create a Haskell development environment
11+2) Install a Haskell compiler.
1212
13+3) Create a Haskell development environment.
1314
1415-------------------------------------------------------------------------------
1516
16−# Installing a Haskell compiler
17+# Install Haskell packages from Hackage
18+
19+Lookups based on package names like
20+
21+ $ nix-env -i cabal-install
22+
23+don't work! You have to use attribute paths:
24+
25+ $ nix-env -iA haskellPackages.cabal-install
26+
27+To list all Haskell packages, run:
28+
29+ $ nix-env -qaP -A haskellPackages
30+
31+-------------------------------------------------------------------------------
32+
33+# Install Haskell packages from Hackage
34+
35+There is one Haskell package set per compiler:
36+
37+ $ nix-env -qaP -A haskellPackages
38+ $ nix-env -qaP -A haskell.packages.ghc6123
39+ $ nix-env -qaP -A haskell.packages.ghc763
40+ $ nix-env -qaP -A haskell.packages.ghc7101
41+
42+The default `haskellPackages` currently refers to
43+`haskell.packages.ghc7101`.
44+
45+-------------------------------------------------------------------------------
46+
47+# Install a Haskell compiler
1748
1849 $ nix-env -iA haskell.compiler.ghc784
1950
@@ -33,24 +64,167 @@
3364
3465-------------------------------------------------------------------------------
3566
36−# Installing more than one Haskell compiler
67+# Install a Haskell compiler
68+
69+For every compiler version XYZ, the attributes
70+
71+ haskell.compiler.ghcXYC
72+
73+and
74+
75+ haskell.packages.ghcXYC.ghc
76+
77+are synonymous.
78+
79+-------------------------------------------------------------------------------
80+
81+# Install more than one Haskell compiler (temporary)
82+
83+ $ nix-shell -p haskell.compiler.ghc7101
84+ [nix-shell:~]$ ghc --numeric-version
85+ 7.10.1
86+ [nix-shell:~]$ exit
87+
88+ $ nix-shell -p haskell.compiler.ghc784 \
89+ --command "cabal configure"
90+ $ cabal build
91+
92+-------------------------------------------------------------------------------
93+
94+# Install several Haskell compilers (transient)
95+
96+ $ nix-env -p ~/ghc-7.6.3 -iA haskell.compiler.ghc763
97+ $ nix-env -p ~/ghc-7.8.4 -iA haskell.compiler.ghc784
98+ [...]
99+
100+ $ export PATH=$HOME/ghc-7.6.3/bin:$PATH
101+ $ ghc --numeric-version
102+ 7.6.3
103+
104+ $ cabal configure --with-compiler=$HOME/ghc-7.6.3/bin/ghc
105+
106+-------------------------------------------------------------------------------
107+
108+# Install several Haskell compilers (permanent)
109+
110+ $ PROFILE_DIR=/nix/var/nix/profiles/per-user/$USER
111+ $ nix-env -p $PROFILE_DIR/ghc-7.6.3 -iA ...
112+
113+On NixOS, `/etc/profile` defines `$NIX_USER_PROFILE_DIR` automatically.
114+
115+-------------------------------------------------------------------------------
116+
117+# Create a Haskell development environment
118+
119+Edit the file `~/.nixpkgs/config.nix`:
120+
121+ {
122+ packageOverrides = super: let self = super.pkgs; in
123+ {
124+ myHaskellEnv =
125+ self.haskell.packages.ghc7101.ghcWithPackages
126+ (haskellPackages: with haskellPackages; [
127+ arrows async cabal-install case-insensitive
128+ cgi criterion hspec HStringTemplate
129+ ]);
130+ };
131+ }
132+
133+Now installl with `nix-env -iA myHaskellEnv`.
134+
135+-------------------------------------------------------------------------------
136+
137+# Create a Haskell development environment
138+
139+The generated `ghc` program is a wrapper script that re-directs the real
140+`ghc` to use a "libdir" with all the specified packages installed:
141+
142+ #! /nix/store/xlxjcjbnbwnz...-bash-4.3-p33/bin/bash -e
143+ realGhc=/nix/store/zzhasddj77xhwdban95...-ghc-7.10.1
144+ ghcEnv=/nix/store/cgddwzz9hkdgprvbymph...-ghc-7.10.1
145+ export NIX_GHC=$ghcEnv/bin/ghc
146+ export NIX_GHCPKG=$ghcEnv/bin/ghc-pkg
147+ export NIX_GHC_DOCDIR=$ghcEnv/share/doc/ghc/html
148+ export NIX_GHC_LIBDIR=$ghcEnv/lib/ghc-7.10.1
149+ exec $realGhc/bin/ghc "-B$NIX_GHC_LIBDIR" \
150+ "${extraFlagsArray[@]}" "$@"
151+
152+
153+-------------------------------------------------------------------------------
154+
155+# Create a Haskell development environment
156+
157+Define the same environment variables in your `~/.bashrc`:
158+
159+ NIX_GHC="$HOME/.nix-profile/bin/ghc"
160+ ghcVersion=$($NIX_GHC --numeric-version)
161+ NIX_GHCPKG="$HOME/.nix-profile/bin/ghc-pkg"
162+ NIX_GHC_DOCDIR="$HOME/.nix-profile/share/doc/ghc/html"
163+ NIX_GHC_LIBDIR="$HOME/.nix-profile/lib/ghc-$ghcVersion"
164+ export NIX_GHC NIX_GHCPKG NIX_GHC_DOCDIR NIX_GHC_LIBDIR
165+ unset ghcVersion
37166
38−- Multiple environments:
39167
40− $ nix-env -p ~/ghc-7.6.3 -iA haskell.compiler.ghc763
41− $ nix-env -p ~/ghc-7.8.4 -iA haskell.compiler.ghc784
168+Or:
169+
170+ if [ -e ~/.nix-profile/bin/ghc ]; then
171+ eval $(grep export ~/.nix-profile/bin/ghc)
172+ fi
173+
174+-------------------------------------------------------------------------------
175+
176+# Create a temporary Haskell development environment
177+
178+Save as `shell.nix`:
179+
180+ with (import <nixpkgs> {}).pkgs;
181+ let
182+ ghc = haskell.packages.ghc7101.ghcWithPackages
183+ (pkgs: with pkgs; [ aeson lens monad-par ]);
184+ in
185+ stdenv.mkDerivation {
186+ name = "my-haskell-env-0";
187+ buildInputs = [ ghc ];
188+ shellHook = "eval $(grep export ${ghc}/bin/ghc)";
189+ }
190+
191+Now run `nix-shell`, or even `nix-shell --pure`.
192+
193+-------------------------------------------------------------------------------
194+
195+# Create a temporary Haskell development environment
196+
197+To parameterize the compiler version, edit the file as follows:
198+
199+ { compiler ? "ghc7101" }:
200+
201+ with (import <nixpkgs> {}).pkgs;
202+ let
203+ ghc = haskell.packages.${compiler}.ghcWithPackages
204+ (pkgs: with pkgs; [ aeson lens monad-par ]);
205+ in
206+ stdenv.mkDerivation {
42207 [...]
208+ }
209+
210+Now run "`nix-shell --argstr compiler ghc784`" to select a different
211+compiler.
212+
213+-------------------------------------------------------------------------------
214+
215+# Create a temporary Haskell development environment
43216
44− $ export PATH=~/ghc-7.6.3/bin:$PATH
45− $ ghc --numeric-version
46− 7.6.3
217+Every Haskell package has an `env` attribute that provides a temporary shell environment in which that package can be built:
47218
48−- Temporary environment:
219+ $ cabal get lens && cd lens-4.10
220+ Downloading lens-4.10...
221+ Unpacking to lens-4.10/
49222
50− $ nix-shell -p haskell.compiler.ghc7101
51− [nix-shell:~]$ ghc --numeric-version
52− 7.10.1
53− [nix-shell:~]$ exit
223+ $ nix-shell "<nixpkgs>" -A haskellPackages.lens.env
224+ [nix-shell:/tmp/lens-4.10]$ cabal configure
225+ Resolving dependencies...
226+ Configuring lens-4.10...
227+ [...]
54228
55229-------------------------------------------------------------------------------
56230