diff options
Diffstat (limited to 'mdbook.nix')
-rw-r--r-- | mdbook.nix | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/mdbook.nix b/mdbook.nix new file mode 100644 index 0000000..d336042 --- /dev/null +++ b/mdbook.nix | |||
@@ -0,0 +1,45 @@ | |||
1 | { outputAttrPath, optionsAttrPath, optionsInternal ? true, }: | ||
2 | |||
3 | { config, lib, pkgs, ... }: | ||
4 | |||
5 | with lib; | ||
6 | |||
7 | let | ||
8 | cfg = getAttrFromPath (optionsAttrPath ++ [ "mdbook" ]) config; | ||
9 | in | ||
10 | { | ||
11 | options = setAttrByPath optionsAttrPath { | ||
12 | mdbook = { | ||
13 | src = mkOption { | ||
14 | type = with types; either path package; | ||
15 | description = '' | ||
16 | Root directory of mdbook sources to compile. | ||
17 | ''; | ||
18 | internal = optionsInternal; | ||
19 | }; | ||
20 | }; | ||
21 | }; | ||
22 | |||
23 | config = setAttrByPath outputAttrPath { | ||
24 | # TODO: make pandoc pre-processor | ||
25 | mdbook = pkgs.runCommand "mdbook" | ||
26 | { | ||
27 | src = cfg.src; | ||
28 | nativeBuildInputs = with pkgs; [ mdbook ]; | ||
29 | } '' | ||
30 | unpackFile "$src" | ||
31 | chmod -R u+w . | ||
32 | cd */ | ||
33 | |||
34 | mkdir theme | ||
35 | cp ${pkgs.documentation-highlighter}/highlight.pack.js theme/highlight.js | ||
36 | cp ${pkgs.documentation-highlighter}/mono-blue.css theme/highlight.css | ||
37 | |||
38 | cp "${getAttrFromPath (outputAttrPath ++ ["doc-options-md"]) config}" src/options.md | ||
39 | |||
40 | mdbook build | ||
41 | |||
42 | cp -r book "$out" | ||
43 | ''; | ||
44 | }; | ||
45 | } | ||