Giter VIP home page Giter VIP logo

nix-env-selector's Introduction

πŸ‡ΊπŸ‡¦ Support Ukraine πŸ‡ΊπŸ‡¦

Hi folks, My name is Roman Valihura. I'm the author of this extension. I'm Ukrainian. I was born in Ukraine. I'm living here at the moment.

As you all know Russia invaded my country. Russia has already killed thousands of civilians and continues the war and terror in Ukraine. I have the luck that my region is pretty far from the frontline. But even here, I'm living in the air-alarm reality. The reality where you should wake up in the middle of the night and go into the shelter. Because a rocket flies over your region.

Like a lot of Ukrainians now I became a volunteer in this hard time for my country. We with a team producing Individual First Aid Kits for the Ukrainian army. If you have a wish and ability to support the activity, you can make a donation on our website, which we made to collect funds for producing First Aid Kits.

More datails on the aidkit.shop

Thank you for your attention!

Nix Environment Selector

nix-env-selector-logo

Extension that lets you use environments declared in .nix files in Visual Studio Code.

Motivation

Nix package manager provides a way of creating isolated environments with a specific configuration of packages. These environments are usually activated in the terminal and are not convenient to use within an IDE.

One option is to run nix-shell on the command line and then launch code within the activated shell. However, this process can quickly become tedious. Nix Environment Selector provides an alternative: can automatically apply the environment.

Getting started

  • Install Nix package manager.
  • Restart VS Code (to make sure that nix-shell is in the PATH)
  • Install the extension.
  • Create the Nix environment config (like default.nix or shell.nix) in the root of your project's workspace.
  • Open Command Palette (Ctrl + Shift + P) and run Nix-Env: Select Environment command.
  • Choose the Nix environment you'd like to apply.
  • Wait for the environment to build.
  • Restart VS Code to apply the built environment.

Example

Haskell project

To run a Haskell application you need to have GHC (Haskell compiler) installed. With Nix package manager we can create an isolated environment containing only the GHC version and the dependencies that the project needs without polluting the user's environment.

Environment configuration in shell.nix:

{ pkgs ? import <nixpkgs> { } }:
with pkgs;

let
  haskellDeps = ps: with ps; [
    base
    lens
    mtl
    random
  ];
  haskellEnv = haskell.packages.ghc865.ghcWithPackages haskellDeps;
in mkShell {
  buildInputs = [
    haskellEnv
    haskellPackages.cabal-install
    gdb
  ];
}

Now let's try to open our project in Visual Studio Code.

Without Env Demo

As you can see VS Code can't find the GHC compiler. Let's apply the environment declared in shell.nix.

With Env Demo

Bingo πŸŽ‰πŸŽ‰πŸŽ‰. Everything is working now 😈

Configuration

You can configure the extension in .vscode/settings.json file (located in the root of the workspace). Here are the configuration settings:

Setting Default Description
nixEnvSelector.nixFile null Path to the Nix config file
nixEnvSelector.packages [] List packages using as -p nix-shell args
nixEnvSelector.args null Custom args string for nix-shell. EX: -A <something> --pure
nixEnvSelector.nixShellPath null Custom path for nix-shell executable

Supported Platforms

  • MacOS
  • Linux
  • Windows (with Remote - WSL extension)

Support

If you like the extension and want to support author, click the button bellow.

donate

License

MIT

nix-env-selector's People

Contributors

arrterian avatar daneads avatar dependabot[bot] avatar dsturnbull avatar fruitiex avatar hagl avatar jul1u5 avatar nh2 avatar samuela avatar shayne avatar vitaliimelnychuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nix-env-selector's Issues

nix-env-selector does not work with flakes

Describe the bug
This bug manifests with similar symptoms as in #56... specifically stuck in the "Applying environment..." state, but AFAICT has a different root cause and I am therefore opening a separate issue.

When selecting a flake.nix from the nix-env-selector drop-down, the error

[Extension Host] Error: Command failed: nix-shell "/home/skainswo/dev/sshenanigans/flake.nix" --run export
error: nix-shell requires a single derivation
Try 'nix-shell --help' for more information.

    at ChildProcess.exithandler (node:child_process:420:12)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1091:16)
    at Socket.<anonymous> (node:internal/child_process:449:11)
    at Socket.emit (node:events:513:28)
    at Pipe.<anonymous> (node:net:322:12)

is shown in the developer console, and the tray icon stays in the "Applying environment..." spinner forever.

To Reproduce
Steps to reproduce the behavior:

  1. Go to a project with a flake. For example, I am currently attempting to use nix-env-selector with https://github.com/samuela/sshenanigans.
  2. Run Nix-Env: Select environment... and select flake.nix from the drop down.
  3. Observe the error and infinity spinner......

Expected behavior
The environment equivalent to nix develop to be applied.

Screenshots
n/a

