Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install Cabal, GHC, or GHCJS with one Nix command
# install nix (5.5 mins)
curl | sh
# open a new shell to source nix
# query available haskell compilers
nix-env -qaP -A nixpkgs.haskell.compiler [QUERY]
# install ghc (2.5 mins, cached binary)
nix-env -iA nixpkgs.haskell.compiler.ghc865
# ghc is now in your PATH
ghc --version
# query cabal install version
nix-env -qaP -A nixpkgs.haskellPackages.cabal-install
# install cabal install (0.5 mins, cached binary)
nix-env -iA nixpkgs.haskellPackages.cabal-install
# cabal is now in your PATH
cabal --version
# Install ghcjs (take one sleep, build from source, with `-j1`)
# It will appear to hang at places like 'Preprocessing library for unix-'
# Use `ps -ef | grep nix` to check it is still doing work.
nix-env -iA nixpkgs.haskell.compiler.ghcjs
# ghcjc is now in your PATH
ghcjs --version
# cleanup disk space from unused nix stuff
nix-collect-garbage -d
# uninstall everything
sudo rm -rf /nix
Copy link

louispan commented Oct 10, 2019

More nix commands, only if you want to use nix to install packages for reproducible releases.
Otherwise, just use cabal to build packages

query haskell packages

nix-env -qaP -A nixpkgs.haskellPackages [QUERY]

list pre-built packages for a specific compiler

nix-env -qaP -A nixpkgs.haskell.packages.ghc865 [QUERY]

The first segment of a package can be replaced with -f NAMESPACE

nix-env -qaP -A nixpkgs.haskell.packages.ghc865 [QUERY]
nix-env -f "<nixpkgs>" -qaP -A haskell.packages.ghc865 [QUERY]

Copy link

louispan commented Oct 11, 2019

To build ghcjs faster, you can git clone, remove the -j1, (the -j1 flag is used to prevent an intermittent panic which might have been fixed) and then install the modified pkg

nix-env -f /path/to/cloned/nixpkgs -iA haskell.compiler.ghcjs

Copy link

MurakamiKennzo commented Dec 25, 2021

Thanks, I did it.😘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment