GithubHelp home page GithubHelp logo

dsturnbull / nix-env-selector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arrterian/nix-env-selector

0.0 2.0 0.0 5.45 MB

Allows switch environment for Visual Studio Code and extensions based on Nix config file.

License: MIT License

TypeScript 97.46% Nix 2.54%

nix-env-selector's Introduction

Nix Environment Selector (๐Ÿงช Experimental Release)

The extension allows you switch environment for Visual Studio Code and extensions based on .nix config files.

Motivation

Nix package manager provides a convenient solution for creating isolated environments with a specific configuration of packages. This way is working from the command line as well, but not prepared for using with IDE. For example, if you have a language server extension requires a compiler installed inside an isolated environment there is no simple way to link 'em with each other. The solution allows you to manage the environment for projects based on Visual Studio Code workspace.

Getting started

  • First of all, you should install Nix package manager.
  • Restart VSCode to be sure path to run nix-shell configured properly
  • Install the extension
  • Create nix env config, like default.nix in your project workspace root.
  • Open commands pallet (Cmd + Shift + P) and type Select environment
  • From the list of nix virtual environments choose the one you'd like to apply

Haskell Project running example

To run your Haskell application you have to install GHC compiler. To avoid global GHC instalation and be able to use different compiler versions in your host let's do this by using nix virtual environment

Example of GHC compiler inside the NIX store(shell.nix):

{ nixpkgs ? import <nixpkgs> {} }:
let
  inherit (nixpkgs) pkgs;
  inherit (pkgs) haskellPackages;

  haskellDeps = ps: with ps; [
    base
    lens
    mtl
    random
  ];

  ghc = pkgs.haskell.packages.ghc864.ghcWithPackages haskellDeps;

  nixPackages = [
    ghc
    pkgs.gdb
    haskellPackages.cabal-install
  ];
in
pkgs.stdenv.mkDerivation {
  name = "snadbox-haskell-workspace";
  buildInputs = nixPackages;
}

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

Without Env Demo

You can see, IDE can't find a compiler. Let's turn on shell.nix env.

With Env Demo

Bingo ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰. Everything is fine now ๐Ÿ˜ˆ

Manual Configuration

All plugin configuration located in .vscode/settings.json. You are able to configure for your needs by changing following props in your settings.json

nixEnvSelector.nixShellConfig: path where your nix config is located. Default: ${workspaceRoot}/default.nix

Supported Platforms

  • MacOS

The extension Should work on the Linux platform as well, but not tested yet. Feel free to create an issue if you found a problem.

License

MIT

nix-env-selector's People

Contributors

arrterian avatar vitaliimelnychuk avatar

Watchers

James Cloos avatar  avatar

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.