[Feature]: Support Flake and nix develop
Is your feature request related to a problem? Please describe. Selecting a flake.nix file from the environment selector dropdown currently doesn't work (the "Applying environment..." status keeps spinning).
Describe the solution you'd like
Compatibility with the newer nix develop shell.
Describe alternatives you've considered
It's possible to create a shell.nix file that provides a compatibility layer, however I thin kit doesn't benefit from the performance improvements with nix develop:
(import (
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
) {
src = ./.;
}).shellNix
Yes! This would be awesome! I just moved all my projects over to flakes, but this has been holding me back...
What would be needed for this? I didn't look into how this extension works, but I believe a hacky solution would be using flake-compat as explained by the OP. It would basically be something like nix-build -E '(import (fetchTarball { /* flake-compat url and hash */ }) { src = ./.; }).shellNix' which I think the extension could use (again, I don't how the extension handles this).
Just to be clear, if I create a shell.nix with the content that @jmatsushita is proposing.. this should be working already? because it's not for me :-( Even if nix-shell shell.nix works.
It works already if you create the shell.nix file and you select shell.nix with the Nix Env: Select Environment command.
@arrterian I'd happily sponsor work that would result in this being implemented, do you think that could be arranged?
@arrterian I'd happily sponsor work that would result in this being implemented, do you think that could be arranged?
I will pledge $20 worth of Monero if that means anything : )
What would be needed for this?
Some notes:
Implementation wise, for covering nix develop I'd estimate the main work would be in src/main/ext/nix_env.cljs. https://github.com/arrterian/nix-env-selector/blob/472c4c4211f13f74ea27418e1ec30a706b809e5f/src/main/ext/nix_env.cljs, the actions.cljs then uses env/get-nix-env-async and env/set-current-env.
This file seems to roughly take the output of nix-shell --run "export", and parses the various declare -x name="nix-shell".
The nix flake equivalent nix develop at least provides nix print-dev-env --json which may be easier to make use of as a way to get environment variables from a flake devshell.
For covering nix shell nixpkgs#<pkg>, I guess it'd involve something like the equivalent of getting the path from nix build nixpkgs#gcc --no-link --json.
The setting name nixEnvSelector.nixFile doesn't make as much sense for flake devshells as it does for the nix-shell command.
If anyone is looking for a workaround: https://github.com/srid/haskell-template uses flake-compat to provide a shell.nix that in turn uses flake.nix (as well as flake.lock). All of that can go away if this issue gets implemented. Using direnv is another option.
EDIT: It no longer uses flake-compat, and shell.nix simply contains: (builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default
For another workaround, consider using nix-direnv and its appropriate vscode extension too - it seems to work with use flake for me.
@kubukoz wdym the appropriate vscode extension? The direnv one? So no need for this one?
@mimoo yeah, I'm using this one: https://marketplace.visualstudio.com/items?itemName=Rubymaniac.vscode-direnv
This one's being maintained actively: https://marketplace.visualstudio.com/items?itemName=mkhl.direnv