diff --git a/doc/default.nix b/doc/default.nix index 7aa5760b02f7..c56920c482c9 100644 --- a/doc/default.nix +++ b/doc/default.nix @@ -1,7 +1,6 @@ { pkgs ? (import ./.. { }), nixpkgs ? { }}: let inherit (pkgs) lib callPackage; - inherit (lib) hasPrefix removePrefix; fs = lib.fileset; common = import ./common.nix; @@ -12,27 +11,9 @@ let epub = callPackage ./doc-support/epub.nix { }; - # NB: This file describes the Nixpkgs manual, which happens to use module - # docs infra originally developed for NixOS. - optionsDoc = pkgs.nixosOptionsDoc { - inherit (pkgs.lib.evalModules { - modules = [ ../pkgs/top-level/config.nix ]; - class = "nixpkgsConfig"; - }) options; - documentType = "none"; - transformOptions = opt: - opt // { - declarations = - map - (decl: - if hasPrefix (toString ../..) (toString decl) - then - let subpath = removePrefix "/" (removePrefix (toString ../.) (toString decl)); - in { url = "https://github.com/NixOS/nixpkgs/blob/master/${subpath}"; name = subpath; } - else decl) - opt.declarations; - }; - }; + # 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 { }; + in pkgs.stdenv.mkDerivation { name = "nixpkgs-manual"; diff --git a/doc/doc-support/options-doc.nix b/doc/doc-support/options-doc.nix new file mode 100644 index 000000000000..6405ef9efe6f --- /dev/null +++ b/doc/doc-support/options-doc.nix @@ -0,0 +1,27 @@ +{ lib, nixosOptionsDoc }: + +let + modules = lib.evalModules { + modules = [ ../../pkgs/top-level/config.nix ]; + class = "nixpkgsConfig"; + }; + + root = toString ../..; + + transformDeclaration = + decl: + let + declStr = toString decl; + subpath = lib.removePrefix "/" (lib.removePrefix root declStr); + in + assert lib.hasPrefix root declStr; + { + url = "https://github.com/NixOS/nixpkgs/blob/master/${subpath}"; + name = subpath; + }; +in +nixosOptionsDoc { + inherit (modules) options; + documentType = "none"; + transformOptions = opt: opt // { declarations = map transformDeclaration opt.declarations; }; +}