Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Support Flake and nix develop #53

Open
jmatsushita opened this issue Mar 13, 2021 · 12 comments
Open

[Feature]: Support Flake and nix develop #53

jmatsushita opened this issue Mar 13, 2021 · 12 comments
Assignees
Labels
enhancement New feature or request

Comments

@jmatsushita
Copy link

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
@zyansheep
Copy link

Yes! This would be awesome! I just moved all my projects over to flakes, but this has been holding me back...

@yusdacra
Copy link

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).

@edulix
Copy link

edulix commented Nov 3, 2021

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.

@jmatsushita
Copy link
Author

It works already if you create the shell.nix file and you select shell.nix with the Nix Env: Select Environment command.

@kubukoz
Copy link

kubukoz commented Dec 23, 2021

@arrterian I'd happily sponsor work that would result in this being implemented, do you think that could be arranged?

@zyansheep
Copy link

@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 : )

@rgoulter
Copy link

rgoulter commented Mar 2, 2022

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.

@srid
Copy link

srid commented May 29, 2022

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

@kubukoz
Copy link

kubukoz commented May 30, 2022

For another workaround, consider using nix-direnv and its appropriate vscode extension too - it seems to work with use flake for me.

@mimoo
Copy link

mimoo commented Jul 6, 2022

@kubukoz wdym the appropriate vscode extension? The direnv one? So no need for this one?

@kubukoz
Copy link

kubukoz commented Jul 6, 2022

@srid
Copy link

srid commented Jul 6, 2022

This one's being maintained actively: https://marketplace.visualstudio.com/items?itemName=mkhl.direnv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants