The prior code is a partial solution, shell.nix is not required to exist, default.nix can be used instead, and even with looking only in Haskell project root dir - the relevant {default,shell}.nix can be found arbitrary number of the levels up the filesystem hierarchy (practical limit is Git the repo).
The default standardized nix-shell behavior and expectation is that if shell.nix not found - nix-shell loads default.nix (which, if exists - is always possible, since default.nix describes package derivation, and package derivation always can be loaded as shell environment by Nix), so there are a number of projects that do not have shell.nix, but, expect default.nix to be used instead.
And then there is are projects where shell.nix or default.nix can be in ../ or up the tree - there is a subset of the project with those types of quirks, for example, Target company Nix configurations promote that approach. This all (for all intents and purposes - all) cases is solved by using a well-supported/used library function from the https://github.com/travisbhartwell/nix-emacs, package nix-sandbox, function nix-current-sandbox - "searches for a sandbox file starting from the current working directory".
The prior code is a partial solution,
shell.nix
is not required to exist,default.nix
can be used instead, and even with looking only in Haskell project root dir - the relevant{default,shell}.nix
can be found arbitrary number of the levels up the filesystem hierarchy (practical limit is Git the repo).The default standardized
nix-shell
behavior and expectation is that ifshell.nix
not found -nix-shell
loadsdefault.nix
(which, if exists - is always possible, sincedefault.nix
describes package derivation, and package derivation always can be loaded as shell environment by Nix), so there are a number of projects that do not haveshell.nix
, but, expectdefault.nix
to be used instead.And then there is are projects where
shell.nix
ordefault.nix
can be in ../ or up the tree - there is a subset of the project with those types of quirks, for example, Target company Nix configurations promote that approach. This all (for all intents and purposes - all) cases is solved by using a well-supported/used library function from the https://github.com/travisbhartwell/nix-emacs, packagenix-sandbox
, functionnix-current-sandbox
- "searches for a sandbox file starting from the current working directory".