Skip to content

FreaxMATE/shells

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Shells Icon

🐚 Shells - Nix Flake Environment Switcher

Seamlessly switch your VS Code development environment to any Nix flake πŸš€

License: GPL v3 VS Code Nix


✨ What is Shells?

Shells is a VS Code extension that brings the power of Nix flakes directly into your editor! It detects flake.nix files in your workspace and activates them with a single click, making your entire VS Code instance behave as if it's running inside nix develop.

No more switching between terminals or remembering to activate environments manuallyβ€”just open your project and go! 🎯

🎁 Features

βœ… Smart Auto-Detection - Automatically finds flake.nix files in your workspace
βœ… Status Bar Integration - Shows current flake status at a glance
βœ… Multi-Flake Support - Easily switch between multiple flakes in one workspace
βœ… Full Workspace Integration - Everything uses your flake environment:

  • πŸ–₯️ All integrated terminals
  • πŸ”¨ Build tasks and commands
  • πŸ› Debuggers
  • πŸ” Language servers
  • 🎨 Formatters and linters

βœ… Optional Auto-Activation - Jump straight into your environment on workspace open
βœ… Zero Configuration - Works out of the box with sensible defaults

πŸ“‹ Requirements

Before using Shells, make sure you have:

  • πŸ”Ή Nix installed on your system
  • πŸ”Ή Nix flakes enabled in your configuration
πŸ”§ How to enable Nix flakes

Add to your ~/.config/nix/nix.conf or /etc/nix/nix.conf:

experimental-features = nix-command flakes

πŸš€ Usage

πŸ“ Commands

Access these commands via Command Palette (Ctrl+Shift+P / Cmd+Shift+P):

Command Description
🟒 Shells: Enter Nix Flake Environment Activates the detected or selected flake
πŸ”΄ Shells: Exit Nix Flake Environment Deactivates the flake environment
πŸ”„ Shells: Select Nix Flake Choose which flake to use (if multiple exist)
πŸ“Š Shells: Show Output Open the output channel to view detailed logs

πŸ“Š Status Bar

The extension adds a status bar item on the bottom left with visual indicators:

Icon Status Visual Style Action
βœ… Nix: <flake-name> Flake environment ACTIVE οΏ½ Highlighted with green background Click to change flakes
οΏ½πŸ“¦ Nix: <flake-name> Flake detected but not active Normal styling Click to activate
πŸ“¦ No Flake No flake.nix found Normal styling β€”

Tip: When the environment is active, the status bar item has a prominent colored background so you can easily see at a glance whether you're in a flake shell!

πŸ› Debugging & Output

The extension includes a comprehensive output channel for debugging:

  • πŸ“ View detailed logs of all nix develop operations
  • πŸ” See full command output including stdout and stderr
  • οΏ½ Track environment variable extraction with counts
  • ⏱️ Timestamped operations for troubleshooting
  • ❌ Detailed error messages when something goes wrong

Access the output:

  • Automatically shows when activating a flake
  • Click "Show Output" button in notifications
  • Run command: Shells: Show Output
  • Or open manually: View β†’ Output β†’ Select "Nix Flake Environment"

βš™οΈ Configuration

Customize the extension via VS Code settings:

Setting Type Default Description
shells.autoActivate boolean false Automatically activate flake environment on workspace open
shells.flakePath string "" Path to flake.nix (relative to workspace root). Empty = auto-detect

πŸ” How It Works

graph LR
    A[πŸ“‚ Open Workspace] --> B{πŸ”Ž flake.nix found?}
    B -->|Yes| C[πŸ“Š Show in Status Bar]
    B -->|No| D[πŸ’€ Idle]
    C --> E[πŸ‘† Click to Activate]
    E --> F[⚑ Run nix develop]
    F --> G[🌍 Extract Environment]
    G --> H[βš™οΈ Configure VS Code]
    H --> I[πŸŽ‰ Ready to Code!]
Loading

Step-by-step:

  1. πŸ” Extension searches for flake.nix files when you open a workspace
  2. πŸ“Š Displays flake status in the status bar
  3. πŸ‘† Click the status bar or run "Enter Nix Flake Environment" command
  4. ⚑ The extension runs nix develop and:
    • 🌍 Extracts all environment variables
    • πŸ–₯️ Configures integrated terminal environment
    • βš™οΈ Updates workspace settings for tools and language servers
  5. πŸŽ‰ All new terminals, tasks, debuggers, and LSPs use your flake environment!

