A `nix` and `nix-shell` wrapper for shells other than `bash`

Related tags

Command-line nix nixos
Overview

nix-your-shell

nixpkgs Crates.io

A nix and nix-shell wrapper for shells other than bash.

nix develop and nix-shell use bash as the default shell, so nix-your-shell prints shell snippets you can source to use the shell you prefer inside of Nix shells.

Usage

nix-your-shell will print out shell environment code you can source to activate nix-your-shell.

Then, nix-shell, nix develop, and nix shell will use your shell instead of bash, unless overridden with a --command argument.

Fish

Add to your ~/.config/fish/config.fish:

if command -q nix-your-shell
  nix-your-shell fish | source
end

Zsh

Add to your ~/.zshrc:

if command -v nix-your-shell > /dev/null; then
  nix-your-shell zsh | source /dev/stdin
fi

Installation

You can either install nix-your-shell from this repository or from nixpkgs. The version packaged in nixpkgs will probably lag behind this repository by about a week or so.

nix profile

To install the latest version with nix profile, use one of:

nix profile install github:MercuryTechnologies/nix-your-shell
nix profile install "nixpkgs#nix-your-shell"

nix-env

To install the latest version with nix-env, use one of:

nix-env --install --file https://github.com/MercuryTechnologies/nix-your-shell/archive/refs/heads/main.tar.gz
nix-env --install nix-your-shell

You can later remove the installed program with nix-env --uninstall nix-your-shell.

nix run

Run dynamically with nix run:

nix run github:MercuryTechnologies/nix-your-shell -- zsh
nix run "nixpkgs#nix-your-shell" -- zsh

Note that because the generated shell code will refer to the dynamically-built nix-your-shell executable, it may get garbage collected and cause problems later.

Flakes

nix-your-shell is packaged in nixpkgs, so you can add pkgs.nix-your-shell to environment.systemPackages if you don't need the bleeding edge releases from this repo.

Add to a NixOS flake configuration using the overlay:

flake.nix:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    nix-your-shell = {
      url = "github:MercuryTechnologies/nix-your-shell";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = {
    self,
    nixpkgs,
    ...
  } @ attrs: {
    nixosConfigurations = {
      YOUR_HOSTNAME = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        specialArgs = attrs;
        modules = [./YOUR_HOSTNAME.nix];
      };
    };
  };
}

./YOUR_HOSTNAME.nix:

{
  config,
  pkgs,
  nix-your-shell,
  ...
}: {
  nixpkgs.overlays = [
    nix-your-shell.overlay
  ];

  environment.systemPackages = [
    pkgs.nix-your-shell
  ];

  # Example configuration for `fish`:
  programs.fish = {
    enable = true;
    promptInit = ''
      nix-your-shell fish | source
    '';
  };

  # ... extra configuration
}

Comparison with any-nix-shell

any-nix-shell does roughly the same thing, and serves as the inspiration for nix-your-shell.

