-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add support for nix-shell in JetBrains products #1
Comments
Yes of course, using profiles or shells for development is one of the main goals of this plugin. |
Hi, Any update on this project? |
Maybe |
Just note that EnvFile is not currently supported across all JetBrains applications, unfortunately. Most notably for me is CLion (for Rust envs, etc.) Related: ashald/EnvFile#71 |
I generally start my |
@jonringer - for the work-around win. :) Big thanks. I've been wracking my brain all afternoon trying to get it working. I'm now running NixOS on several machines and wanted to start using nix-shell instead of venv. Another vote for native support. Some additional details to anyone still trying to figure out:
|
I created a plugin to load direnvs It works, but is nothing but a big hack (because the JVM does not want you to modify the environment...). To natively support changing the environment on a per project basis, the IDE could clone the environment from the OS (like the JVM does it) and pass the clone to all processes it launches while allowing modifications. This would allow implementing direnv support without hacks. |
@ergose Thank you for the instructions! That wasn't quite enough to get IDEA to pick up the Python dependencies, I also had to add pip to the Unfortunately the Neither the envfile nor intellij-direnv seem to work for wiring up the SDK when using Nix outside of NixOS. The workaround is to change the path to the SDK every time the Nix shell is updated. |
Hello, I came across this plugin that tries to add this feature. Maybe there are some interesting ideas that could be exploited. |
Thanks for your suggestions. I am reluctant to integrate the solution of Enter Nix Shell or intellij-direnv into this plugin. 😔 They both work by changing the environment of the IDEA process. This means that you cannot have different environments per project. While changing the IDEA environment with these plugins might be easier than restarting the whole IDE, it might also work less reliable. For example, see this page from Enter Nix Shell (archive.org). Besides that, you could also end up with a mix of multiple environments, which could have strange effects in some edge cases. While you might very well use one of these plugins, I feel like the implementations are too unstable for an official solution. At least that is my personal opinion. |
I used this weekend to explore the IntelliJ Platform API for alternatives. Unfortunately, I haven't found a good solution. Run targetsI found Run targets (extension point Run configuration extensionsEnvFile and ProjectEnv use Program runnerI also found the extension point Source code
plugin.xml <extensions defaultExtensionNs="com.intellij">
<programRunner implementation="org.nixos.idea.shell.NixProgramRunner" order="first"/>
</extensions> NixProgramRunner.java public final class NixProgramRunner implements ProgramRunner<RunnerSettings> {
@Override
public @NotNull @NonNls String getRunnerId() {
return "nix-shell-wrapper";
}
@Override
public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
return true;
}
@Override
public void execute(@NotNull ExecutionEnvironment environment) throws ExecutionException {
ProgramRunner<?> runner = ProgramRunner.PROGRAM_RUNNER_EP.findFirstSafe(r -> matches(environment, r));
// Somehow modify the environment?
runner.execute(environment);
}
private boolean matches(@NotNull ExecutionEnvironment environment, @NotNull ProgramRunner<?> runner) {
String executorId = environment.getExecutor().getId();
return runner != this && runner.canRun(executorId, environment.getRunProfile());
}
} Execution target providerThe extension point ConclusionAs written in the first paragraph of this comment, it looks like there is no straightforward solution. From the options I have covered, the approach of EnvFile and ProjectEnv seems to be the most promising, but it might take a lot of effort. So I am still open for suggestions. |
I created a post on the community board of JetBrains. Let's see if someone responds. |
Yeah, you did the same research as me. The main problem is that the JVMs have no way of modifying the environment (at least not with a public API). Over a year ago I created a very similar suggestion to yours at https://youtrack.jetbrains.com/issue/IDEA-260725 but nothing happened, so I would not have high hopes... At least someone got assigned I guess 🤷 For reference: https://youtrack.jetbrains.com/issue/IDEA-288756 |
FYI Enter Nix Shell is not just abandoned, none of the links (source, issues, documentation) work anymore. Does anyone have a copy of the source code, so we could revive it? |
Interesting. It was still available in February. Unfortunately, I don't have a local copy of the repository. You can still download the binaries from JetBrains Marketplace (https://plugins.jetbrains.com/plugin/16864-enter-nix-shell) and use a decompiler. According to the page on the Marketplace, the plugin was available under MIT license. I guess I should invalidate the links in my messages since they seem to point to some NSFW-site now. |
Hmm it seems like runConfigurationExtension is not available in IDEA 2022.2? Can't really find a way to extend new env in the new API |
Note that you have to add |
I've had a bit of an internet historian moment, and found the website of the developer of this plugin saved on web archive. It might have some interesting information and it also has some videos showing the plugin. https://web.archive.org/web/20220131211828/https://fctorial.com/posts/nix_intellij.html |
Thank you for this! It does seem to break when changing the packages in the Nix shell, though, in a weird way: Notice how, in the above, |
I use Better Direnv and it seems to work: |
@starquake One problem with that approach is that IDEA gets very confused about which packages are installed. This also happens when using nix-direnv + Better Direnv. We need a solution which works with more than one project. |
Would it be possible to do something like
to put the whole ide in the new environment? Problems I see with this:
|
Here's a summary of the most significant things mentioned:
|
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
hey we patch the env of all the intellij IDEs, maybe this approach could help? |
Here's a workaround, after trying many things. tl;dr: Symlink the Tested only with IDEA and poetry2nix repos. Caveats:
|
@infiniteregrets: Could you elaborate on your approach, or even highlight where in the |
This might be a lot of work but it would be awesome if you could use
nix-shell
inside JetBrains products (e.g. activating shell.nix of your current project).I have a lot of friends who use
virtualenv
instead ofnix
just because PyCharm (the python IDE by JetBrains) have builtin support for it.What do you think about it?
The text was updated successfully, but these errors were encountered: