travisbhartwell/nix-emacs

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

cumber opened this issue · 3 comments

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.

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.

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

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