Skip to content

Instantly share code, notes, and snippets.

@katychuang
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katychuang/288ac8b21c1b912dd755 to your computer and use it in GitHub Desktop.
Save katychuang/288ac8b21c1b912dd755 to your computer and use it in GitHub Desktop.
nix installation on OSX 10.10 with ghc 7.8 and Cabal-1.22
# ~/.nixpkgs/config.nix
{
# ~/.nixpkgs/config.nix lets us override the Nix package set
# using packageOverrides. In this case we extend it by adding
# new packages using myEnvFun.
packageOverrides = pkgs : with pkgs; {
ghc76 = pkgs.myEnvFun {
name = "ghc76";
buildInputs = [ ghc.ghc763 ];
};
ghc78 = pkgs.myEnvFun {
name = "ghc78";
buildInputs = [ ghc.ghc784 ]; #look for ghc versions in: $HOME/nixpkgs/pkgs/development/compilers/ghc
};
};
}
pwd # currently in ~/
git clone https://github.com/NixOS/nixpkgs.git #saves to ~/nixpkgs
# connect nix for the following nix commands to work
. $HOME/.nix-profile/etc/profile.d/nix.sh
# had to type in /Users/yourname/.nix-profile/etc/profile.d/nix.sh for this line to work.
# seems like I have to type this command in each time I create a new terminal window
nix-channel --remove nixpkgs
cd ~/.nix-defexpr
rm -rf *
ln -s $HOME/nixpkgs nixpkgs
# again, had to type in /Users/yourname/nixpkgs instead of $HOME variable
nix-env -i hello
# next, followed guide from http://chromaticleaves.com/posts/nix-in-2-days.html
# create the config.nix file. see attached example.
#look for ghc versions in: $HOME/nixpkgs/pkgs/development/compilers/ghc
nix-env -i env-ghc78
load-env-ghc78

To install nix on OSX10.10, I first followed this nixos.org wiki guide shared by @boothead, and then found this guide on setting up a haskell environment with nix. See config.nix file below. I made one change from the tutorial, which is to change ghc783 to ghc784 (line 13).

After creating the file ~/.nixpkgs/config.nix, I skipped the ghc76 stuff and went straight to nix-env -i env-ghc78. It took a bit more than 2 hrs on an 8gb ram MBA for everything to build and link. The end result says

building path(s) ‘/nix/store/6rcj8chl2vim4mry5k7w8gs7nxifxixc-user-environment’
created 51 symlinks in user environment

Then finally: load-env-ghc78 loaded up a shell from which I could ghci

Don't know if it's important but for posterity, I'm going to make a note here that I was in $HOME/nixpkgs when running the nix-env -i env-ghc78 and load-env-ghc78 commands. Using github.com/NixOS/nixpkgs.git commit 6a24650 dated Sat Feb 7 18:45:56 2015 +0100

Also, I found a write up by ocharles.org.uk about the advantages of nix and the difference between nix/nixpkgs/nixos, which was helpful but definitely see the wiki guide and chromaticleaves for installation.

# Here are my path settings
# Note: you might have to type out the exact path, i.e. /Users/yourname/.cabal
export NIX_PATH=$HOME/nixpkgs/pkgs:nixpkgs=$HOME/nixpkgs/pkgs
# these were existing settings. Not sure if they needed for nix, but for thorough note-taking am including them here.
export GHC_HOME=/usr/local/bin # not /usr/local/bin/ghc
export CABAL_HOME=$HOME/.cabal/ # not $HOME/.cabal/bin
export PATH=$GHC_HOME:$CABAL_HOME/bin:${PATH}
# quotes only required if your directory name has spaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment