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

Nix构建waf生成文件而非目录导致无法调用及配置报错

Fixing "waf: command not found" on NixOS

Let's break down what's going on here and walk through the fixes step by step:

Why This Happens

The waf package in nixpkgs is a bit of an odd one—it's packaged as just the standalone waf executable file itself, not following the standard Nix package structure that includes a bin/ directory for executables.

  • When you run nix-build -A waf, the result symlink points directly to this single file instead of a directory with a bin/ subfolder.
  • nix-env relies on packages having a bin/ directory to add to your PATH, so installing the raw waf package doesn't make the command available.
  • For environment.systemPackages, NixOS uses pkgs.buildEnv which expects every package to be a directory (not a single file), hence the build failure when you try to add the unmodified waf package.

Solutions

1. Temporary Usage (No Installation Required)

If you just need to run waf occasionally, you can skip installation entirely and use nix-shell to spawn a shell with waf preloaded:

nix-shell -p waf --run waf

Or directly call the executable from your nix-build result:

./result  # Run this after nix-build -A waf

2. Install to User Environment (nix-env)

To make waf permanently available in your user PATH, create a small wrapper derivation that places the waf executable into a standard bin/ directory.

Create a file named waf-wrapper.nix with this content:

with import <nixpkgs> {};
stdenv.mkDerivation {
  name = "waf-wrapper";
  buildInputs = [ waf ];
  phases = "installPhase";
  installPhase = ''
    mkdir -p $out/bin
    ln -s ${waf} $out/bin/waf
  '';
}

Then install it with:

nix-env -f ./waf-wrapper.nix -i

Now the waf command should be available in your shell.

3. Add to NixOS System Packages

To make waf available system-wide, add the wrapped package directly to your configuration.nix:

{ pkgs, ... }:
{
  environment.systemPackages = with pkgs; [
    # Your other system packages go here...
    (stdenv.mkDerivation {
      name = "waf-wrapper";
      buildInputs = [ waf ];
      phases = "installPhase";
      installPhase = ''
        mkdir -p $out/bin
        ln -s ${waf} $out/bin/waf
      '';
    })
  ];
}

Run sudo nixos-rebuild switch to apply the configuration—this time it should build successfully, and waf will be accessible to all users.

内容的提问来源于stack exchange,提问作者Jeffrey Benjamin Brown

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 11:27:51