All Projects → chisui → Zsh Nix Shell

chisui / Zsh Nix Shell

Licence: bsd-3-clause
zsh plugin that lets you use zsh in nix-shell shells.

Programming Languages

shell
77523 projects

Labels

Projects that are alternatives of or similar to Zsh Nix Shell

Shabka
Shabka. Declaritive description of my network, workstations and servers.
Stars: ✭ 138 (+6.15%)
Mutual labels:  zsh, nix
Dotfiles
Configuration files for XMonad, Emacs, NixOS, Taffybar and more.
Stars: ✭ 127 (-2.31%)
Mutual labels:  zsh, nix
Dotfiles
~ 🍭 ~
Stars: ✭ 147 (+13.08%)
Mutual labels:  zsh, nix
Dotfiles
Zsh, Karabiner, VS Code, Sublime, Neovim, Nix
Stars: ✭ 634 (+387.69%)
Mutual labels:  zsh, nix
Dotfiles
My small loan of configuration files and scripts - based on NixOS
Stars: ✭ 124 (-4.62%)
Mutual labels:  nix
Polyglot
Color, ASCII-only Git prompt for zsh, bash, ksh93, mksh, pdksh, dash, and busybox ash
Stars: ✭ 118 (-9.23%)
Mutual labels:  zsh
Hie Nix
Nix packages for Haskell IDE Engine
Stars: ✭ 118 (-9.23%)
Mutual labels:  nix
Jovial
jovial - a jovial theme for zsh
Stars: ✭ 124 (-4.62%)
Mutual labels:  zsh
Pure
Pretty, minimal and fast ZSH prompt
Stars: ✭ 10,891 (+8277.69%)
Mutual labels:  zsh
Crate2nix
nix build file generator for rust crates
Stars: ✭ 123 (-5.38%)
Mutual labels:  nix
Antibody
The fastest shell plugin manager.
Stars: ✭ 1,659 (+1176.15%)
Mutual labels:  zsh
Nixgl
A wrapper tool for nix OpenGL application
Stars: ✭ 120 (-7.69%)
Mutual labels:  nix
Micro Ci
A tiny CI server built around GitHub and Nix
Stars: ✭ 126 (-3.08%)
Mutual labels:  nix
Xxh
🚀 Bring your favorite shell wherever you go through the ssh.
Stars: ✭ 2,559 (+1868.46%)
Mutual labels:  zsh
Up
Quickly navigate to a parent directory via tab-completion.
Stars: ✭ 126 (-3.08%)
Mutual labels:  zsh
Dotfiles
Dotfiles
Stars: ✭ 117 (-10%)
Mutual labels:  zsh
Dotfiles
My dotfiles
Stars: ✭ 127 (-2.31%)
Mutual labels:  zsh
Alien Minimal
An asynchronous minimal zsh prompt
Stars: ✭ 122 (-6.15%)
Mutual labels:  zsh
Wasm Cross
Nix expressions for cross compiling to WebAssembly
Stars: ✭ 122 (-6.15%)
Mutual labels:  nix
Zulu
Total environment manager for ZSH
Stars: ✭ 129 (-0.77%)
Mutual labels:  zsh

zsh in nix-shell

This oh-my-zsh plugin lets you use zsh as the default shell in a nix-shell environment. It's recommended to use this in conjunction with nix-zsh-completions.

Motivation

In theory all you need to do to use zsh in nix-shell is to set NIX_BUILD_SHELL to zsh. Unfortunatly nix assumes that the NIX_BUILD_SHELL is a bash variant and passes bash specific arguments to the shell. To fix this we need a shim that translates these arguments.

The information that nix-shell exposes to the environment is also pretty sparse. It would be nice to know what derivations are included in the current environment for example to display them in the shells prompt.

Installation

Oh-My-ZSH

Clone this repository into your plugins directory

git clone https://github.com/chisui/zsh-nix-shell.git $ZSH_CUSTOM/plugins/nix-shell

Then add nix-shell to the plugins list in ~/.zshrc.

NixOS

If you have installed zsh using nix the plugins directory is readonly since it's inside of the nix store. To get around this you can override the ZSH_CUSTOM directory. Simply create a writable directory inside of your home directory (eg. $HOME/.config/oh-my-zsh) and set ZSH_CUSTOM to that path inside of your .zshrc file.

ZSH_CUSTOM=$HOME/.config/oh-my-zsh

After that simply install for oh-my-zsh as normal.

Plain ZSH

Clone this repository and add the following to your ~/.zshrc.

source /path/to/zsh-nix-shell/nix-shell.plugin.zsh

home-manager

Add this repository to the plugins list of your configurations:

{
  programs.zsh = {
    enable = true;
    enableCompletion = true;
    plugins = [
      {
        name = "zsh-nix-shell";
        file = "nix-shell.plugin.zsh";
        src = pkgs.fetchFromGitHub {
          owner = "chisui";
          repo = "zsh-nix-shell";
          rev = "v0.1.0";
          sha256 = "0snhch9hfy83d4amkyxx33izvkhbwmindy0zjjk28hih1a9l2jmx";
        };
      }
    ];
  };
}

Plugin managers

It should be possible to install this plugin through most zsh plugin managers. If the one of your choice is not supported feel free to open an issue or even better create a pull request.

MacOS

On MacOS you have to have a bash with version 4 or greater. See Issue 14

Usage

Use nix-shell as you did before.

Commands run with --run or --command argument are executed in nix-shells default shell. In the case of --command you are put into a zsh shell afterwords.

--pure

If you use the --pure flag the interactive shell will be the default shell.

Environment info

If you are inside a nix-shell environment IN_NIX_SHELL will be set. The value will be impure or pure if you specified --pure.

The packages argument is passed through as NIX_SHELL_PACKAGES to the shell.

If this Variable is empty nix-shell was called for a specific nix expression which is stored in the name environment variable.

These variables can now be used inside a theme to customize the prompt. Take a look at this variant of the agnoster theme for an example of how this might look.

example prompt

example prompt for projects

Limitations

Shell hooks

Shell hooks are supported in general. Since they are executed inside of bash before the zsh shell is spawned they aren't executed in the same environment. This means that things like aliases wont work.

Zsh dotfiles

The normal zsh dotfiles are sourced after the nix-shell is opened. This means that you have to take into account that these files may override variables set by nix-shell.

Contributing

Please do. Pull requests welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].