stack build error: attribute ‘ghc822’ missing, at (string):1:53

It seems like your stack wants to retrieve the haskell.packages.ghc822 attribute or perhaps haskell.compiler.ghc822, which is not present in your version of <nixpkgs>.

Please check your channel configuration using sudo nix-channel --list (NixOS) or nix-channel --list. Releases 17.03 and older do not have this attribute. 17.09 and unstable should be fine. To switch your default <nixpkgs> to 17.09, note the name of the channel and run

nix-channel --add https://nixos.org/channels/nixos-17.09 <NAME>

Also run nix-channel --update to make sure you have a recent version. GHC 8.2.2 was added on Oct 31st.

If you don't want to change your channel configuration, I suppose you can set the NIX_PATH environment variable

NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz stack build

Another option is to use a shell.nix. nixos-18.03 comes with ghc 8.2.2, so you can create a shell.nix like:

with import (builtins.fetchGit {
    url = https://github.com/NixOS/nixpkgs-channels;
    ref = "nixos-18.03";
    rev = "cb0e20d6db96fe09a501076c7a2c265359982814";
}) {};

haskell.lib.buildStackProject {
    name = "my-project";
    buildInputs = [ ghc <otherlibs-here> ];
}

And add the following to your stack.yaml:

nix:
  shell-file: shell.nix

Then stack build as usual.


You can provide an old GHC version using a shell.nix file place in the root of your project:

with import (fetchTarball https://github.com/NixOS/nixpkgs/archive/83b35508c6491103cd16a796758e07417a28698b.tar.gz) {};
let ghc = haskell.compiler.ghc802;
in haskell.lib.buildStackProject {
    inherit ghc;
    name = "myEnv";
    buildInputs = [ pcre ];
}

Use a tar url from https://github.com/NixOS/nixpkgs/releases for a version of nixpkgs that contains the GHC version you need.

Then run nix-shell in the root of the project. This will put you into a shell in which you can perform stack build successfully since it would have access to the correct GHC version.