From 2266280af7c3fd3d3248dbff4ac463efb6c435d8 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 26 Jul 2024 11:21:15 -0700 Subject: [PATCH] doc: reshape python-interpreter-table.nix into a normal callPackage Before, it produced a string, not a derivation. --- doc/default.nix | 14 +++--- doc/doc-support/python-interpreter-table.nix | 53 ++++++++++---------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/doc/default.nix b/doc/default.nix index c56920c482c9..6cbec54f7967 100644 --- a/doc/default.nix +++ b/doc/default.nix @@ -14,6 +14,8 @@ let # NB: This file describes the Nixpkgs manual, which happens to use module docs infra originally developed for NixOS. optionsDoc = callPackage ./doc-support/options-doc.nix { }; + pythonInterpreterTable = pkgs.callPackage ./doc-support/python-interpreter-table.nix {}; + in pkgs.stdenv.mkDerivation { name = "nixpkgs-manual"; @@ -39,12 +41,9 @@ in pkgs.stdenv.mkDerivation { ln -s ${optionsDoc.optionsJSON}/share/doc/nixos/options.json ./config-options.json ''; - pythonInterpreterTable = pkgs.callPackage ./doc-support/python-interpreter-table.nix {}; - - passAsFile = [ "pythonInterpreterTable" ]; - buildPhase = '' - substituteInPlace ./languages-frameworks/python.section.md --subst-var-by python-interpreter-table "$(<"$pythonInterpreterTablePath")" + substituteInPlace ./languages-frameworks/python.section.md \ + --subst-var-by python-interpreter-table "$(<"${pythonInterpreterTable}")" cat \ ./functions/library.md.in \ @@ -92,7 +91,9 @@ in pkgs.stdenv.mkDerivation { echo "doc manual $dest nixpkgs-manual.epub" >> $out/nix-support/hydra-build-products ''; - passthru.tests.manpage-urls = with pkgs; testers.invalidateFetcherByDrvHash + passthru = { + inherit pythonInterpreterTable; + tests.manpage-urls = with pkgs; testers.invalidateFetcherByDrvHash ({ name ? "manual_check-manpage-urls" , script , urlsFile @@ -113,4 +114,5 @@ in pkgs.stdenv.mkDerivation { script = ./tests/manpage-urls.py; urlsFile = ./manpage-urls.json; }; + }; } diff --git a/doc/doc-support/python-interpreter-table.nix b/doc/doc-support/python-interpreter-table.nix index 6f2b3422f672..ca80d7631703 100644 --- a/doc/doc-support/python-interpreter-table.nix +++ b/doc/doc-support/python-interpreter-table.nix @@ -1,14 +1,15 @@ -# For debugging, run in this directory: -# nix eval --impure --raw --expr 'import ./python-interpreter-table.nix {}' -{ pkgs ? (import ../.. { config = { }; overlays = []; }) }: +# To run this derivation, `nix-build -A nixpkgs-manual.pythonInterpreterTable` +{ + lib, + writeText, + pkgs, + pythonInterpreters, +}: let - lib = pkgs.lib; - inherit (lib.attrsets) attrNames filterAttrs; - inherit (lib.lists) elem filter map naturalSort reverseList; - inherit (lib.strings) concatStringsSep; - - isPythonInterpreter = name: - /* NB: Package names that don't follow the regular expression: + isPythonInterpreter = + name: + /* + NB: Package names that don't follow the regular expression: - `python-cosmopolitan` is not part of `pkgs.pythonInterpreters`. - `_prebuilt` interpreters are used for bootstrapping internally. - `python3Minimal` contains python packages, left behind conservatively. @@ -16,7 +17,8 @@ let */ (lib.strings.match "(pypy|python)([[:digit:]]*)" name) != null; - interpreterName = pname: + interpreterName = + pname: let cuteName = { cpython = "CPython"; @@ -26,16 +28,16 @@ let in "${cuteName.${interpreter.implementation}} ${interpreter.pythonVersion}"; - interpreters = reverseList (naturalSort ( - filter isPythonInterpreter (attrNames pkgs.pythonInterpreters) - )); + interpreters = lib.reverseList ( + lib.naturalSort (lib.filter isPythonInterpreter (lib.attrNames pythonInterpreters)) + ); - aliases = pname: - attrNames ( - filterAttrs (name: value: - isPythonInterpreter name - && name != pname - && interpreterName name == interpreterName pname + aliases = + pname: + lib.attrNames ( + lib.filterAttrs ( + name: value: + isPythonInterpreter name && name != pname && interpreterName name == interpreterName pname ) pkgs ); @@ -45,18 +47,17 @@ let interpreter = interpreterName pname; }) interpreters; - toMarkdown = data: + toMarkdown = + data: let line = package: '' - | ${package.pname} | ${join ", " package.aliases or [ ]} | ${package.interpreter} | + | ${package.pname} | ${lib.concatStringsSep ", " package.aliases or [ ]} | ${package.interpreter} | ''; in - join "" (map line data); - - join = lib.strings.concatStringsSep; + lib.concatStringsSep "" (map line data); in -'' +writeText "python-interpreter-table.md" '' | Package | Aliases | Interpeter | |---------|---------|------------| ${toMarkdown result}