Search code examples
nixnixos

Prevent nix build from querying cache.nixos.org


when trying to build a derivation:

with import <nixpkgs> {};
stdenv.mkDerivation {
    name = "testdrive";
    version = "1.0.0";
    src = ./. ;
    phases = [
        "unpackPhase"  
        "buildPhase" 
        "installPhase"
    ];
    buildPhase = ''
        ${gcc}/bin/g++ a.cc -o a
    '';
    installPhase = ''
        mkdir -p $out/
        cp a $out/
    '';
}

nix always queries https://cache.nixos.org before the actual build. Since the dependencies was retrieved at first build, the subsequent query seems redundant and inefficient.

documentation around nix build command is a bit obscure. the behavior seems to relate to how nix handle the src.

how to disable the query?


Solution

  • nix build --option substitute false will do the trick.

    Note that the nix command is still in development as of writing.