You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NixOS中不使用nix-shell/nix-env安装file、ripgrep的常用方法

在NixOS中安装file、ripgrep的替代方法

以下是几种符合你要求的常用安装方式:

1. 用Home Manager的home.packages安装

Home Manager的programs模块仅针对带有专属配置项的软件(比如编辑器、窗口管理器这类需要额外配置的),像file、ripgrep这类无特殊配置需求的工具,直接添加到home.packages即可。

修改你的home.nix配置文件:

{ config, pkgs, ... }:
{
  home.packages = with pkgs; [
    file
    ripgrep
  ];
  # 保留你原有的其他Home Manager配置
}

执行命令生效:

home-manager switch

2. 系统级安装(需管理员权限)

如果你拥有系统配置权限,可以将工具添加到系统全局的软件包列表,所有用户都能使用。

修改/etc/nixos/configuration.nix:

{ config, pkgs, ... }:
{
  environment.systemPackages = with pkgs; [
    file
    ripgrep
  ];
  # 保留其他系统配置项
}

执行命令应用配置:

sudo nixos-rebuild switch

3. 手动构建并添加到PATH

如果上述方法都无法使用,可手动从Nixpkgs构建软件包,再将二进制文件路径加入用户的PATH:

# 构建ripgrep,输出到当前目录的result文件夹
nix-build '<nixpkgs>' -A ripgrep
# 构建file工具
nix-build '<nixpkgs>' -A file

然后将构建生成的result/bin目录添加到你的shell配置文件(比如~/.bashrc或~/.zshrc):

export PATH="$HOME/result/bin:$PATH"

注意:每次构建会覆盖当前的result链接,若需同时保留多个工具,可指定不同的输出目录,比如nix-build '<nixpkgs>' -A ripgrep -o ripgrep-result。

内容的提问来源于stack exchange,提问作者zoey1771

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 02:26:19