Nix 安装
使用 Nix 包管理器安装 ClawdBot
概述
Nix 是一个强大的包管理器,提供可重现的构建和声明式配置。 使用 Nix 安装 ClawdBot 可以确保环境一致性,轻松管理依赖,并支持回滚。
可重现
任何机器上得到相同结果
声明式
配置即代码,版本控制
原子更新
安全升级,支持回滚
前提条件
- Linux 或 macOS 操作系统
- 管理员/sudo 权限(安装 Nix 时需要)
- 至少 5 GB 可用磁盘空间
安装 Nix
如果你还没有安装 Nix,请先安装:
单用户安装(推荐 macOS)
sh <(curl -L https://nixos.org/nix/install)多用户安装(推荐 Linux)
sh <(curl -L https://nixos.org/nix/install) --daemon验证安装
# 重新加载 shell 或重新登录后
nix --version启用 Flakes(推荐)
# ~/.config/nix/nix.conf 或 /etc/nix/nix.conf
experimental-features = nix-command flakes安装 ClawdBot
方法 1: 使用 nix profile
# 安装 ClawdBot
nix profile install github:clawdbot/clawdbot
# 验证安装
clawdbot --version方法 2: 使用 nix-env(传统方式)
# 添加 ClawdBot channel
nix-channel --add https://github.com/clawdbot/nixpkgs clawdbot
nix-channel --update
# 安装
nix-env -iA clawdbot.clawdbot方法 3: 临时使用
# 不安装,直接运行
nix run github:clawdbot/clawdbot -- --version
# 进入包含 ClawdBot 的 shell
nix shell github:clawdbot/clawdbot更新 ClawdBot
# 使用 nix profile
nix profile upgrade clawdbot
# 使用 nix-env
nix-env -u clawdbotNixOS 配置
如果你使用 NixOS,可以在系统配置中声明式地安装 ClawdBot:
系统级安装
# /etc/nixos/configuration.nix
{ config, pkgs, ... }:
{
# 添加 ClawdBot overlay
nixpkgs.overlays = [
(import (builtins.fetchTarball {
url = "https://github.com/clawdbot/nixpkgs/archive/main.tar.gz";
}))
];
# 安装 ClawdBot
environment.systemPackages = with pkgs; [
clawdbot
];
}用户级安装(Home Manager)
# ~/.config/home-manager/home.nix
{ config, pkgs, ... }:
{
home.packages = with pkgs; [
clawdbot
];
# 可选:配置 ClawdBot
home.file.".clawdbot/config.yaml".text = ''
provider: anthropic
model: claude-3-5-sonnet-20241022
'';
}ClawdBot 服务
# 配置为 systemd 服务
{ config, pkgs, ... }:
{
systemd.user.services.clawdbot-gateway = {
description = "ClawdBot Gateway";
wantedBy = [ "default.target" ];
serviceConfig = {
ExecStart = "${pkgs.clawdbot}/bin/clawdbot gateway";
Restart = "always";
};
environment = {
ANTHROPIC_API_KEY = "your-api-key";
};
};
}Flakes 方式
使用 Nix Flakes 获得更好的可重现性:
在项目中使用
# flake.nix
{
description = "My project with ClawdBot";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
clawdbot.url = "github:clawdbot/clawdbot";
};
outputs = { self, nixpkgs, clawdbot }:
let
system = "x86_64-linux"; # 或 "aarch64-darwin" 等
pkgs = nixpkgs.legacyPackages.${system};
in {
devShells.${system}.default = pkgs.mkShell {
buildInputs = [
clawdbot.packages.${system}.default
];
};
};
}使用开发环境
# 进入开发环境
nix develop
# ClawdBot 可用
clawdbot --version锁定版本
# 更新 flake.lock
nix flake update
# 锁定特定版本
nix flake lock --update-input clawdbot故障排查
Nix 未找到
# 重新加载 shell 配置
source ~/.bashrc # 或 ~/.zshrc
# 或重新登录构建失败
# 清理缓存重试
nix-collect-garbage -d
nix profile install github:clawdbot/clawdbot --refresh权限问题
# 确保 Nix daemon 运行(多用户安装)
sudo systemctl status nix-daemon
sudo systemctl start nix-daemonmacOS 特定问题
# 如果遇到 /nix 只读问题
# 需要创建 synthetic.conf
echo 'nix' | sudo tee -a /etc/synthetic.conf
# 然后重启获取更多帮助
# 运行诊断
clawdbot doctor --verbose
# 查看 Nix 构建日志
nix log github:clawdbot/clawdbot