Philip, thank you so much for your help and your detailed description,
it is very much appreciated! Having your example to compare it with how
the standard environment includes the search paths helped me a lot in
understanding how everything is supposed to work.

The custom environment---using ghcWithPackages---that you're suggesting
seems to be using the exported environment variables to find the
packages' information.

In the default environment ghc instead relies on the script 
'/nix/store/m9f..-ghc-get-packages.sh' to collect all packages'
information. It can be called with the ghc's version number.

The reason why ghc-mod works in the default environment is because it is
wrapped to call the ghc-get-packages.sh script as well. I'll try to
patch hdevtools the same way to make it work. I'll probably only have to
change the script's output from '-package-db xxx' to '-g-package-db=xxx'
to make it compatible with hdevtools.

Thanks again!
Thomas


On 06/19/2014 10:34 PM, Philip Carlsen wrote:
> tl;dr; To answer your questions: the contents of my ghc installed ghc
> wrapper is listed below, and no, your installed packages should not
> show up in the same nix-store location as your ghc (unless you use
> shell environments like in my previous mail).
>
> So, I guess it comes down to which method you use to deploy ghc and
> haskell packages on your machine. It sunds to me like your process is
> something along the lines of:
>
> $ nix-env -i cabal-install
> $ cabal install hdevtools ...
>
> I think I tried something like that in the beginning, but switched to
> using per-project environments due to both the poor integration with
> ad-hoc cabal installs and of course the benefits of isolated
> dependency tracking (though arguably that could be achieved using
> cabal-dev or cabal sandbox).
>
> When using a dedicated project shell environment, ghc is wrapped
> differently:
>
> % which ghc
> /nix/store/lvb..nz-haskell-env-ghc-7.6.3/bin/ghc
>
> % cat $(which ghc)
> #! /nix/store/fp...v9sq-bash-4.2-p45/bin/bash -e
> export NIX_GHC=/nix/store/lvb..nz-haskell-env-ghc-7.6.3/bin/ghc
> export NIX_GHCPKG=/nix/store/lvb..nz-haskell-env-ghc-7.6.3/bin/ghc-pkg
> export
> NIX_GHC_DOCDIR=/nix/store/lvb..nz-haskell-env-ghc-7.6.3/share/doc/ghc/html
> export
> NIX_GHC_LIBDIR=/nix/store/lvb..nz-haskell-env-ghc-7.6.3/lib/ghc-7.6.3
> exec /nix/store/b9....sgl-ghc-7.6.3/bin/ghc "-B$NIX_GHC_LIBDIR"
> "${extraFlagsArray[@]}" "$@"
>
> When thinking about it, it might just be enough to just
>
> export NIX_GHC_LIBDIR=~/.ghc-7.6.3/packages.conf.d
> (or whatever now the correct path to the cabal user (or sandbox)
> package database is..)
>
>
> Now, if you've used nix-env to install your haskell dependencies and
> tools you might not be as lucky as in the first case, as the package
> database resides in ~/.nix-profile/ and is spread over multiple files
> (one per cabal package) due to the read-only nature of the nix-store,
> and the GHC api used to list the available packages (as it appears to
> hdevtools) needs to be specifically instructed to consider each of
> these files (this may be what the ghc-get-packages.sh script in your
> ghc wrapper actually does, but that may just be speculation on my part)
>
> I hope I've given you some leads to proceed :-)
>
>
> 2014-06-19 12:26 GMT+02:00 Thomas Strobel <ts...@cam.ac.uk
> <mailto:ts...@cam.ac.uk>>:
>
>     Hi,
>
>     thanks for your help, Thomas and Philip, but I would have two
>     further questions.
>
>     - What should be exported in /nix/store/<current-ghc-hash>/bin/ghc
>     ? My ghc wrapper only looks like:
>     '''
>     #! /nix/store/...--bash-4.2-p45/bin/bash -e
>     exec /nix/store/...-ghc-7.6.3/bin/ghc
>     $(/nix/store/...-ghc-get-packages.sh 7.6.3 "$(dirname $0)")
>     "${extraFlagsArray[@]}"
>     "$@"
>     '''
>
>     -
>     '/nix/store/...ghc-<version>-wrapper/lib/ghc-<version>/package.conf.d'
>     seems to contain only configurations for a few standard modules.
>     Should all packages which are installed on my system show up in there?
>
>
>     Again, many thanks!
>     Thomas
>
>
>
>     On 06/18/2014 02:45 PM, Philip Carlsen wrote:
>>     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 <ts...@cam.ac.uk
>>     <mailto:ts...@cam.ac.uk>>:
>>
>>         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
>>         nix-dev@lists.science.uu.nl <mailto:nix-dev@lists.science.uu.nl>
>>         http://lists.science.uu.nl/mailman/listinfo/nix-dev
>>
>>
>
>
>     _______________________________________________
>     nix-dev mailing list
>     nix-dev@lists.science.uu.nl <mailto:nix-dev@lists.science.uu.nl>
>     http://lists.science.uu.nl/mailman/listinfo/nix-dev
>
>

_______________________________________________
nix-dev mailing list
nix-dev@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-dev

Reply via email to