Environment:

  • OS: macOS 14.1.1, running over SSH on a NixOS 23.05
  • VS Code: Version: 1.85.1 (Universal), Commit: 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
  • Version: v1.0.10

Additional context
n/a

Handle multiple folders in the workspace

I spent ages with this extension not working because I had multiple folders defined in the workspace eg

myproj.workspace
{
	"folders": [
		{
			"path": "foo"
		},
		{
			"path": "bar"
		},
		{
			"path": "."
		},
}

shell.nix was present in ".". The extension silently didn't find it.

I suggest either

  • warning in the log (or the readme even) that there were multiple workspace folders and only the first is checked OR
  • enumerate files in each configured folder when building the list of possible environments.

Now it's working, all my intellisense has started working again (I reordered my folders), which is brilliant. Thank you!

Extension unable to find nix-shell

Describe the bug
I can't get the extension to work. It just gives me this error notification:

Command failed: nix-shell /Users/derrickbeining/Dev/ihp-app/default.nix --run env /bin/sh: nix-shell: command not found

If I go into ~/.vscode/extension/arrterian-nix-env-selector-0.1.2/out/helpers.js and replace nix-shell with the absolute path to the binary and restart vscode, then the extension works properly.

Perhaps this is just a problem with my environment, but perhaps if nix-env-selector exposed configuration to be able to specify the path to nix-shell, then that could fix my issue.

To Reproduce
Steps to reproduce the behavior:

  1. Fresh install of nix/nix-shell
  2. Fresh install of plugin
  3. Open project with default.nix expression
  4. Open command panel in VS Code and run "Nix-Env: select environment" command
  5. See error notification

Expected behavior
I expect the extension to be able to find and run nix-shell on my PATH

Environment:

  • OS: MacOS Catalina 10.15.6
  • shell: zsh
  • VS Code:
Version: 1.51.1
Commit: e5a624b788d92b8d34d1392e4c4d9789406efe8f
Date: 2020-11-11T01:11:34.018Z (1 mo ago)
Electron: 9.3.3
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 19.6.0```

 - Plugin Version: 0.1.2

[HELP]: Share your .nix usage propose

Hi guys πŸ‘‹
I have a plan to create a docs site for the extension.
In one of the chapters, I would write about how to use the extension and nix for creating a development environment for different languages and platforms.

Could you guys share with me your nix configs for different cases that using in your real projects?
It'll be good to have examples for Haskell, Rust, Go, Java, etc.

Have the extension output logs in the Output window

Hi!

I had a problem with my nix environment file, but I couldn’t find any error log in VS Code itself. AFAIK your extension doesn’t log anything anywhere at the moment. There exists an output window that extensions can use to send their log to. This would be useful to get feedback if something went wrong.

How to reproduce the behavior:
Open a folder on VS Code with a env.nix file containing:

{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/tags/21.05.tar.gz") {} }:

pkgs.mkShell {
    buildInputs = [
        pkgs.npm
    ];
}

Open the command palette and use Nix-Env: select environment to select env.nix. The extension will hang on forever while trying to apply the environment.

Using nix-shell env.nix in a terminal instead logs this error:
error: attribute 'npm' missing, at folder/env.nix:5:9
and terminate its process.

I’m kinda busy at the moment, but I can make a pull request if I find some free time if you would like. Thanks for your time!

Empty string value for attr results in Command failed: `nix-shell -A --run env error: ... `

Describe the bug
Having edited the value and removing it (setting it to empty string) the extension tries to spawn nix-shell with -A argument but no (empty string) value which fails. The only workaround is to set the value to '' which is quite ugly/non-intuitive.

To Reproduce
Steps to reproduce the behavior:

  1. Fresh install of plugin
  2. Go to plugin settings
  3. Set "Nix Shell Config Attr" to some value
  4. Save settings
  5. Clear "Nix Shell Config Attr" setting
  6. Restart vscode
  7. Command failed: nix-shell -A --run env error: ...

Expected behavior
After restart the attr should be interpreted as empty string and plain nix-shell should be used.

Screenshots
image

Environment:

  • OS: Fedora 33
  • Version 0.1.2

Rustup packages as settings packages

Describe the bug

This is a corner case, but I'm improvising here not seeing right solution anywhere else. VSCode's Rust Extension requires presence of rustup. I've added "nixEnvSelector.packages": ["rustup"] to .vcode/settings.json, but VSCode Extension do not see rustup after restart. All happens with WSL and remote session.

To Reproduce

Steps to reproduce the behavior:

  1. Add "nixEnvSelector.packages": ["rustup"] to .vscode/settings.json
  2. Set environment to shell.nix
  3. Open source file in Rust
  4. VSCode still complaints it doesn't see rustup.

Expected behavior

Extension notices rustup and installs rls or rust-analyzer depending on settings.

Screenshots

image

Environment:

  • OS: Windows 10 19042.964 & Ubuntu 18.04 in WSL2
  • VS Code 1.55.2
  • Version 1.0.7

Additional context

Under normal circumstances my development environment would be just deb packages installed from Ubuntu repository or manual installation of rustup. However, in conditions I'm working on at the moment Nix is used for all development environment and I'm trying to figure out best way to use VSCode with this.

Running nix-shell -p rustup and then code . on WSL2 terminal session work - VSCode sees the rustup.

Add unit tests for actions, helpers, and status bar

Need write unit tests for the following modules:

  • Actions | src/actions.ts
    Actions are all side effects that can be performed by the extension
  • Status bar | status-bar.ts
    Simple wrap for default VSCode status bar API
  • Helpers | src/helpers.ts
    Simple stateless and reusable functions

Feel free to add testing dependencies to package.json if you need it.

We should remove existed test runner for integration tests and init mocha or jest instead.

[Feature]: Command for reloading current environment

Is your feature request related to a problem? Please describe.
When I try to set up my nix environment for some project, I often need to reload the environment. The current workflow seems too cumbersome to me.

Right now, the fastest way to reload the environment is the following:

  1. Ctrl+Shift+P (Go to the command palette)
  2. Choose Nix-Env: Select environment
  3. Choose shell.nix (or some other file)

Note: the Select environment command always preselects Original user environment which isn't very useful. Perhaps we could put the current environment at the top of the environment list?

  1. Wait for the environment to prepare
  2. Click Reload

Describe the solution you'd like
I would like to have a command which reloads the current environment. I guess it would be enough to wrap the first three steps in this command. After the environment prepares, the user could then press the Reload button or use Developer: Reload Window command.

Additional context
It would also be great to have a keyboard shortcut for this command.

shell.nix exetubables don't seem to be made available after selecting shell.nix

I'd like to be able to use the Dhall LSP Server extension with dependencies made available via a shell.nix file.

To Reproduce
I created a shell.nix file with the contents:

{ pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
    # nativeBuildInputs is usually what you want -- tools you need to run
    nativeBuildInputs = [ pkgs.dhall-lsp-server ];
}

However, after selecting the Nix environment and reloading VS Code, I still get this error:

No `dhall-lsp-server` executable is available in the VSCode PATH.
You might need to install [Dhall LSP server](https://github.com/PanAeon/dhall-lsp-server).
Also you might want to set an absolute path to the `dhall-lsp-server` executable in the plugin settings.

In the vs code terminal, I can confirm the dhall-lsp-server executable is available after running nix-shell shell.nix.

Expected behavior
I would expect VS Code to be able to find the dhall-lsp-server executable.

Environment:

  • OS:
    Linux beb82dell0 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
    $ lsb_release -a
    No LSB modules are available.
    Distributor ID:	Ubuntu
    Description:	Ubuntu 20.04.3 LTS
    Release:	20.04
    Codename:	focal
    
  • VS Code
    Version: 1.54.3
    Commit: 2b9aebd5354a3629c3aba0a5f5df49f43d6689f8
    Date: 2021-03-15T10:55:24.277Z
    Electron: 11.3.0
    Chrome: 87.0.4280.141
    Node.js: 12.18.3
    V8: 8.7.220.31-electron.0
    OS: Linux x64 5.4.0-90-generic
    

[Feature]: Environment Auto-Switch

It would be great to (optionally) support automatically switching to an environment when a project containing a shell.nix file is opened.

Alternatively, some users might like to get a notification window saying something like "A shell.nix file was found: would you like to activate the nix environment?".

Python extension does not pickup Nix environment

Describe the bug
The official Python extension does not pickup the environment provided by the shell.nix.

e.g. my nix-shell has black formatter and flake8 in buildInputs, which I can call from the command line after nix-shell, but VS Code still tells me that black and flake8 are not installed.

To Reproduce
Steps to reproduce the behavior:

  1. Create poetry project, e.g. nix-shell -p poetry then poetry init && poetry add -D black
  2. Create shell.nix
let
  pkgs = import <nixpkgs> {};
  python-env = pkgs.poetry2nix.mkPoetryEnv {
    projectDir = ./.;
  };
in
  pkgs.mkShell {
    buildInputs = [
      python-env
    ];
  }
  1. Start VS Code with Python extension, select shell.nix and reload.
  2. Try to format some Python code using black (in VS Code Shift+Alt+F, after setting "python.formatting.provider": "black" in settings)

Expected behavior
VS Code should pickup black from my nix shell

Environment:

  • OS: NixOS 20.03
  • VS Code:
    Version: 1.51.0-insider
    Commit: fce8fc82cacf0b4e2a18c633b6c6f3058702a5c9
    
  • Version: v0.1.2

Additional context
Add any other context about the problem here.

[Feature]: VSCodium support

Is your feature request related to a problem? Please describe.
At the moment it doesn't look like this plugin works with codium. It looks like the plugin watnt's to save settings to .vscode, instead of the codium path?

Describe the solution you'd like
Support VSCodium

Describe alternatives you've considered
I'm just using nix-shel, then opening codium from there. Might look into the nix direnv support too.

[BUG] Extension don't add package to PATH variable, when some active tabs need any package from shell.nix

Weird situation. First time run extension, I selected my configured shell.nix file, extension loaded packages, everything works. Second time, extension didn't load my packages and LSP throws exception, because package didn't add to PATH. But when I close every tabs, that use any package from shell.nix, extension will load packages, add to PATH and everything back to normal.

I found this bug for GoLang project. You can generate simple golang project and add to your shell.nix LSP for golang.

Can't make my fhs env work

I have a nix shell like this

{pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv
{
    name = "clang-env";
    targetPkgs = pkgs: (with pkgs; [
        vim
        python3
        python3Packages.six
        clang
        lldb
        zlib openssl.dev binutils which
        git
        source-code-pro
#        cantarell-fonts
#        dejavu_fonts
    ]);
    runScript = "bash";
}).env

but I had no success to make it run in vscode
my settings.json

...
"nixEnvSelector.nixFile": "${workspaceRoot}/fhs.nix"
...

[Feature]: passing arguments to nix-shell

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

[Feature]: VSCode-Remote (SSH) support?

Is your feature request related to a problem? Please describe.
When working remotely over VScode Remote (SSH β€” a Linux box β€” not WSL), this extension doesn't appear to have any effect. The pop-up that a Nix environment has been detected works; but clicking the "Select" button does … nothing; the window doesn't reload, the environment doesn't appear affected.

Describe the solution you'd like
I'd like to be able to use VSCode-OCaml-Platform etc with Nix environments that are on remote vscode-ssh servers! (=

[Feature]: Support shell.nix files outside of the project directory

Is your feature request related to a problem? Please describe.
I frequently find myself working in a monorepo setup. It's often the case that I have a shell.nix file in the root of the project and then separate subdirectories for different pieces. Whenever I open up one of those subdirectories in vscode, I have no way of activating the root shell.nix.

Describe the solution you'd like
Some mechanism to activate shell.nix files outside of the current project directory. Being able to simply input ../shell.nix in the "Select environment config" prompt would be huge.

Describe alternatives you've considered
symlinking the parent shell.nix file into subdirectories. splintering the shell.nix into many separate files.

Additional context
n/a

Brittle environment parsing

Describe the bug
A multi-line environment variable where some lines happen to include assignments mess up the environment created by nix-env-selector.

I'm not sure if this is a bug in nix-env-selector or the dotenv dependency, but anyway I figured it'd be good to document this behaviour somewhere.

Basically, this preConfigure snippet breaks the nixpkgs compiler inside nix-env-selector:

  preConfigure = ''
    echo "custom preConfigure running..."
    NIX_CFLAGS_COMPILE=$(some_filter_over_old_NIX_CFLAGS_COMPILE_due_to_reasons)
  '';

It seems like the second line of the preConfigure variable get treated as a separate variable assignment, thus the compiler gets run in an environment where NIX_CFLAGS_COMPILE literally is $(some shell code) and completely breaks.

To Reproduce

  1. Have a C/C++ code base built with cmake.
  2. Open vscode and install extensions: nix-env-selector 0.1.2, cmake-tools 1.4.1, cpptools 1.0.0.
  3. Have a default.nix file with e.g.
preConfigure = ''
  echo "custom preConfigure running..."
  NIX_CFLAGS_COMPILE=$(some_filter_over_old_NIX_CFLAGS_COMPILE_due_to_reasons)
'';
  1. Activate the environment.
  2. The the cmake step will fail due to the nixpkgs gcc compiler wrapper receiving unexpanded/wrong NIX_CFLAGS_COMPILE.

Expected behavior
Variables inside other variables (like in preConfigure above) should not be picked up as separate variables.

Environment:

  • OS: Ubuntu 18.04
  • VS Code 1.48.2
  • nix-env-selector version: 0.1.2

Additional context

  • I worked around the problem by adding export in front of the NIX_CFLAGS_COMPILE variable. That seems to prevent the bug.
  • I realize now that setting the NIX_CFLAGS_COMPILE variable in preConfigure does not mean it will get set by nix-shell, so now I'm also setting it with shellHook.
  • Thanks for making this extension! (I couldn't get vscode remote ssh to work without it.)

[Feature]: Display shell load logs

Is your feature request related to a problem? Please describe.
When I select my shell.nix file as Nix env, the build can be long/hang/stop in error.

Describe the solution you'd like
I would like to be able to monitor the nix-shell evaluation done by the extension.
For instance in the "Output" view of VS Code.

Describe alternatives you've considered
I can use nix-shell in the command line, but whenever I forget to do that I have to go in a terminal and reevaluate, which can take again a lot of time.

Command 'Nix-Env: Select environment' resulted in an error (command 'extension.selectEnv' not found)

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. install extension
  2. Cmd + Shift + P) and type Select environment
  3. See error
    Command 'Nix-Env: Select environment' resulted in an error (command 'extension.selectEnv' not found)

Expected behavior
show .nix files in from the folder

Screenshots
If applicable, add screenshots to help explain your problem.

Environment:
nix-shell -p nix-info --run "nix-info -m"

 - system: `"x86_64-linux"`
 - host os: `Linux 5.7.10, NixOS, 20.03.2652.076c67fdea6 (Markhor)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.4pre20200622_334e26b`
 - channels(ae): `"home-manager-20.03, home-manager-unstable, nixos-20.03.2652.076c67fdea6, nixpkgs-20.03.2652.076c67fdea6, unstableNix-20.09pre235652.7d557a5d1b3, unstableOS-20.09pre235279.5717d9d2f7c"`
 - nixpkgs: `/home/user/.nix-defexpr/channels/nixpkgs`

Additional context

[Feature]: numtide/devshell integration

A tight integration with numtide/devshell (which seems to grow soonish out of alpha) would be very helpful.

  • Specifically, this request includes: interpreting a bare devshell.toml proxying through the devshell cli

  • Motivation: Remove that friction to devshell for vscode users

/cc @zimbatm (fyi)

[Feature]: Remember nix environment answer

Is your feature request related to a problem? Please describe.
Every time I switch to a direnv-enabled workspace, I get this message:

image

Describe the solution you'd like
The extension should ask only the 1st time a workspace is opened, and remember the answer for next times.

Describe alternatives you've considered
Sometimes I just ignore it. It seems to work anyway. But I'm not sure if it has any side effects.

Additional context
My .envrc files usually contain just use nix or use flake.

Extension Development Host does not launch

For context, I (too) was about to implement #59 and opened the extension itself in VSCode. When you press F5/run the extension, the Extension Development Host window never opens.

To Reproduce
Steps to reproduce the behavior:

  1. Open the extension in VS Code
  2. Press F5 and/or click "Run Extension"

Expected behavior
A second VSCode window (with title prefixed by [Extension Development Host]) opens. (See https://code.visualstudio.com/api/get-started/your-first-extension)

Environment:

  • OS: Manjaro 22.0.0
  • VS Code 1.74.2
  • Version main

Additional context
The cause is using watch in the pre-launch task here: https://github.com/arrterian/nix-env-selector/blob/master/.vscode/launch.json#L19 Removing the pre-launch task and running watch in a terminal gets you as far as being able to simply restart the extension after you make a change. I'm not sure if it should be possible to "reload" in the extension development host window.

(It's also worth noting that if you run the extension in an empty window, it fails because the workspace dir is null. I assume that's known/intentional, though I did fix it. Let me know if you want a PR for that.)

Open VSX

Hi, have you considered putting it on Open VSX as well as the official marketplace? VSCodium and other FOSS editors based on VSCode use Open VSX because the official marketplace has some licensing issues with third-party applications.

[Feature]: Support specifying path to nix-shell

Is your feature request related to a problem? Please describe.
I am using vscode's devcontainers feature to use nixos. VSCode's process doesn't use the PATH variable from the container so when this extension attempts to invoke nix-shell, it cannot find it. This extension is pretty awesome, this is the only issue I have with it.

Describe the solution you'd like
Add a setting to allow specifying the path to nix-shell.

Describe alternatives you've considered
I modified the helpers.js file in the devcontainer to use the absolute path of nix-shell and it worked. I'd rather not continue editing the extension every time I use it.

Additional context
..

[Feature]: Allow to specify packages without nix file

Is your feature request related to a problem? Please describe.
Right now the quickest way of making VSCode aware of some packages you need to create a shell.nix file.
This creates some friction when you want to check out some projects without creating new files.

Describe the solution you'd like
I propose a new command that would function similarly to nix-shell -p.
The command would ask for the name of the package and then load it into the environment. Ideally, the command could display a list of packages from nixpkgs and filter it out as you type the name of the package.

I am not sure what could be the best way to add multiple packages:

  • Execute the command multiple times
  • Run the command only once and specify multiple packages separated by space. It might be difficult to implement auto-completion for every package, although I don't know how VSCode API for extension commands looks like.

Describe alternatives you've considered
An alternative is to use nix-shell -p in the terminal and then start VSCode from the same nix-shell.

Additional context
I think the specified packages could be saved in an array in .vscode/settings.json.
Also, thanks for the extensions. It works really well.

Stuck applying environment

Describe the bug
When i select my environment it just says applying environment forever

To Reproduce
Steps to reproduce the behavior:
1.Select envirnment
2.Select shell.nix
3.Wait forever??
Expected behavior
It loads the environment.

Environment:

  • OS: [nixos 20.09]
  • VS Code
  • Version 1.0.2

Additional context
My nix shell:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  buildInputs = [
    pkgs.hello

    # keep this line if you use bash
    pkgs.bashInteractive
  ];
}

[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

TypeError when applying nix environment in Remote SSH

Describe the bug
I am using this extension from VS Code on my macbook, and using the Remote SSH extension to open a workspace on a remote Ubuntu server. The wokspace has nix flakes set up. When I try to select a nix environment using this extension, the message "Applying environment" appears forever, but in the "Extension Host (Remote)" output pane I see the error:

2023-06-27 07:25:22.142 [error] TypeError: c.call is not a function
	at /home/sid/.vscode-server/extensions/arrterian.nix-env-selector-1.0.9/dist/main.js:2538:310

To Reproduce
Steps to reproduce the behavior:

  1. Open a remote workspace.
  2. Use the "Nix-Env: Select environment" command to select flake.nix
  3. Open the Outputs pane and go to "Extension Host (Remote)"
  4. See error

Expected behavior
I expect the nix environment to be activated so that I can use HLS for my project.

Environment:

  • OS: macOS 13.4.1
  • VS Code: 1.79.2

"command 'nixEnvSelector.selectEnv' not found"

Describe the bug
Just tried to run the "Select Environment" command from the command palette, but got an odd error.

To Reproduce
Steps to reproduce the behavior:

  1. Open the command palette with Cmd-Shift-P.
  2. Select the "Select Environment" command.
  3. Wait a few seconds, then observe the error modal.

Expected behavior
The command to not throw an error.

Screenshots
Screen Shot 2022-02-04 at 5 26 17 PM

Environment:

  • OS: macOS, running VSCode over SSH connected to a NixOS machine.
  • VS Code [e.g. chrome, safari]Β 
  • Version 1.64.0
Version: 1.64.0 (Universal)
Commit: 5554b12acf27056905806867f251c859323ff7e9
Date: 2022-02-03T04:20:17.224Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Darwin arm64 21.2.0

Additional context
n/a

[Feature]: Add Ouput log

Is your feature request related to a problem? Please describe.
When switching to an environment that might have problems building, the "Applying environment..." status bar spinner can go forever without the ability to look at an output log to troubleshoot the problem.

Describe the solution you'd like
Other extensions use the Output tab in the Panel to log their output (for instance the Haskell extension uses it to display Haskell Language Server launch info).

Describe alternatives you've considered
Maybe a log file setting?

Automatically switch Python path when reloading env

Describe the bug
I had the same issue as #14, because I was working with a Nix env described by a shell.nix file. I modified this file, adding black and flake8 to the Python env, and selected this env again through the plugin.
However the Python bin was still on the previous shell.nix configuration, not the new one in my Nix store.

Expected behavior
Reloading Nix env should update the Python path for the Python plugin to the right binary.

[Feature]: Support multiple folders in workspace

Is your feature request related to a problem? Please describe.
Currently, *.nix files are only found in workspace root. If there are two folders in workspace, no *.nix files are found.

Describe the solution you'd like
I'd like to find any *.nix file in top-level folders

Describe alternatives you've considered
Recursively searching all folders may be useful in some cases, but just searching the root for each folder in workspace is sufficient for my needs.

Additional context
Awesome extension, thanks so much πŸ˜„

C/C++ Support: Can this be used to help generate the c_cpp_properties.json configuration file?

Is your feature request related to a problem? Please describe.

The c_cpp_properties.json configuration file is necessary for intellisense to work for C/C++ files.

For example right now I have to manually configure it like:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/nix/store/zl4bvsqfxyx5vn9bbhnrmbmpfvzqj4gd-nodejs-16.14.2/include/**"
            ],
            "defines": [],
            "compilerPath": "/nix/store/58pwclg9yr437h0pfgrnbd0jis8fqasd-gcc-wrapper-11.2.0/bin/gcc",
            "cStandard": "c99",
            "cppStandard": "c++17",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

In particular both the compilerPath and includePath I had to add in manually.

My shell.nix brings in $NIX_CFLAGS_COMPILE and $NIX_LDFLAGS which shows us all the include paths we need.

Describe the solution you'd like

It would be nice if nix-env-selector could acquire this information, or allow us to configure it to acquire this information from the relevant nix environment, then provide us a way to reference these "variables" from the shell environment for other VScode extensions such as the C/C++ extension. That would be most flexible way.

I could imagine doing something like:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "${nixEnv:...}"
            ],
            "defines": [],
            "compilerPath": "${nixEnv:NIX_CC}",
            "cStandard": "c99",
            "cppStandard": "c++17",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

I'm not familiar with how vscode extensions work, and how to apply these variables to vscode dynamically, but it would greatly simplify the usage of nix-shell related environment configuration with other extensions and other languages.

Unable to switch due to spaces in path name

Describe the bug
I am using a path that includes spaces in the name. I am unable to switch environments because of it. The error message is as follows:

Command failed: nix-shell /mnt/Disk E/.../shell.nix --run env error: getting status of '/mnt/Disk': No such file or directory

(I've replaced the full path with ...).

To Reproduce

  1. Create a folder with spaces in the name and a *.nix.
  2. Switch to the *.nix environment.

Expected behavior
I expect to be able to switch environment.

Environment:
This should affect any OS that allows spaces in the path.

Additional context
Open #42 as a possible fix to the issue.

Terminal running in environment

I've got this working, but when I want to build manually I still need to write "nix-shell" in the terminal by hand, it seems. Could this not be done automatically by the extension?

Stuck applying environment

Describe the bug
Symptoms are equal to #49: after selecting the environment, the status remains "Applying environment..." forever.

To Reproduce
Steps to reproduce the behavior:

  1. Install nix-env-selector 1.0.7
  2. Apply environment:
    { pkgs ? import ./haskell.nix
    , hsPkgs ? import ./default.nix {} }:
    
    let
      terraform = pkgs.terraform_0_14.withPlugins(p: [ p.aws ]);
    in hsPkgs.shellFor {
      # Include only the *local* packages of your project.
      packages = ps: with ps;
        [ shiba ];
    
      # Builds a Hoogle documentation index of all dependencies,
      # and provides a "hoogle" command to search the index.
      withHoogle = true;
    
      # You might want some extra tools in the shell (optional).
    
      # Some common tools can be added with the `tools` argument
      tools = { cabal = "3.2.0.0"; hlint = "2.2.11"; stylish-haskell = "0.12.2.0"; };
      # See overlays/tools.nix for more details
    
      # Some you may need to get some other way.
      buildInputs = with hsPkgs.haskellPackages;
        [ terraform pkgs.awscli ];
    
      # Prevents cabal from choosing alternate plans, so that
      # *all* dependencies are provided by Nix.
      exactDeps = true;
    }
    It's a fairly standard haskell.nix setup. Let me know if you need to see the rest of my nix files as well! I have the same problem with my work machine, with a similar haskell.nix setup.

Expected behavior
I'd expect this plugin to do as advertised and load my nix environment.

Environment:

  • OS: Fedora 34 / Mac OS Big Sur
  • VS Code 1.55.2
  • Version 1.0.7

No longer applies shell.nix to integrated terminal?

Describe the bug
I'm not sure if this is caused by the VSCode update that came out recently, but I noticed that the shell.nix file no longer seems to be being applied to the integrated terminal. I noticed it after updating to the most recent version but it could also be unrelated to that.

To Reproduce
Steps to reproduce the behavior:

  1. Open a project in VSCode containing a shell.nix file
  2. Load the environment using this Extension
  3. Open the integrated terminal in VSCode
  4. Try to use one of the executable files specified in shell.nix
  5. Note that the executables are not found
  6. Run nix-shell ./shell.nix
  7. Note that the executables are now available in the terminal

Expected behavior
The integrated terminal should load with the executables (and libraries) provided in shell.nix.

Screenshots
N/A

Environment:

  • OS: NixOS 22.11
  • VS Code
  • VSCode: 1.73.1 / Extension: 1.0.9

Additional context
N/A

python linter not found

First of all many thanks for this plugin!

I'm using a shell.nix with a python environment. While the python interpreter is correctly detected, additional tools don't handle the nix shell environment properly.

One example is autopep8. While I have installed (through shell.nix), I get this popup:
Formatter autopep8 is not installed. Install?

I also see problems like:

Unable to import 'requests' (pylint import-error)

... although python requests is installed through shell.nix.

To Reproduce
Steps to reproduce the behavior:

  1. Install nix-env-selector and python extension in VS Code
  2. create shell.nix and set the env to it, e.g. something like:
with import <nixpkgs> {};

(python38.withPackages (ps: [ ps.requests ps.pylint  ps.autopep8 ])).env
  1. Create a python file, something like this should be enough:
import requests

i=0
  1. See errors (warning about autopep8 and requests missing)

Expected behavior
Additional tools like linters should use shell.nix env as well

Environment:

  • OS: MacOS 10.14.6
  • VS Code 1.40.2

[Feature]: Support multiroot workspace

Is your feature request related to a problem? Please describe.

I have a workspace with multiple roots. Some are node projects, some are C++ projects with CMake and I use nix to manage all the environments.

The nix-env-selector don't seem to support this. I cannot select which nix file I'm loading for which directory, and some tools don't seem to work. I must run all my tools in the integrated terminal instead of using extension commands

Describe the solution you'd like

Being able to select a nix file for each projects.

Describe alternatives you've considered

Running all tools in the integrated terminal. For some things like python debugging it seem to work since the venv point to the nix python.

Also running everything in different windows seem to work.

Can find packages from nix-shell, but not with nix-env-selector

When I run nix-shell and then code ., intellisense can find all of my packages. However, opening VS Code (not from the nix-shell) using nix-env-selector, intellisense does not find the packages. I've uninstalled, reinstalled, and repeated selection of the environment.

Environment:

  • OS: Ubuntu 22.04.2
  • VS Code
  • Version 1.77.0

Latest Pylance update brakes python environment

Describe the bug
After the latest Pylance upgrade to 2023.9.20 Python environment is not correctly recognized. All imports of 3-party packages are marked as Import "xxx" could not be resolved, on the previous version of Pylance 2023.9.10 everything works fine. So temporary solution is to downgrade Pylance.

nix-env-selector version: 1.0.10

Environment:

  • OS: ubuntu 22.04
  • VS Code: 1.82.2

[Feature]: Support conda / buildFHSUserEnv

Is your feature request related to a problem? Please describe.
Occasionally, I need to use conda on my NixOS box. Normally, I'd use nix-shell to enter a buildFHSUserEnv, then run VSCode. This workflow isn't possible with remote-ssh, however, and this is where nix-env-selector is fantastic.

nix-env-selector uses nix-shell --run and this is unfortunately unsupported for buildFHSUserEnv. <- also has a workaround however.

Describe the solution you'd like
I'd like to be able to use buildFHSUserEnv with nix-env-selector. A hacky solution would be to grep for "buildFHSUserEnv" in the *.nix file, and if found, to instead pass --argstr run XXX. Then, in the FHS, I could write `runScript = "bash --rcfile <(echo '. ~/.bashrc; conda activate caiman; ${run}')";

Describe alternatives you've considered
For shebang scripts, I use the workaround linked above: create an executable called conda for my conda.nix buildFHSUserEnv:

#!/usr/bin/env bash
set -euo pipefail
fhs="/Computer/shell/conda.nix"
function run {
  nix-shell --pure --argstr run "$*" "${fhs}"
}
if [[ $# -eq 0 ]]; then
  run bash
else
  run "conda $@"
fi

Then, in a python script I do (-S is for passing multiple arguments)

#!/usr/bin/env -S conda run -n caiman python
import caiman
print("hello world")

Unfortunately, I haven't succeeded in hooking in my conda wrapper with VScode's python interpreter selector.

[Feature] Pick up nix environment in tasks

Describe the bug

I attempted a minimalist example to run the hello program provided by nix from a task and the task is not found after loading / hitting the environment. I'm probably doing something wrong here, but if I load the nix environment before opening vscode from the same terminal things work. Thanks in advance.

To Reproduce
Steps to reproduce the behavior:

# file: default.nix
{ pkgs ? import <nixpkgs> {}}:

pkgs.mkShell {
  nativeBuildInputs = [ pkgs.hello ];
}
// file: .vscode/tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "hello",
            "type": "shell",
            "command": "hello"
        }
    ]
}
  1. Start vs code
  2. Open the project folder
  3. Select the environment
  4. Reload the environment
  5. Click on Terminal menu
  6. Click on Run Task ... option
  7. Select hello
  8. Select continue without scanning task output

