Skip to content

Commit 889cfac

Browse files
author
jared
committed
Switch documentation to use mdbook instead of pandoc + general
cleanup on generated documentation
1 parent 58ccadf commit 889cfac

File tree

6 files changed

+71
-23
lines changed

6 files changed

+71
-23
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# flake-lang.nix
22

3-
Nix tools to help create flakes for projects
3+
Nix tools to help create flakes for projects.
44

5-
See examples [here](./examples/).
5+
## Documentation
6+
7+
- [API reference](https://mlabs-haskell.github.io/flake-lang.nix/).
8+
- [Example projects](./examples/).

docs/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
book
2+
result
3+
# Ignore `src/api_reference.md` since this is built by Nix
4+
src/api_reference.md

docs/book.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[book]
2+
authors = ["LambdaBuffers Team"]
3+
language = "en"
4+
multilingual = false
5+
src = "src"

docs/build.nix

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
perSystem = { pkgs, config, ... }:
33

44
# 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:
89
# 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:
1011
# https://github.com/NixOS/nixpkgs/blob/master/doc/default.nix
1112
let
12-
# TODO(jaredponn): make this a module option or something so someone
13-
# can set this somewhere else...
1413
rootSrcUrl = "https://github.com/mlabs-haskell/flake-lang.nix/blob/master";
1514
eval =
1615
# pkgs.lib.evalModules
@@ -25,7 +24,6 @@
2524
optionsDoc = pkgs.nixosOptionsDoc {
2625
inherit (eval) options;
2726
documentType = "none";
28-
revision = "none";
2927
# We only want to include the options provided by us (there's a
3028
# bunch of extra garbage provided by flake-parts).
3129
# So, we set the attribute `.visible` to `false` for all options
@@ -73,23 +71,53 @@
7371
{
7472

7573
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;
7977

8078
# 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 ];
8982

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+
);
93121
};
94122
};
95123
}

docs/src/SUMMARY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# flake-lang.nix
2+
3+
- [Introduction](./introduction.md)
4+
- [API Reference](./api_reference.md)

docs/src/introduction.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Introduction
2+
3+
This library provides a set of Nix functions to make creating flakes for
4+
languages such as Haskell, PureScript, Rust, and TypeScript easier.

0 commit comments

Comments
 (0)