Purpose of sourceRoot

The sample code on the Packaging/Binaries wiki page contains

stdenv.mkDerivation rec {
  src = fetchurl { ... };
  sourceRoot = ".";

while the nixpkgs manual states

  • srcs / src

    The list of source files or directories to be unpacked or copied. One of these must be set. Note that if you use srcs, you should also set sourceRoot or setSourceRoot.

  • sourceRoot

    After running unpackPhase, the generic builder changes the current directory to the directory created by unpacking the sources. If there are multiple source directories, you should set sourceRoot to the name of the intended directory. Set sourceRoot = “.”; if you use srcs and control the unpack phase yourself.

Is the setting of sourceRoot in the sample code superfluous, or does it serve some useful purpose?

In the example it is very likely, that the unpack Phase does not create a folder, and therefore the sourceRoot has to be set.

1 Like