15 个稳定版本
| 1.4.5 | 2024年3月25日 |
|---|---|
| 1.4.4 | 2024年3月21日 |
| 1.4.1 | 2023年12月19日 |
| 1.4.0 | 2023年11月20日 |
| 1.1.1 | 2023年2月21日 |
#62 在 命令行工具 中排名
674 每月下载量
32KB
558 行
nix-your-shell
为非 bash 的shell提供 nix 和 nix-shell 的包装器。
nix develop 和 nix-shell 使用 bash 作为默认shell,因此 nix-your-shell 会打印出可以源码导入的shell代码片段,以便在Nix shell中使用您喜欢的shell。
用法
nix-your-shell 将打印出您可以使用来激活 nix-your-shell 的shell环境代码。例如
$ nix-your-shell fish
# If you see this output, you probably forgot to pipe it into `source`:
# nix-your-shell fish | source
function nix-shell --description "Start an interactive shell based on a Nix expression"
nix-your-shell fish nix-shell -- $argv
end
function nix --description "Reproducible and declarative configuration management"
nix-your-shell fish nix -- $argv
end
这些命令将替换为 nix foo bar,变为 nix-your-shell fish nix foo bar。然后,nix-your-shell 会解析 nix 参数,并在启动底层命令之前添加一个 --command fish 参数。
然后,nix-shell,nix develop 和 nix shell 将使用您的shell而不是bash,除非显式地用 --command 参数覆盖。
Fish
添加到您的 ~/.config/fish/config.fish
if command -q nix-your-shell
nix-your-shell fish | source
end
Zsh
添加到您的 ~/.zshrc
if command -v nix-your-shell > /dev/null; then
nix-your-shell zsh | source /dev/stdin
fi
Xonsh
添加到您的 ~/.config/xonsh/rc.xsh
if !(which nix-your-shell):
nix-your-shell xonsh | source
Nushell
[!IMPORTANT] 需要 Nushell 版本 >=0.87.0
[!NOTE] Nushell 需要在启动
nu之前存在源码配置文件。
添加到您的 ~/.config/nushell/config.nu
source nix-your-shell.nu
要生成 nix-your-shell.nu 文件
手动生成它
nix-your-shell nu | save $env.XDG_CONFIG_HOME/nushell/nix-your-shell.nu
或确保它与 nix-your-shell 一起保持更新,通过使用 home-manager 填充文件
{ config, pkgs, ... }: {
home.file."${config.xdg.configHome}/nushell/nix-your-shell.nu".source = pkgs.nix-your-shell.generate-config "nu";
}
安装
您可以从本仓库或从 nixpkgs 中安装 nix-your-shell。在 nixpkgs 中打包的版本可能比本仓库晚一周左右。
nix profile
要使用 nix profile 安装最新版本,请使用以下之一
nix profile install github:MercuryTechnologies/nix-your-shell
nix profile install "nixpkgs#nix-your-shell"
nix-env
要使用 nix-env 安装最新版本,请使用以下之一
nix-env --install --file https://github.com/MercuryTechnologies/nix-your-shell/archive/refs/heads/main.tar.gz
nix-env --install nix-your-shell
之后,您可以使用以下命令删除已安装的程序:nix-env --uninstall nix-your-shell。
nix run
使用 nix run 动态运行
nix run github:MercuryTechnologies/nix-your-shell -- zsh
nix run "nixpkgs#nix-your-shell" -- zsh
注意,由于生成的 shell 代码会引用动态构建的 nix-your-shell 可执行文件,它可能会被 垃圾回收,并在以后引起问题。
Flakes
nix-your-shell 已打包在 nixpkgs 中,因此如果您不需要此仓库的尖端版本,可以将 pkgs.nix-your-shell 添加到 environment.systemPackages。
使用 overlay 将其添加到 NixOS flake 配置中
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.overlays.default
];
environment.systemPackages = [
pkgs.nix-your-shell
];
# Example configuration for `fish`:
programs.fish = {
enable = true;
promptInit = ''
nix-your-shell fish | source
'';
};
# ... extra configuration
}
添加对新 shell 的支持
请参阅 #23,了解如何向 nix-your-shell 添加对新 shell 的支持。
与 any-nix-shell 的比较
any-nix-shell 做的事情大致相同,并成为 nix-your-shell 的灵感来源。
以下是我编写 nix-your-shell 作为竞争对手的几个原因
any-nix-shell不支持通过nix develop使用 Nix flakes。而nix-your-shell支持。any-nix-shell是由多个层级的eval和模板拼凑而成的混合体,这使得对其进行破解或修改具有挑战性。相比之下,nix-your-shell使用 Rust 编写,具有相对简单的结构(shell 环境代码生成命令和nix包装器相同,因此不需要在您的$PATH中设置 dotfile 可执行文件)。
但是,any-nix-shell 可选地可以在右侧提示符中显示当前 shell 中的包。而 nix-your-shell 不支持此功能。
依赖关系
~13–24MB
~344K SLoC