There are a few reasons I wrote nix-your-shell as a competitor:

  • any-nix-shell doesn't support Nix flakes through nix develop. nix-your-shell does.
  • any-nix-shell is a hodgepodge of shell scripts with multiple layers of eval and templating, making hacking or modifying it challenging. In contrast, nix-your-shell is written in Rust with a relatively straightforward structure (the shell environment code generation command and the nix wrappers are the same, so there's no need for dotfile executables on your $PATH).

However, any-nix-shell can optionally display the packages in the current shell on a righthand prompt. nix-your-shell does not support this.

Comments
  • [DUX-1066] Fix `--command` with `nix develop`

    [DUX-1066] Fix `--command` with `nix develop`

    The Nix CLI is inconsistent with the --command flag...

    We would transform (e.g.) nix develop -L .#ghc942 into nix develop --command fish -L .#ghc942, which Nix interprets as running the command fish -L .#ghc942 in the shell. This patch puts the --command fish bit at the end, instead of at the front, so the -L .#ghc942 arguments are correctly passed to nix develop.

    Future work: actually writing some tests lol

    patch 
    opened by 9999years 2
  • Broken pipe when running with nix run

    Broken pipe when running with nix run

    I get the following error log:

    $ RUST_BACKTRACE=1 nix run github:MercuryTechnologies/nix-your-shell -- zsh | source
    source: not enough arguments
    The application panicked (crashed).
    Message:  failed printing to stdout: Broken pipe (os error 32)
    Location: library/std/src/io/stdio.rs:1009
    
      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                    ⋮ 7 frames hidden ⋮
       8: std::io::stdio::_print::h8161ac4f19406cdf
          at <unknown source file>:<unknown line>
       9: nix_your_shell::main::h1ef7ab779e977552
          at <unknown source file>:<unknown line>
      10: std::sys_common::backtrace::__rust_begin_short_backtrace::h50a6c336720655bd
          at <unknown source file>:<unknown line>
      11: std::rt::lang_start::{{closure}}::h4580b04423cddd21
          at <unknown source file>:<unknown line>
      12: std::rt::lang_start_internal::h398023bd7970a80b
          at <unknown source file>:<unknown line>
      13: main<unknown>
          at <unknown source file>:<unknown line>
      14: __libc_start_call_main<unknown>
          at <unknown source file>:<unknown line>
      15: __libc_start_main_alias_1<unknown>
          at <unknown source file>:<unknown line>
      16: _start<unknown>
          at <unknown source file>:<unknown line>
    
    Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
    Run with RUST_BACKTRACE=full to include source snippets.
    

    This also happens with fish.

    opened by IGI-111 2
  • Add `--` to `nix-your-shell` invocations

    Add `--` to `nix-your-shell` invocations

    This fixes extra arguments. Before, you'd see this if you tried to use any arguments with nix-shell or nix develop:

    $ nix develop --command whatever
    error: unexpected argument '--command' found
    
      note: to pass '--command' as a value, use '-- --command'
    
    Usage: nix-your-shell <SHELL> nix <ARGS>
    
    For more information, try '--help'.
    
    patch 
    opened by 9999years 1
  • Add nixpkgs badge

    Add nixpkgs badge

    It got picked up by repology so we can add this badge too now! Although curiously it hasn't actually landed on nixpkgs yet: https://nixpk.gs/pr-tracker.html?pr=215733

    opened by 9999years 0
  • Fix zsh

    Fix zsh

    1. zsh source requires a filename, so we use nix-your-shell zsh | source /dev/stdin instead.
    2. nix-your-shell zsh was printing the fish code instead of the zsh code due to a copy-pasting error (lol). Fix that.

    Also clean up the README a bit.

    Closes #4

    patch 
    opened by 9999years 0
  • Remove `cargo-dist`

    Remove `cargo-dist`

    cargo-dist is neat but can't yet produce universal macOS binaries; see https://github.com/axodotdev/cargo-dist/issues/77

    Remove it for now

    This will have to wait on getting the self-hosted runners added

    patch 
    opened by 9999years 0
  • Add CI

    Add CI

    The basic workflow is:

    • Label PRs with patch, minor, or major
    • When PRs are merged, version numbers are bumped automatically and a new PR is opened, labeled release
    • When a release PR is merged, a release is cut and built and published automatically
    major 
    opened by 9999years 0
  • Add `bash` support

    Add `bash` support

    This is a little weird, because bash is the default shell Nix uses. However, we're currently seeing a bug where nix develop will exit if any command being run exits with a nonzero exit code, but nix develop --command bash will not. Weird!

    EDIT: The bug was caused by sourcing scripts created with writeShellApplication instead of writeShellScriptBin in the Nix shell's shellHook, causing set -eu being sourced at the beginning of the shell. This in turn caused any failing command to exit the shell. I'm still going to merge this though because bash support won't hurt anyone.

    minor 
    opened by 9999years 1
Releases(v1.1.1)
Owner
Mercury
Mercury
Set Shell Environment Variables across multiple shells with a single configuration file.

Xshe – Cross-Shell Environment Vars xshe allows for setting Shell Environment Variables across multiple shells with a single TOML configuration file.

Ethan Kinnear 9 Dec 16, 2022
Scriptable tool to read and write UEFI variables from EFI shell. View, save, edit and restore hidden UEFI (BIOS) Setup settings faster than with the OEM menu forms.

UEFI Variable Tool (UVT) UEFI Variable Tool (UVT) is a command-line application that runs from the UEFI shell. It can be launched in seconds from any

null 4 Dec 11, 2023
Tricking shells into interactive mode when local PTY's are not available

Remote Pseudoterminals Remote Pseudoterminals or "RPTY" is a Rust library which intercepts calls to the Linux kernel's TTY/PTY-related libc functions

null 135 Dec 4, 2022
Demo Repo for BSides 2024 Live Training: "Blue Crab Shells: Getting Started with Offensive Rust Programming"

Blue Crab Shells: Getting Started with Offensive Rust Programming This repository contains example code for the live training provided for BSides San

The Taggart Institute 6 Apr 9, 2024
Downloads and provides debug symbols and source code for nix derivations to gdb and other debuginfod-capable debuggers as needed.

nixseparatedebuginfod Downloads and provides debug symbols and source code for nix derivations to gdb and other debuginfod-capable debuggers as needed

Guillaume Girol 16 Mar 6, 2023
A natural language shell interface for *nix systems

Orphic A natural language shell interface for *nix systems. Overview Orphic is a CLI tool that uses GPT to translate complex tasks into shell commands

Will Savage 42 Mar 29, 2023
Progress In Nix - Pacman inspired frontend for Nix

Progress In Nix Pinix is a Pacman inspired frontend for Nix. It wraps a regular Nix command and replaces the output with a more modern and informative

Rémi Dupré 23 Mar 9, 2024
Bashly - Bash CLI Framework and Generator

Bashly - Bash CLI Framework and Generator Create feature-rich bash scripts using simple YAML configuration

Danny Ben Shitrit 1.4k Jan 4, 2023
Use Git installed in Bash on Windows/Windows Subsystem for Linux (WSL) from Windows and Visual Studio Code (VSCode)

WSLGit This project provides a small executable that forwards all arguments to git running inside Bash on Windows/Windows Subsystem for Linux (WSL). T

A. R. S. 1.1k Jan 3, 2023
Nvm - Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Node Version Manager Table of Contents Intro About Installing and Updating Install & Update Script Additional Notes Troubleshooting on Linux Troublesh

nvm.sh 63.8k Jan 7, 2023
A handy way to handle sh/bash cli parameters

Argc A handy way to handle sh/bash cli parameters. How Argc works To write a command line program with Argc, we only need to do two things: Describe t

null 398 Jan 3, 2023
An enhanced history(1) for bash

history This is a replacement for the history builtin in bash. It has a couple of additional features that relative to the one included with bash: Con

Robert T. McGibbon 4 Aug 25, 2022
Check if the process is running inside Windows Subsystem for Linux (Bash on Windows)

is-wsl Check if the process is running inside Windows Subsystem for Linux (Bash on Windows) Inspired by sindresorhus/is-wsl and made for Rust lang. Ca

Sean Larkin 6 Jan 31, 2023
GPT-3 powered CLI tool to help you remember bash commands.

Rusty: GPT-3 Powered CLI Tool Convert natural language into executable commands directly from the terminal! Open source CLI tool powered by OpenAI (br

Zahid Khawaja 287 Apr 19, 2023
Simple joke randomizer from bash.org.pl made as CLI Tool in Rust.

RBashOrg Simple joke randomizer from bash.org.pl made as CLI Tool in Rust. Description Main motivation of this project was to learn basic concepts abo

Krzysztof Szostak 3 Feb 20, 2024
A localized open-source AI server that is better than ChatGPT.

??AI00 RWKV Server English | 中文 | 日本語 AI00 RWKV Server is an inference API server based on the RWKV model. It supports VULKAN inference acceleration a

顾真牛 142 Aug 23, 2023
More than safe rust abstractions over rytm-sys, an unofficial SDK for writing software for Analog Rytm running on firmware 1.70.

rytm-rs More than safe rust abstractions over rytm-sys, an unofficial SDK for writing software for Analog Rytm running on firmware 1.70. On top of CC

Ali Somay 5 Dec 22, 2023
Navigating around TUM with excellence – An API and website to search for rooms, buildings and other places

NavigaTUM NavigaTUM is a non-official tool developed by students for students, that aims to help you get around at TUM. Feel free to contribute. Featu

TUM Developers 21 Dec 22, 2022
Captures packets and streams them to other devices. Built for home network analysis and A&D CTFs.

?? shiny-donut shiny-donut is a packet capture app that supports streaming packets from a remote system to another device. The main use for this is to

Justin Perez 3 Nov 30, 2022