|
2 | 2 | perSystem = { pkgs, config, ... }:
|
3 | 3 |
|
4 | 4 | # Note(jaredponn): What is going on here to generate the documentation?
|
5 |
| - # Since flake-parts is using the module system and nixos also uses the |
6 |
| - # module system, we copy how they generate documentation: |
7 |
| - # - The nix function which builds the documentation |
| 5 | + # Since flake-parts is using the module system, and NixOS also uses the |
| 6 | + # module system; we copy how NixOS generates their documentation: |
| 7 | + # [1] The Nix function which builds the documentation returning an attribute |
| 8 | + # set of a bunch of goodies: |
8 | 9 | # https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/make-options-doc/default.nix
|
9 |
| - # - The file where they actually build the documentation |
| 10 | + # [2] The file where NixOS builds its own documentation: |
10 | 11 | # https://github.com/NixOS/nixpkgs/blob/master/doc/default.nix
|
11 | 12 | let
|
12 |
| - # TODO(jaredponn): make this a module option or something so someone |
13 |
| - # can set this somewhere else... |
14 | 13 | rootSrcUrl = "https://github.com/mlabs-haskell/flake-lang.nix/blob/master";
|
15 | 14 | eval =
|
16 | 15 | # pkgs.lib.evalModules
|
|
25 | 24 | optionsDoc = pkgs.nixosOptionsDoc {
|
26 | 25 | inherit (eval) options;
|
27 | 26 | documentType = "none";
|
28 |
| - revision = "none"; |
29 | 27 | # We only want to include the options provided by us (there's a
|
30 | 28 | # bunch of extra garbage provided by flake-parts).
|
31 | 29 | # So, we set the attribute `.visible` to `false` for all options
|
|
73 | 71 | {
|
74 | 72 |
|
75 | 73 | packages = {
|
76 |
| - # Useful for debugging. |
77 |
| - docs-raw-json = optionsDoc.optionsJSON; |
78 |
| - docs-raw-common-mark = optionsDoc.optionsCommonMark; |
| 74 | + # Documentation outputs produced from [1] |
| 75 | + options-doc-json = optionsDoc.optionsJSON; |
| 76 | + options-doc-common-mark = optionsDoc.optionsCommonMark; |
79 | 77 |
|
80 | 78 | # Documentation
|
81 |
| - docs = pkgs.runCommand |
82 |
| - "flake-lang-docs" |
83 |
| - { nativeBuildInputs = [ pkgs.pandoc ]; } |
84 |
| - '' |
85 |
| - pandoc ${pkgs.lib.escapeShellArg config.packages.docs-raw-common-mark} \ |
86 |
| - --metadata title="flake-lang.nix" \ |
87 |
| - --standalone \ |
88 |
| - --output index.html |
| 79 | + docs = pkgs.stdenv.mkDerivation { |
| 80 | + name = "flake-lang-docs"; |
| 81 | + nativeBuildInputs = [ pkgs.mdbook ]; |
89 | 82 |
|
90 |
| - mkdir -p "$out" |
91 |
| - mv index.html "$out" |
92 |
| - ''; |
| 83 | + src = ./.; |
| 84 | + |
| 85 | + OPTIONS_DOC_COMMON_MARK = config.packages.options-doc-common-mark; |
| 86 | + |
| 87 | + configurePhase = |
| 88 | + '' |
| 89 | + # Provide a command for linking `$OPTIONS_DOC_COMMON_MARK` |
| 90 | + # for use when in a developer shell. |
| 91 | + link-options-doc-common-mark() { |
| 92 | + 2>&1 echo "link-options-doc-common-mark: creating a symbolic link named \`./src/api_reference.md\` pointing to \`\$OPTIONS_DOC_COMMON_MARK\`" |
| 93 | + ln -sf ${pkgs.lib.escapeShellArg config.packages.options-doc-common-mark} ./src/api_reference.md |
| 94 | + } |
| 95 | +
|
| 96 | + link-options-doc-common-mark |
| 97 | + ''; |
| 98 | + |
| 99 | + buildPhase = |
| 100 | + '' |
| 101 | + mdbook build --dest-dir book |
| 102 | + ''; |
| 103 | + |
| 104 | + installPhase = |
| 105 | + '' |
| 106 | + mkdir -p "$out" |
| 107 | + mv book/* "$out" |
| 108 | + ''; |
| 109 | + }; |
| 110 | + }; |
| 111 | + |
| 112 | + devShells = { |
| 113 | + docs = config.packages.docs.overrideAttrs (_self: super: |
| 114 | + { |
| 115 | + shellHook = |
| 116 | + '' |
| 117 | + ${super.configurePhase} |
| 118 | + ''; |
| 119 | + } |
| 120 | + ); |
93 | 121 | };
|
94 | 122 | };
|
95 | 123 | }
|
0 commit comments