Nix构建waf生成文件而非目录导致无法调用及配置报错
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, theresultsymlink points directly to this single file instead of a directory with abin/subfolder. nix-envrelies on packages having abin/directory to add to yourPATH, so installing the rawwafpackage doesn't make the command available.- For
environment.systemPackages, NixOS usespkgs.buildEnvwhich expects every package to be a directory (not a single file), hence the build failure when you try to add the unmodifiedwafpackage.
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