The output in the terminal shows that it can't find hello

> Executing task: hello <

zsh:1: command not found: hello
The terminal process "/bin/zsh '-c', 'hello'" failed to launch (exit code: 127).

Terminal will be reused by tasks, press any key to close it.

Expected behavior

The following is the expected output, but I can only get it if vscode is started from a terminal with the nix environment loaded already. Which is precisely what I am looking to not do with this extension.

> Executing task: hello <

Hello, world!

Terminal will be reused by tasks, press any key to close it.

Environment:

  • OS: macOS 10.15.7 Catalina
  • Version: 1.54.3 (Universal)
  • Commit: 2b9aebd5354a3629c3aba0a5f5df49f43d6689f8
  • Electron: 11.3.0
  • Chrome: 87.0.4280.141
  • Node.js: 12.18.3
  • V8: 8.7.220.31-electron.0
  • OS: Darwin x64 19.6.0

[Feature]: direnv support

Is your feature request related to a problem? Please describe
I see this plugin is clearly made with nix in mind. Yet, currently I'm using direnv in combination with this . plugin. Sadly that one seems unmaintained having received no update for the last three (!) years and has . accumulated some issues ragarding api incompatibilities.

I was hoping now that you implement a similar thing, adding support for another environment provider i.e. direnv might be worthwhile to think about.

In addition this would allow for higher flexibility harnessing an existing tool for the job. Maybe this could also solve #17?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.