travisbhartwell / nix-emacs

A set of useful Emacs modes and functions for users of Nix and Nix OS.
225 stars 32 forks source link

flycheck s not working with nix-sandbox #19

Closed wedens closed 8 years ago

wedens commented 8 years ago

I've added this configuration from README to my .emacs:

(setq flycheck-command-wrapper-function
        (lambda (command) (apply 'nix-shell-command (nix-current-sandbox) command))
      flycheck-executable-find
        (lambda (cmd) (nix-executable-find (nix-current-sandbox) cmd)))

flycheck-verify-setup output:

Syntax checkers for buffer API.hs in haskell-mode:

  haskell-stack-ghc
    - predicate:  nil
    - executable: Not found

  haskell-ghc
    - predicate:  nil
    - executable: Not found

  haskell-hlint
    - predicate:  nil
    - executable: Not found

Flycheck Mode is enabled.

my shell.nix (generated by cabal2nix):

{ nixpkgs ? import <nixpkgs> {}, compiler ? "default" }:

let

  inherit (nixpkgs) pkgs;

  f = { mkDerivation, base, blaze-builder, blaze-html, bytestring
      , containers, cookie, either, mtl, postgresql-simple, servant
      , servant-blaze, servant-server, SHA, stdenv, stm, text, time
      , transformers, uuid, wai, warp
      }:
      mkDerivation {
        pname = "xxx";
        version = "0.1.0.0";
        src = ./.;
        isLibrary = false;
        isExecutable = true;
        executableHaskellDepends = [
          base blaze-builder blaze-html bytestring containers cookie either
          mtl postgresql-simple servant servant-blaze servant-server SHA stm
          text time transformers uuid wai warp
        ];
        license = stdenv.lib.licenses.mit;
      };

  haskellPackages = if compiler == "default"
                       then pkgs.haskellPackages
                       else pkgs.haskell.packages.${compiler};

  drv = haskellPackages.callPackage f {};

in

  if pkgs.lib.inNixShell then drv.env else drv

@svenkeidel

svenkeidel commented 8 years ago

I use a different style for my shell.nix file. Can you create a new directory with these files. Then open the Main.hs file and see if it works?

shell.nix

{ pkgs ? import <nixpkgs> {} }:

let env = pkgs.haskellPackages.ghcWithPackages(p: with p; [
    Cabal cabal-install hlint
  ]);
in pkgs.stdenv.mkDerivation {
  name = "xxx";
  version = "0.1.0.0";
  src = ./.;
  buildInputs = [ env ];
  shellHook = ''
    export NIX_GHC="${env}/bin/ghc"
    export NIX_GHCPKG="${env}/bin/ghc-pkg"
    export NIX_GHC_DOCDIR="${env}/share/doc/ghc/html"
    export NIX_GHC_LIBDIR=$( $NIX_GHC --print-libdir )
  '';
}

Main.hs

main = print "hello"
wedens commented 8 years ago

Still nothing. No executables for checkers detected. PATH in nix-shell is correct

svenkeidel commented 8 years ago

Can you try the following steps please

  1. Restart Emacs.
  2. In the Main.hs file, can you execute the commands (nix-current-sandbox), (nix-exec-path (nix-current-sandbox)) and (nix-executable-find (nix-current-sandbox) "hlint") with M-: and send me the output.
wedens commented 8 years ago

@svenkeidel flycheck successfully finds ghc/hlint binaries without nix-sandbox (but obviously is unable to find dependenies) (nix-current-sandbox) shows correct path. (nix-exec-path (nix-current-sandbox)) is empty! (nix-executable-find (nix-current-sandbox) "hlint") is nil

svenkeidel commented 8 years ago

Ok, what nix-exec-path does is, it simply executes nix-shell --run 'echo $PATH' inside the sandbox directory. nix-executable-find then uses this path and calls the normal executable-find function of Emacs with the path it got from nix-exec-path.

So it seams, the problem is in nix-exec-path. Can you try the following things and send me the output please:

wedens commented 8 years ago

Result of nix-shell --run 'echo $PATH':

nix/store/r843jhj8hv5sg4qs45pp8l92bayiiigh-ghc-7.10.2/bin:/nix/store/30ayza19w9yyrv3qd4m9i0cxkly08ni0-patchelf-0.8/bin:/nix/store/pzyz725flnqnkbfc6ndn79nmk89zqvap-paxctl-0.9/bin:/nix/store/piq5rxp8c91j5bn9bir9k67agg1fa199-gcc-wrapper-4.9.3/bin:/nix/store/zzj4664wj266mnd8a1l21ggw21g4x2ya-coreutils-8.24/bin:/nix/store/z074lx3wfy4hi14ygdxbysg6i4cl2vsl-findutils-4.4.2/bin:/nix/store/fj6343mw2qphj3fcglpai5x5inlmx4c4-diffutils-3.3/bin:/nix/store/9302xvrawv1qx9991fwg9n0b22c1b47i-gnused-4.2.2/bin:/nix/store/yvi31c5mqaz072sdn5pmh0qhy944i7gd-gnugrep-2.22/bin:/nix/store/3s0fzyxjygylzcrhi71va3sa2g5jwh45-gawk-4.1.3/bin:/nix/store/n6sypqbklshikk0qf8wkbbwyxikzj2z1-gnutar-1.28/bin:/nix/store/gbvijz4iy7a6vb3fcnggaykwrwfnlvnl-gzip-1.6/bin:/nix/store/sc2yq86dh48rlw6y5k9876s3mbkh9ip3-bzip2-1.0.6/bin:/nix/store/gwvh88diwx72rqfwm4nd6wvs3gbgjfra-gnumake-4.1/bin:/nix/store/7d2g3bvmbi5ps3vlkl54h7d7yasc4ynv-bash-4.3-p42/bin:/nix/store/i3f6jxcl1igpsn3b6p9qq15rhfsk8a1x-patch-2.7.5/bin:/nix/store/9dh83qvaqpxkk6d9vvf4g2xfm9v1qk5m-xz-5.2.2/bin:/nix/store/2xrkp6zca9hbmsdjfb3v09dv4awaqyap-gcc-4.9.3/bin:/nix/store/5kdjp8200hazaydx0dmwn5qghqkyi3py-binutils-2.23.1/bin:/nix/store/483br9kb3f5igsgmb6aqsjhl2ipj2bxr-glibc-2.21/bin:/nix/store/zzj4664wj266mnd8a1l21ggw21g4x2ya-coreutils-8.24/bin:/home/wedens/dotfiles/scripts:/home/wedens/dotfiles/scripts:/home/wedens/bin:/var/setuid-wrappers:/home/wedens/.nix-profile/bin:/home/wedens/.nix-profile/sbin:/home/wedens/.nix-profile/lib/kde4/libexec:/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/sbin:/nix/var/nix/profiles/default/lib/kde4/libexec:/run/current-system/sw/bin:/run/current-system/sw/sbin:/run/current-system/sw/lib/kde4/libexec

(nix-shell (nix-current-sandbox) "echo" "$PATH") output is empty. and every other command called via (nix-shell (nix-current-sandbox) cmd) results in empty string

svenkeidel commented 8 years ago

I think I have found the error. If you execute nix-shell --run 'echo $PATH' /path/to/sandbox/ and the sandbox directory does not contain a default.nix file, then you get the error opening file '/path/to/sandbox/default.nix': No such file or directory. So I fixed this issue by improving the nix-find-sandbox function to return the path to the shell.nix file if one exists and otherwise return the path to the parent directory of a default.nix file. I upload the patch shortly.

svenkeidel commented 8 years ago

Sorry, it seams that I have no commit bit yet. In the mean time, can you try svenkeidel/nix-emacs@8033ccfd6904f2caee54f433e58b2eddc4e73836 and see if (nix-shell (nix-current-sandbox) "echo" "$PATH") works now?

wedens commented 8 years ago

yeah. now it shows the same path as in shell. and flycheck is able to find ghc binary

svenkeidel commented 8 years ago

Cool, now flycheck should work. Try opening a Haskell file and activate flycheck-mode

wedens commented 8 years ago

haskell-mode - :white_check_mark: flycheck - :white_check_mark:

thanks for the fix!

svenkeidel commented 8 years ago

Thank you very much for your contribution. Can you close this issue now?

wedens commented 8 years ago

sure

wedens commented 8 years ago

will nix-sandbox be released on MELPA?

svenkeidel commented 8 years ago

I would like to do a little bit more testing before I release on MELPA, but yeah, this is the plan.

travisbhartwell commented 8 years ago

@svenkeidel Speaking of releasing on MELPA, did you get my email from earlier this week?

svenkeidel commented 8 years ago

Yes I got the mail. As I said, I would like to do a little bit more testing before I release.

travisbhartwell commented 8 years ago

@svenkeidel You should have commit bit now, just let me know when you are ready for a release.