Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mercurytechnologies/nix-your-shell
A `nix` and `nix-shell` wrapper for shells other than `bash`
https://github.com/mercurytechnologies/nix-your-shell
nix nixos
Last synced: about 20 hours ago
JSON representation
A `nix` and `nix-shell` wrapper for shells other than `bash`
- Host: GitHub
- URL: https://github.com/mercurytechnologies/nix-your-shell
- Owner: MercuryTechnologies
- License: mit
- Created: 2023-02-09T22:45:07.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-24T17:23:10.000Z (4 months ago)
- Last Synced: 2025-01-28T21:06:54.189Z (6 days ago)
- Topics: nix, nixos
- Language: Rust
- Homepage:
- Size: 140 KB
- Stars: 142
- Watchers: 11
- Forks: 12
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# nix-your-shell
[![nixpkgs](https://repology.org/badge/version-for-repo/nix_unstable/nix-your-shell.svg?header=nixpkgs)](https://repology.org/project/nix-your-shell/versions)
[![Crates.io](https://img.shields.io/crates/v/nix-your-shell)](https://crates.io/crates/nix-your-shell)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`. For example:```ShellSession
$ nix-your-shell fish
# If you see this output, you probably forgot to pipe it into `source`:
# nix-your-shell fish | sourcefunction nix-shell --description "Start an interactive shell based on a Nix expression"
nix-your-shell fish nix-shell -- $argv
endfunction nix --description "Reproducible and declarative configuration management"
nix-your-shell fish nix -- $argv
end
```These replace commands like `nix foo bar` with `nix-your-shell fish nix foo
bar`. `nix-your-shell` then parses the `nix` arguments and adds a `--command
fish` argument before launching the underlying command.Then, `nix-shell`, `nix develop`, and `nix shell` will use your shell instead
of bash, unless overridden explicitly with a `--command` argument.### Fish
Add to your `~/.config/fish/config.fish`:
```fish
if command -q nix-your-shell
nix-your-shell fish | source
end
```### Zsh
Add to your `~/.zshrc`:
```zsh
if command -v nix-your-shell > /dev/null; then
nix-your-shell zsh | source /dev/stdin
fi
```### Xonsh
Add to your `~/.config/xonsh/rc.xsh`
```xonsh
if !(which nix-your-shell):
nix-your-shell xonsh | source
```### Nushell
> [!IMPORTANT]
> Nushell version >=0.87.0 is required> [!NOTE]
> Nushell requires sourced configuration files to exist before `nu` is started.Add to your `~/.config/nushell/config.nu`:
```nu
source nix-your-shell.nu
```To generate the `nix-your-shell.nu` file:
Either manually generate it:
```nu
nix-your-shell nu | save $env.XDG_CONFIG_HOME/nushell/nix-your-shell.nu
```Or ensure it's kept updated alongside `nix-your-shell` by populating the file with [`home-manager`][home-manager]:
[home-manager]: https://nix-community.github.io/home-manager/
```nix
{ config, pkgs, ... }: {
home.file."${config.xdg.configHome}/nushell/nix-your-shell.nu".source = pkgs.nix-your-shell.generate-config "nu";
}
```## 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:
```sh
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:
```sh
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`:
```sh
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][nix-collect-garbage] and cause problems later.[nix-collect-garbage]: https://nixos.org/manual/nix/stable/package-management/garbage-collection.html
### 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`:
```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`:
```nix
{
config,
pkgs,
nix-your-shell,
...
}: {
nixpkgs.overlays = [
nix-your-shell.overlays.default
];environment.systemPackages = [
pkgs.nix-your-shell
];# Example configuration for `fish`:
programs.fish = {
enable = true;
interactiveShellInit = ''
nix-your-shell fish | source
'';
};# ... extra configuration
}
```## Adding support for new shells
See [#23](https://github.com/MercuryTechnologies/nix-your-shell/pull/23) for an
example of adding support for a new shell to `nix-your-shell`.## Comparison with `any-nix-shell`
[`any-nix-shell`](https://github.com/haslersn/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.