summary refs log tree commit diff
diff options
context:
space:
mode:
authorJan Malakhovski <oxij@oxij.org>2023-07-25 13:29:56 +0000
committerJan Malakhovski <oxij@oxij.org>2023-08-03 16:32:05 +0000
commitccbb065c88080966e14872ea9e0ac577f753d902 (patch)
tree747a7209cc08a0aaccc87a3d3f48dee5354d7500
parentd8f7f6a5cee067b81bfaaa3aa079adb94ed7c01e (diff)
downloadnixpkgs-ccbb065c88080966e14872ea9e0ac577f753d902.tar
nixpkgs-ccbb065c88080966e14872ea9e0ac577f753d902.tar.gz
nixpkgs-ccbb065c88080966e14872ea9e0ac577f753d902.tar.bz2
nixpkgs-ccbb065c88080966e14872ea9e0ac577f753d902.tar.lz
nixpkgs-ccbb065c88080966e14872ea9e0ac577f753d902.tar.xz
nixpkgs-ccbb065c88080966e14872ea9e0ac577f753d902.tar.zst
nixpkgs-ccbb065c88080966e14872ea9e0ac577f753d902.zip
doc: make `sourceRoot` and `setSourceRoot` documentation match the implementation, fix examples
-rw-r--r--doc/languages-frameworks/rust.section.md2
-rw-r--r--doc/stdenv/stdenv.chapter.md9
2 files changed, 8 insertions, 3 deletions
diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md
index 2f65afc796c..08738026447 100644
--- a/doc/languages-frameworks/rust.section.md
+++ b/doc/languages-frameworks/rust.section.md
@@ -558,7 +558,7 @@ buildPythonPackage rec {
     hash = "sha256-miW//pnOmww2i6SOGbkrAIdc/JMDT4FJLqdMFojZeoY=";
   };
 
-  sourceRoot = "source/bindings/python";
+  sourceRoot = "${src.name}/bindings/python";
 
   nativeBuildInputs = [
     cargo
diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md
index a0f81b97f6b..4e8559467f5 100644
--- a/doc/stdenv/stdenv.chapter.md
+++ b/doc/stdenv/stdenv.chapter.md
@@ -614,14 +614,19 @@ The list of source files or directories to be unpacked or copied. One of these m
 
 ##### `sourceRoot` {#var-stdenv-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.
+After unpacking all of `src` and `srcs`, if neither of `sourceRoot` and `setSourceRoot` are set, `unpackPhase` of the generic builder checks that the unpacking produced a single directory and moves the current working directory into it.
 
-By default the `sourceRoot` is set to `"source"`. If you want to point to a sub-directory inside your project, you therefore need to set `sourceRoot = "source/my-sub-directory"`.
+If `unpackPhase` produces multiple source directories, you should set `sourceRoot` to the name of the intended directory.
+You can also set `sourceRoot = ".";` if you want to control it yourself in a later phase.
+
+For example, if your want your build to start in a sub-directory inside your sources, and you are using `fetchzip`-derived `src` (like `fetchFromGitHub` or similar), you need to set `sourceRoot = "${src.name}/my-sub-directory"`.
 
 ##### `setSourceRoot` {#var-stdenv-setSourceRoot}
 
 Alternatively to setting `sourceRoot`, you can set `setSourceRoot` to a shell command to be evaluated by the unpack phase after the sources have been unpacked. This command must set `sourceRoot`.
 
+For example, if you are using `fetchurl` on an archive file that gets unpacked into a single directory the name of which changes between package versions, and you want your build to start in its sub-directory, you need to set `setSourceRoot = "sourceRoot=$(echo */my-sub-directory)";`, or in the case of multiple sources, you could use something more specific, like `setSourceRoot = "sourceRoot=$(echo ${pname}-*/my-sub-directory)";`.
+
 ##### `preUnpack` {#var-stdenv-preUnpack}
 
 Hook executed at the start of the unpack phase.