IIRC, issuing:

$(grep export /nix/store/<your-current-ghc-hash>/bin/ghc)

(or maybe ~/.nix-profile/bin/ghc will work as well if you have your haskell
tools in your home profile)

in your working shell sets NIX-specific environment variables that the ghc
api uses to locate the package database by sourcing the wrapper code around
ghc. Actually, hdevtools should probably just be wrapped similarly itself,
though I think there might be some problems with that (not that I remember
right now).

I'm using hdevtools myself, and if this is insufficient to get it working I
might be forgetting some part of my setup.

Now, for haskell development in general I can recommend making shell
environments per haskell project you develop using the myEnvFun (see
https://nixos.org/wiki/Howto_develop_software_on_nixos)
I have a file with something along the lines of:

A general dev-env.nix:
-----------------

# This nix environment contains all the tools used in the process of
developing
# Because each package has its own dependencies, this file provides a
function
# for creating environments, rather than a concrete environment.
# envName :: String -- The suffix of the name of the resulting environment.
# hsEnvDeps :: HsPkgs -> [CabalNix] -- the dependencies of the package being
#   developed in this environment.
{ envName, hsEnvDeps } :
let
  pkgs = import <nixpkgs> {};
  hsEnv = pkgs.haskellPackages.ghcWithPackagesOld (hsPkgs : ([
    hsPkgs.hlint
    hsPkgs.hdevtools
    hsPkgs.hasktags
    ] ++ (hsEnvDeps hsPkgs)));
in
  pkgs.myEnvFun {
    name = envName;
    buildInputs = with pkgs; [
      binutils
      coreutils
      ctags
      vimHugeX
      zsh
      hsEnv
      ];
    shell = "${pkgs.zsh.outPath}/bin/zsh";
    extraCmds = ''
      $(grep export ${hsEnv.outPath}/bin/ghc)
    '';
    }

...And a project-env.nix file for each project:
-----------------------------------------------------------
let
  envFun        = import ./dev-env.nix;
  projectCabal = import ./cabal.nix;
in
  envFun {
    envName   = "myproject";
    hsEnvDeps = hsPkgs :
     (let
       deriv = hsPkgs.callPackage projectCabal (rec {
         # satisfy dependencies not in hsPkgs by adding them here.
         });
     in deriv.nativeBuildInputs ++ deriv.propagatedNativeBuildInputs);
    }

And 'cabal.nix' being the file output by the cabal2nix tool applied to your
cabal file.

Then just issuing

$ nix-build project-env.nix
$ ./result/bin/load-env-myproject

gives you a completely selfcontained, replicatable development environment
where everything is wired to the same package database. (Except for the vim
plugins for hdevtools, syntastic etc, which I have yet to figure out how to
include in my nix expression. So for the time being these should be
installed separately in ~/.vim)


2014-06-18 11:11 GMT+02:00 Thomas Strobel <[email protected]>:

> Hi!
>
> I've got a question for those using Haskell under NixOS. I'm trying to
> use hdevtools to check my Haskell source file, but hdevtools does not
> find any modules. ghc-pkg does, as does ghc-mod. From what I have read
> it might be necessary to set some environment variables.
> Can someone maybe give me an example of how to use hdevtools under NixOS?
>
> Many thanks in advance,
> Thomas
> _______________________________________________
> nix-dev mailing list
> [email protected]
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>
_______________________________________________
nix-dev mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-dev

Reply via email to