nix-emacs
nix-emacs copied to clipboard
nix-find-sandbox does not behave as advertised
(defun nix-find-sandbox (path)
"Search for a sandbox starting at PATH traversing upwards the directory tree.
If the directory contains a `shell.nix' file, the path to this
file is returned. Otherwise if the directory contains a
`default.nix' file, the parent directory is returned."
The implementation seems to detect the presence of any file ending in .nix
, not just default.nix
. This is a problem for me, because I have .nix
files in various directories that do not correspond to usable shells for development.
So what do you suggest? Search only for shell.nix
files or for shell.nix
and default.nix
files?
I can't think of a situation where I'd want it to pick anything other than shell.nix
, but I could be wrong - I haven't been developing in Nix very long.
I'd also like the search to never extend beyond a Git or Projectile root. So really I think the more important thing is just to make this function customizable.
Maybe this can help someone, I redefined the function for my config like this:
(defun nix-find-sandbox-file (path file)
"Find the given FILE by walking to / starting from PATH"
(let ((found
(locate-dominating-file
path (lambda (dir) (file-exists-p (concat dir (f-path-separator) file) )))))
(and found (concat (expand-file-name found) file))))
(defun nix-find-sandbox (path)
"Find the closest nix-shell, prefer shell.nix but if none is found settle with default.nix"
(and (file-exists-p path)
(or (nix-find-sandbox-file path "shell.nix")
(nix-find-sandbox-file path "default.nix"))))