NixOS and ghc-mod - module not found

I am experimenting with the interaction problem between the ghc-mod plugin in emacs and NixOS 14.04. Basically, after the packages are installed via nix-env -i , they are visible from ghc and ghci recognized by haskell-mode, but ghc-mod was not found.

To avoid duplication of information, you can find all the details and the exact replication of the problem in the virtual machine on the ticket with the error https://github.com/kazu-yamamoto/ghc-mod/issues/269

+6
source share
1 answer

The current default control set for Haskell on NixOS will work with packages that use ghc-api resources or similar ( ghc-mod , hint , plugins, hell, ...) runtime resources. It takes a bit more work to create Nix expression that integrates them well into the rest of the environment. It is called creating a shell expression for a package, for example, consider how GHC is installed, works with NixOS.

It is reasonable that this is difficult, because you are trying to make an installation procedure that is atomic, but interacts with an unknown number of other system packages with their own atomic installations and updates. This is doable, but there is faster work.

Take a look at this example on the wiki setup page . Instead of trying to create a ghc-mod package that works atomically, you weld it to ghc, so ghc + ghc-mod is an atomic update.

I installed ghc + ghc-mod with the installation script installed below in my ~/.nixpkgs/nixpkgs.nix .

 hsEnv = haskellPackages.ghcWithPackages (self : [ self.ghc self.ghcMod # add more packages here ]); 

Install the package with something like:

 nix-env -i hsEnv 

or better in most cases:

 nix-env -iA nixpkgs.haskellPackages.hsEnv 

I have an alias for the above, so I don't need to enter it every time. It's simple:

 nixh hsEnv 

The downside of this method is that other Haskell packages installed with nix-env -i[A] will not work with the above installation. If I wanted to get everything that works with the lens package, I would have to change the script setting to include lens like:

 hsEnv = haskellPackages.ghcWithPackages (self : [ self.ghc self.ghcMod self.lens # add more packages here ]); 

and reinstall. Nix doesn't seem to use a different setting for lens or ghc-mod in hsEnv and with ghc from nix-env -i ghc , so it seems that only a little more time has to be done behind the scenes most of the time to combine existing packages into the above mod.

ghc-mod installed with the above script, but I have not tested its integration with Emacs yet.

Additional notes added to github stream

DanielG:

I have problems working with this environment, I can’t even get cabal install to behave correctly: / I just get a lot of errors, for example:

With Nix and NixOS, you almost never use Cabal to install globally

  • Be sure to use sandboxes if you intend to use cabal-install . You probably don't need this, but its there, and it works.
  • Use ghcWithPackages when installing packages such as ghc-mod , hint , or something requires significant runtime for an existing package (they are hard to make atomic and ghcWithPackages get around this for GHC).
  • If you are developing a standard nix-env -i stdenv toolkit with nix-env -i stdenv . NixOS does not force you to use your command line and PATH with tools that you do not need.
  • cabal assumes the existence of several standard tools, such as ar , patch (I think), and several others, as well as if the memory functions correctly.

If you use the standard installation method and / or ghcWithPackages if necessary, then NixOS will deduplicate at the package level (if you build the dependency tree, they will point to the same package in /nix/store , nix-store --optimise can always deduplicate storage at the file level.), many packages automatically differ from chamber sandboxes.


Reply to comment

 [ carlo@nixos :~]$ nix-env -iA nixos.pkgs.hsEnv installing `haskell-env-ghc-7.6.3' these derivations will be built: /nix/store/39dn9h2gnp1pyv2zwwcq3bvck2ydyg28-haskell-env-ghc-7.6.3.drv building path(s) `/nix/store/minf4s4libap8i02yhci83b54fvi1l2r-haskell-env-ghc-7.6.3' building /nix/store/minf4s4libap8i02yhci83b54fvi1l2r-haskell-env-ghc-7.6.3 collision between `/nix/store/1jp3vsjcl8ydiy92lzyjclwr943vh5lx-ghc-7.6.3/bin/haddock' and `/nix/store/2dfv2pd0i5kcbbc3hb0ywdbik925c8p9-haskell-haddock-ghc7.6.3-2.13.2/bin/haddock' at /nix/store/9z6d76pz8rr7gci2n3igh5dqi7ac5xqj-builder.pl line 72. builder for `/nix/store/39dn9h2gnp1pyv2zwwcq3bvck2ydyg28-haskell-env-ghc-7.6.3.drv' failed with exit code 2 error: build of `/nix/store/39dn9h2gnp1pyv2zwwcq3bvck2ydyg28-haskell-env-ghc-7.6.3.drv' failed 

This is a line starting with a collision that tells you what is going wrong:

 collision between `/nix/store/1jp3vsjcl8ydiy92lzyjclwr943vh5lx-ghc-7.6.3/bin/haddock' and `/nix/store/2dfv2pd0i5kcbbc3hb0ywdbik925c8p9-haskell-haddock-ghc7.6.3-2.13.2/bin/haddock' at /nix/store/9z6d76pz8rr7gci2n3igh5dqi7ac5xqj-builder.pl line 72. 

This is a conflict between two different haddocks. Switch to the new profile and try again. Since this is welding together ghc + packages, it should not be installed in the profile with other Haskell packages. This does not stop you from running executables and breakers from both packages at the same time, they just have to be in their own namespace, so when you call haddock, cabal, ghc, there is only one choice for each profile.

If you are not already familiar with profiles, you can use:

 nix-env -S /nix/var/nix/profiles/per-user/<user>/<New profile name> 

Default profile: default or channels not what it will be for your setup. But check that you can return to it later. There are some tricks, so you do not need to use the /nix/var/nix/profiles/ directory to store profiles to cut out text, but this is the default location.

+6
source

Source: https://habr.com/ru/post/970860/


All Articles