travisbhartwell / nix-emacs

A set of useful Emacs modes and functions for users of Nix and Nix OS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Name collision with nix-mode

c0deaddict opened this issue · comments

I'm using nix-mode and would like to also make use of nix-sandbox for Flycheck (and other executables where possible). Unfortunately the example code in the README does not work. When trying to Flycheck a file I get the error:

eval: Wrong number of arguments: (1 . 2), 3

After some digging I found that the bug appears to be that nix-sandbox declares a function called nix-shell which overlaps with a function defined in the nix-mode package.

@c0deaddict, thank you for reporting this issue. I'll take a look.

Yes, there is a name conflict, but I don't think the error you are getting is related to this name conflict. Just to be sure, can you retry without loading the nix-mode package?

Without loading nix-mode it works. I think the problem is that i'm loading nix-sandbox before nix-mode hence nix-shell of nix-sandbox is redefined. Without changing the loading order, this "fix" works:

  (use-package nix-mode
    :ensure t
    :init
    (add-to-list 'interpreter-mode-alist '("nix-shell" . nix-shebang-mode))
    (add-to-list 'auto-mode-alist '("\\.nix\\'" . nix-mode))
    :config
    ;; Override nix-shell defined in nix-mode with this definition from nix-sandbox.
    ;; https://github.com/travisbhartwell/nix-emacs/issues/48
    (defun nix-shell (sandbox &rest command)
      "Run a COMMAND in the given SANDBOX and return the output."
      (shell-command-to-string (apply 'nix-shell-string sandbox command)))
    )

Great, thanks for testing. I'll just rename the function.

Thanks!

Hello!

First, thanks for creating and sharing this package! 🍻

I have stumbled upon this problem as well. I've made a PR with a possible solution: #49

Cheers!