Result: Your entire VS Code behaves as if it's running inside nix develop!

πŸ“š Example

Here's a simple flake.nix that the extension can detect:

{
  description = "πŸš€ My awesome development environment";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      devShells.${system}.default = pkgs.mkShell {
        buildInputs = with pkgs; [
          nodejs_20
          python3
          git
          # Add more packages here!
        ];
        
        shellHook = ''
          echo "πŸŽ‰ Welcome to your dev environment!"
        '';
      };
    };
}

With this flake, the extension automatically gives you access to:

  • βœ… Node.js 20
  • βœ… Python 3
  • βœ… Git
  • βœ… Any other packages you add!

πŸ› οΈ Development

Want to contribute or customize the extension? Here's how to get started:

Prerequisites

  • 🦊 Nix with flakes enabled
  • πŸ“¦ VS Code

Setup

# 1️⃣ Clone the repository
git clone https://github.com/FreaxMATE/shells.git
cd shells

# 2️⃣ Enter the development environment (using its own flake! 🎭)
nix develop

# 3️⃣ Install dependencies
npm install

# 4️⃣ Compile TypeScript
npm run compile

# 5️⃣ Watch mode (auto-recompile on changes)
npm run watch

Run & Debug

Press F5 in VS Code to launch the Extension Development Host and test your changes! πŸš€

πŸ“¦ Installation

Method 1: Package Locally

# 1️⃣ Enter dev environment
nix develop

# 2️⃣ Package the extension
npx @vscode/vsce package

# 3️⃣ Install the .vsix file
code --install-extension shells-0.0.1.vsix

πŸ’‘ NixOS Tip: Use npx instead of global npm installs for better compatibility!

Method 2: Install from VSIX (GUI)

  1. Open VS Code
  2. Navigate to Extensions view (Ctrl+Shift+X / Cmd+Shift+X)
  3. Click the ... menu at the top
  4. Select "Install from VSIX..."
  5. Choose the shells-0.0.1.vsix file

βœ… Verify Installation

  1. Open a workspace with a flake.nix file
  2. Look for the status bar item: πŸ“¦ Nix: <flake-name>
  3. Open Command Palette (Ctrl+Shift+P) and search for "Shells" commands

🀝 Contributing

Contributions are welcome and appreciated! πŸ’™

οΏ½ Python & Jupyter Notebooks

The extension fully supports Python development and Jupyter notebooks! When you activate a flake environment, the extension:

  1. πŸ” Detects the Python interpreter from your flake's PATH
  2. βš™οΈ Configures VS Code's Python extension to use the flake's Python
  3. πŸ““ Enables Jupyter notebooks with all packages from your flake

Example Jupyter-ready flake:

{
  description = "Python Data Science Environment";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
  };

  outputs = { self, nixpkgs, ... }:
  let
    system = "x86_64-linux";
    pkgs = import nixpkgs { inherit system; };
  in {
    devShells."${system}".default = pkgs.mkShell {
      packages = with pkgs; [
        python312Packages.python
        python312Packages.numpy
        python312Packages.matplotlib
        python312Packages.pandas
        python312Packages.scipy
        python312Packages.notebook
        python312Packages.jupyter
        python312Packages.pip
      ];
    };
  };
}

⚠️ Important: Reload Required

After activating a flake environment for the first time, you must reload VS Code for the Python and Jupyter extensions to pick up the new interpreter. The extension will prompt you to do this automatically.

Click "Reload Window" when prompted, or manually run: Developer: Reload Window from the Command Palette.

πŸ’‘ Why Reload?

VS Code's Python and Jupyter extensions cache the interpreter path and environment. A reload ensures they discover and use the Python from your Nix flake environment.

οΏ½πŸ“„ License

This project is licensed under the GPL-3.0-or-later License.

See LICENSE for details.


Made with ❀️ and Nix

⭐ Star this repo if you find it useful!

About

VS Code extension for automatic Nix flake environment detection and activation

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published