Notes: Nix package manager

April 22, 2016

These are my notes from using the Nix package manager.



To search packages in the haskellPackages namespace:

$ nix-env -f "<nixpkgs>" -qaP -A haskellPackages

To install packages, which live in the haskellPackages namespace, use -A:

$ nix-env -f "<nixpkgs>" -i -A haskellPackages.ghc

See User's Guide to the Haskell Infrastructure for more information.

To fix various problems, use nix-shell:

$ nix-shell -p zlib zlibStatic

To use the latest Agda, pull the latest nixpkgs and install directly:

$ nix-env -f /path/to/nixpkgs -i -A haskellPackages.Agda

To list all known Haskell compilers in Nix:

$ nix-instantiate --eval -E "with import <nixpkgs> {}; lib.attrNames haskell.compiler"

nix-repl can also be used to do this:

$ nix-env -i nix-repl
$ nix-repl
nix-repl> :l <nixpkgs>
nix-repl> haskell.compiler.ghc<Tab>

Nix shell

Use nix-shell to set up a temporary environment with dependencies that aren't needed in your daily environment:

$ nix-shell -p ruby --run "gem install --user vimgolf"

Adding a new package to nixpkgs

See nixpkgs/15731.


$ nix-env -f "<nixpkgs>" -i -A haskellPackages.hoogle
installing ‘hoogle-4.2.43’

$ hoogle data -d ~/.hoogle
0 warnings, saved to .warnings
Data generation complete
$ hoogle '(>>=)' -d ~/.hoogle
Prelude (>>=) :: Monad m => m a -> (a -> m b) -> m b
Control.Monad (>>=) :: Monad m => m a -> (a -> m b) -> m b
Control.Monad.Instances (>>=) :: Monad m => m a -> (a -> m b) -> m b