From 2f181d6f062e6bd0b794e7978a1ec56188be95bb Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Sat, 6 May 2023 21:56:59 -0400 Subject: [PATCH] python3.doc: build offline documentation Since python documentation requires Sphinx to build, documentation is built in separate derivation to avoid hard recursion/bootstrapping questions and plugged into main derivation. Care is taken that "python3.doc" derivation feels and looks as close as possible to as if it were main derivation were multi-output one. This change does not cause rebuild of python3 itself. --- .../interpreters/python/cpython/default.nix | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index a089dbf2002b..d1e541891ecc 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -141,6 +141,11 @@ let "$out/bin/python" else pythonForBuild.interpreter; + src = fetchurl { + url = with sourceVersion; "https://www.python.org/ftp/python/${major}.${minor}.${patch}/Python-${version}.tar.xz"; + inherit hash; + }; + # The CPython interpreter contains a _sysconfigdata_ # module that is imported by the sysconfig and distutils.sysconfig modules. # The sysconfigdata module is generated at build time and contains settings @@ -216,15 +221,11 @@ let in with passthru; stdenv.mkDerivation { pname = "python3"; - inherit version; + inherit src version; inherit nativeBuildInputs; buildInputs = [ bash ] ++ buildInputs; # bash is only for patchShebangs - src = fetchurl { - url = with sourceVersion; "https://www.python.org/ftp/python/${major}.${minor}.${patch}/Python-${version}.tar.xz"; - inherit hash; - }; prePatch = optionalString stdenv.isDarwin '' substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"' @@ -523,7 +524,24 @@ in with passthru; stdenv.mkDerivation { separateDebugInfo = true; - inherit passthru; + passthru = passthru // { + doc = stdenv.mkDerivation { + inherit src; + name = "python${pythonVersion}-${version}-doc"; + + dontConfigure = true; + + dontBuild = true; + + sphinxRoot = "Doc"; + + postInstallSphinx = '' + mv $out/share/doc/* $out/share/doc/python${pythonVersion}-${version} + ''; + + nativeBuildInputs = with pkgsBuildBuild.python3.pkgs; [ sphinxHook python_docs_theme ]; + }; + }; enableParallelBuilding = true;