Giter Site home page Giter Site logo

alexandre-lavoie / 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.62 MB

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

License: MIT License

TypeScript 97.57% Nix 2.43%

nix-env-selector's Introduction

Nix Environment Selector (๐Ÿงช Experimental Release)

This extension 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.nixShellConfig ${workspaceRoot}/default.nix Path of the Nix config file
nixEnvSelector.nixShellConfigAttr undefined Attribute path (nix-shell -A)

Supported Platforms

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

License

MIT

nix-env-selector's People

Contributors

arrterian avatar vitaliimelnychuk avatar jul1u5 avatar dependabot[bot] avatar dsturnbull avatar fruitiex avatar alexandre-lavoie 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.