diff options
-rw-r--r-- | mdbook.nix | 105 |
1 files changed, 84 insertions, 21 deletions
@@ -5,7 +5,7 @@ | |||
5 | with lib; | 5 | with lib; |
6 | 6 | ||
7 | let | 7 | let |
8 | cfg = getAttrFromPath (optionsAttrPath ++ [ "mdbook" ]) config; | 8 | cfg = getAttrFromPath (optionsAttrPath ++ [ "mdbook" ]) config; |
9 | in | 9 | in |
10 | { | 10 | { |
11 | options = setAttrByPath optionsAttrPath { | 11 | options = setAttrByPath optionsAttrPath { |
@@ -18,6 +18,54 @@ in | |||
18 | internal = optionsInternal; | 18 | internal = optionsInternal; |
19 | }; | 19 | }; |
20 | 20 | ||
21 | pages = mkOption { | ||
22 | type = with types; attrsOf (submodule ({ name, config, ... }: { | ||
23 | options = { | ||
24 | target = mkOption { | ||
25 | type = types.str; | ||
26 | default = name; | ||
27 | description = '' | ||
28 | Where to install the page, relative to the `src/` directory. | ||
29 | ''; | ||
30 | internal = optionsInternal; | ||
31 | }; | ||
32 | |||
33 | text = mkOption { | ||
34 | type = types.lines; | ||
35 | description = '' | ||
36 | Content of the page. | ||
37 | ''; | ||
38 | internal = optionsInternal; | ||
39 | }; | ||
40 | |||
41 | source = mkOption { | ||
42 | type = types.path; | ||
43 | description = '' | ||
44 | Path of the source file for this page. | ||
45 | |||
46 | If both `text` and `source` are defined, `source` takes | ||
47 | precedence. | ||
48 | ''; | ||
49 | internal = optionsInternal; | ||
50 | }; | ||
51 | }; | ||
52 | |||
53 | config.source = mkDefault (pkgs.writeText name config.text); | ||
54 | })); | ||
55 | default = { }; | ||
56 | example = { | ||
57 | "my-page.md".text = '' | ||
58 | # Title | ||
59 | |||
60 | hello, world! | ||
61 | ''; | ||
62 | }; | ||
63 | description = '' | ||
64 | Pages to add to the source directory before building. | ||
65 | ''; | ||
66 | internal = optionsInternal; | ||
67 | }; | ||
68 | |||
21 | preBuild = mkOption { | 69 | preBuild = mkOption { |
22 | type = types.lines; | 70 | type = types.lines; |
23 | description = '' | 71 | description = '' |
@@ -38,30 +86,45 @@ in | |||
38 | }; | 86 | }; |
39 | }; | 87 | }; |
40 | 88 | ||
41 | config = setAttrByPath outputAttrPath { | 89 | config = mkMerge [ |
42 | # TODO: make pandoc pre-processor | 90 | (setAttrByPath (optionsAttrPath ++ [ "mdbook" ]) { |
43 | mdbook = pkgs.runCommand "mdbook" | 91 | pages."options.md".text = '' |
44 | { | 92 | # Available options |
45 | src = cfg.src; | ||
46 | nativeBuildInputs = with pkgs; [ mdbook ]; | ||
47 | } '' | ||
48 | unpackFile "$src" | ||
49 | chmod -R u+w . | ||
50 | cd */ | ||
51 | 93 | ||
52 | mkdir theme | 94 | You can use the following options: |
53 | cp ${pkgs.documentation-highlighter}/highlight.pack.js theme/highlight.js | ||
54 | cp ${pkgs.documentation-highlighter}/mono-blue.css theme/highlight.css | ||
55 | 95 | ||
56 | cp "${getAttrFromPath (outputAttrPath ++ ["doc-options-md"]) config}" src/options.md | ||
57 | 96 | ||
58 | ${cfg.preBuild} | 97 | ${readFile (getAttrFromPath (outputAttrPath ++ [ "doc-options-md" ]) config)} |
98 | ''; | ||
99 | }) | ||
59 | 100 | ||
60 | mdbook build | 101 | (setAttrByPath outputAttrPath { |
102 | # TODO: make pandoc pre-processor | ||
103 | mdbook = pkgs.runCommand "mdbook" | ||
104 | { | ||
105 | src = cfg.src; | ||
106 | nativeBuildInputs = with pkgs; [ mdbook ]; | ||
107 | } '' | ||
108 | unpackFile "$src" | ||
109 | chmod -R u+w . | ||
110 | cd */ | ||
61 | 111 | ||
62 | ${cfg.postBuild} | 112 | mkdir theme |
113 | cp ${pkgs.documentation-highlighter}/highlight.pack.js theme/highlight.js | ||
114 | cp ${pkgs.documentation-highlighter}/mono-blue.css theme/highlight.css | ||
63 | 115 | ||
64 | cp -r book "$out" | 116 | ${concatMapStrings (page: '' |
65 | ''; | 117 | cp "${page.source}" "src/${page.target}" |
66 | }; | 118 | '') (attrValues cfg.pages)} |
119 | |||
120 | ${cfg.preBuild} | ||
121 | |||
122 | mdbook build | ||
123 | |||
124 | ${cfg.postBuild} | ||
125 | |||
126 | cp -r book "$out" | ||
127 | ''; | ||
128 | }) | ||
129 | ]; | ||
67 | } | 130 | } |