fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Emilydocs: hide `_module.*` from NixOS/nix-darwin docsc707d4f5

master
5.2 KiB154 linesraw
1{ pkgs
2
3# Note, this should be "the standard library" + HM extensions.
4, lib ? import ../modules/lib/stdlib-extended.nix pkgs.lib
5
6, release, isReleaseBranch }:
7
8let
9
10  nmdSrc = fetchTarball {
11    url =
12      "https://git.sr.ht/~rycee/nmd/archive/824a380546b5d0d0eb701ff8cd5dbafb360750ff.tar.gz";
13    sha256 = "0vvj40k6bw8ssra8wil9rqbsznmfy1kwy7cihvm13rajwdg9ycgg";
14  };
15
16  nmd = import nmdSrc {
17    inherit lib;
18    # The DocBook output of `nixos-render-docs` doesn't have the change
19    # `nmd` uses to work around the broken stylesheets in
20    # `docbook-xsl-ns`, so we restore the patched version here.
21    pkgs = pkgs // {
22      docbook-xsl-ns =
23        pkgs.docbook-xsl-ns.override { withManOptDedupPatch = true; };
24    };
25  };
26
27  # Make sure the used package is scrubbed to avoid actually
28  # instantiating derivations.
29  scrubbedPkgsModule = {
30    imports = [{
31      _module.args = {
32        pkgs = lib.mkForce (nmd.scrubDerivations "pkgs" pkgs);
33        pkgs_i686 = lib.mkForce { };
34      };
35    }];
36  };
37
38  dontCheckDefinitions = { _module.check = false; };
39
40  gitHubDeclaration = user: repo: subpath:
41    let urlRef = if isReleaseBranch then "release-${release}" else "master";
42    in {
43      url = "https://github.com/${user}/${repo}/blob/${urlRef}/${subpath}";
44      name = "<${repo}/${subpath}>";
45    };
46
47  hmPath = toString ./..;
48
49  buildOptionsDocs = args@{ modules, includeModuleSystemOptions ? true, ... }:
50    let options = (lib.evalModules { inherit modules; }).options;
51    in pkgs.buildPackages.nixosOptionsDoc ({
52      options = if includeModuleSystemOptions then
53        options
54      else
55        builtins.removeAttrs options [ "_module" ];
56      transformOptions = opt:
57        opt // {
58          # Clean up declaration sites to not refer to the Home Manager
59          # source tree.
60          declarations = map (decl:
61            if lib.hasPrefix hmPath (toString decl) then
62              gitHubDeclaration "nix-community" "home-manager"
63              (lib.removePrefix "/" (lib.removePrefix hmPath (toString decl)))
64            else if decl == "lib/modules.nix" then
65            # TODO: handle this in a better way (may require upstream
66            # changes to nixpkgs)
67              gitHubDeclaration "NixOS" "nixpkgs" decl
68            else
69              decl) opt.declarations;
70        };
71    } // builtins.removeAttrs args [ "modules" "includeModuleSystemOptions" ]);
72
73  hmOptionsDocs = buildOptionsDocs {
74    modules = import ../modules/modules.nix {
75      inherit lib pkgs;
76      check = false;
77    } ++ [ scrubbedPkgsModule ];
78    variablelistId = "home-manager-options";
79  };
80
81  nixosOptionsDocs = buildOptionsDocs {
82    modules = [ ../nixos scrubbedPkgsModule dontCheckDefinitions ];
83    includeModuleSystemOptions = false;
84    variablelistId = "nixos-options";
85    optionIdPrefix = "nixos-opt-";
86  };
87
88  nixDarwinOptionsDocs = buildOptionsDocs {
89    modules = [ ../nix-darwin scrubbedPkgsModule dontCheckDefinitions ];
90    includeModuleSystemOptions = false;
91    variablelistId = "nix-darwin-options";
92    optionIdPrefix = "nix-darwin-opt-";
93  };
94
95  docs = nmd.buildDocBookDocs {
96    pathName = "home-manager";
97    projectName = "Home Manager";
98    modulesDocs = [{
99      docBook = pkgs.linkFarm "hm-module-docs-for-nmd" {
100        "nmd-result/home-manager-options.xml" = hmOptionsDocs.optionsDocBook;
101        "nmd-result/nix-darwin-options.xml" =
102          nixDarwinOptionsDocs.optionsDocBook;
103        "nmd-result/nixos-options.xml" = nixosOptionsDocs.optionsDocBook;
104      };
105    }];
106    documentsDirectory = ./.;
107    documentType = "book";
108    chunkToc = ''
109      <toc>
110        <d:tocentry xmlns:d="http://docbook.org/ns/docbook" linkend="book-home-manager-manual"><?dbhtml filename="index.html"?>
111          <d:tocentry linkend="ch-options"><?dbhtml filename="options.html"?></d:tocentry>
112          <d:tocentry linkend="ch-nixos-options"><?dbhtml filename="nixos-options.html"?></d:tocentry>
113          <d:tocentry linkend="ch-nix-darwin-options"><?dbhtml filename="nix-darwin-options.html"?></d:tocentry>
114          <d:tocentry linkend="ch-tools"><?dbhtml filename="tools.html"?></d:tocentry>
115          <d:tocentry linkend="ch-release-notes"><?dbhtml filename="release-notes.html"?></d:tocentry>
116        </d:tocentry>
117      </toc>
118    '';
119  };
120
121in {
122  inherit nmdSrc;
123
124  options = {
125    # TODO: Use `hmOptionsDocs.optionsJSON` directly once upstream
126    # `nixosOptionsDoc` is more customizable.
127    json = pkgs.runCommand "options.json" {
128      meta.description = "List of Home Manager options in JSON format";
129    } ''
130      mkdir -p $out/{share/doc,nix-support}
131      cp -a ${hmOptionsDocs.optionsJSON}/share/doc/nixos $out/share/doc/home-manager
132      substitute \
133        ${hmOptionsDocs.optionsJSON}/nix-support/hydra-build-products \
134        $out/nix-support/hydra-build-products \
135        --replace \
136          '${hmOptionsDocs.optionsJSON}/share/doc/nixos' \
137          "$out/share/doc/home-manager"
138    '';
139  };
140
141  manPages = docs.manPages;
142
143  manual = { inherit (docs) html htmlOpenTool; };
144
145  # Unstable, mainly for CI.
146  jsonModuleMaintainers = pkgs.writeText "hm-module-maintainers.json" (let
147    result = lib.evalModules {
148      modules = import ../modules/modules.nix {
149        inherit lib pkgs;
150        check = false;
151      } ++ [ scrubbedPkgsModule ];
152    };
153  in builtins.toJSON result.config.meta.maintainers);
154}