nix-community / nix-emacs

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

nix-shell-command and nix-find-executable should work when there is no current sandbox #41

Closed cumber closed 7 years ago

cumber commented 7 years ago

The code suggested in the readme for things like getting flycheck to find executables from a nix shell is this:

(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)))

This works fine even for executables that aren't in the shell, but are in your normal PATH. But when you open a file that isn't in a nix shell, nix-current-sandbox returns nil and nix-shell-command and nix-find-executable throw an error on receiving nil, even when the executable that's being asked for could be resolved without a nix shell.

This makes the suggested code unsuitable for putting as global configuration for flycheck; instead it needs to be activated per project.

I could make the flycheck customisation functions more complex and check whether nix-current-sandbox is returning nil, but it'd be much nicer if these functions could instead be no-ops if passed nil (or if nix-current-sandbox could indicate that there isn't a current sandbox in some other way). Then the suggested configuration would "just work" more of the time.

svenkeidel commented 7 years ago

I agree, this is a problem. I think that using nil to representing that no sandbox could be found is fine. Accordingly all functions that do not handle nil gracefully should be changed. I look into it.

svenkeidel commented 7 years ago

@cumber, let me know if this fixed it. Otherwise, please reopen.

cumber commented 6 years ago

@svenkeidel Thanks for the fix; seems to have worked.