diff options
-rw-r--r-- | documentation-highlighter/default.nix | 7 | ||||
-rw-r--r-- | flake.nix | 199 | ||||
-rw-r--r-- | manpage.nix | 31 | ||||
-rw-r--r-- | mdbook.nix | 131 |
4 files changed, 206 insertions, 162 deletions
diff --git a/documentation-highlighter/default.nix b/documentation-highlighter/default.nix index 2a34e36..dbba883 100644 --- a/documentation-highlighter/default.nix +++ b/documentation-highlighter/default.nix | |||
@@ -1,11 +1,14 @@ | |||
1 | { lib, runCommand }: | 1 | { |
2 | lib, | ||
3 | runCommand, | ||
4 | }: | ||
2 | runCommand "documentation-highlighter" { | 5 | runCommand "documentation-highlighter" { |
3 | meta = { | 6 | meta = { |
4 | description = "Highlight.js sources for the Nix Ecosystem's documentation"; | 7 | description = "Highlight.js sources for the Nix Ecosystem's documentation"; |
5 | homepage = "https://highlightjs.org"; | 8 | homepage = "https://highlightjs.org"; |
6 | license = lib.licenses.bsd3; | 9 | license = lib.licenses.bsd3; |
7 | platforms = lib.platforms.all; | 10 | platforms = lib.platforms.all; |
8 | maintainers = [ lib.maintainers.grahamc ]; | 11 | maintainers = [lib.maintainers.grahamc]; |
9 | }; | 12 | }; |
10 | } '' | 13 | } '' |
11 | cp -r ${./.} $out | 14 | cp -r ${./.} $out |
@@ -3,102 +3,131 @@ | |||
3 | 3 | ||
4 | inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05"; | 4 | inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05"; |
5 | 5 | ||
6 | outputs = { self, nixpkgs }: | 6 | outputs = { |
7 | let pkgs = nixpkgs.legacyPackages.x86_64-linux; | 7 | self, |
8 | in | 8 | nixpkgs, |
9 | { | 9 | }: let |
10 | pkgs = nixpkgs.legacyPackages.x86_64-linux; | ||
11 | in { | ||
12 | lib.modules = { | ||
13 | doc-options-md = import ./doc-options-md.nix; | ||
14 | mdbook = import ./mdbook.nix; | ||
15 | manpage = import ./manpage.nix; | ||
16 | }; | ||
10 | 17 | ||
11 | lib.modules = { | 18 | checks.x86_64-linux = let |
12 | doc-options-md = import ./doc-options-md.nix; | 19 | evalModules = modules: |
13 | mdbook = import ./mdbook.nix; | 20 | pkgs.lib.evalModules { |
14 | manpage = import ./manpage.nix; | 21 | modules = |
22 | [ | ||
23 | {config._module.args = {inherit pkgs;};} | ||
24 | ] | ||
25 | ++ modules; | ||
26 | }; | ||
27 | simpleModule = with pkgs.lib; { | ||
28 | options.my.simple.module.outputs = mkOption { | ||
29 | type = with types; attrsOf package; | ||
30 | default = {}; | ||
31 | description = '' | ||
32 | Output products of my simple module system. | ||
33 | ''; | ||
34 | }; | ||
35 | }; | ||
36 | params = { | ||
37 | outputAttrPath = ["my" "simple" "module" "outputs"]; | ||
38 | optionsAttrPath = ["my" "simple" "module" "doc"]; | ||
39 | optionsInternal = false; | ||
15 | }; | 40 | }; |
16 | 41 | ||
17 | checks.x86_64-linux = | 42 | simple-manpage = { |
18 | let | 43 | name = "my simple module system"; |
19 | evalModules = modules: pkgs.lib.evalModules { | 44 | shortDescription = "A sample module system"; |
20 | modules = [ | 45 | }; |
21 | ({ config._module.args = { inherit pkgs; }; }) | ||
22 | ] ++ modules; | ||
23 | }; | ||
24 | simpleModule = with pkgs.lib; { | ||
25 | options.my.simple.module.outputs = mkOption { | ||
26 | type = with types; attrsOf package; | ||
27 | default = { }; | ||
28 | description = '' | ||
29 | Output products of my simple module system. | ||
30 | ''; | ||
31 | }; | ||
32 | }; | ||
33 | params = { | ||
34 | outputAttrPath = [ "my" "simple" "module" "outputs" ]; | ||
35 | optionsAttrPath = [ "my" "simple" "module" "doc" ]; | ||
36 | optionsInternal = false; | ||
37 | }; | ||
38 | |||
39 | simple-manpage = { | ||
40 | name = "my simple module system"; | ||
41 | shortDescription = "A sample module system"; | ||
42 | }; | ||
43 | |||
44 | advanced-manpage = { | ||
45 | name = "my simple module system"; | ||
46 | section = 5; | ||
47 | shortDescription = "A sample module system"; | ||
48 | description = '' | ||
49 | This is a very advanced module system, for advanced people. | ||
50 | ''; | ||
51 | 46 | ||
52 | textBefore = '' | 47 | advanced-manpage = { |
53 | # A SECTION BEFORE | 48 | name = "my simple module system"; |
49 | section = 5; | ||
50 | shortDescription = "A sample module system"; | ||
51 | description = '' | ||
52 | This is a very advanced module system, for advanced people. | ||
53 | ''; | ||
54 | 54 | ||
55 | This is a section before the options. | 55 | textBefore = '' |
56 | ''; | 56 | # A SECTION BEFORE |
57 | 57 | ||
58 | textAfter = '' | 58 | This is a section before the options. |
59 | # A SECTION AFTER | 59 | ''; |
60 | 60 | ||
61 | This is a section after the options. | 61 | textAfter = '' |
62 | ''; | 62 | # A SECTION AFTER |
63 | }; | ||
64 | in | ||
65 | { | ||
66 | simple-doc-options-md = (evalModules [ | ||
67 | simpleModule | ||
68 | (self.lib.modules.doc-options-md params) | ||
69 | ]).config.my.simple.module.outputs.doc-options-md; | ||
70 | 63 | ||
71 | simple-manpage = (evalModules [ | 64 | This is a section after the options. |
72 | simpleModule | 65 | ''; |
73 | (self.lib.modules.doc-options-md params) | 66 | }; |
74 | (self.lib.modules.manpage params) | 67 | in { |
75 | { | 68 | simple-doc-options-md = |
76 | my.simple.module.doc.manpage = simple-manpage; | 69 | (evalModules [ |
77 | } | 70 | simpleModule |
78 | ]).config.my.simple.module.outputs.manpage; | 71 | (self.lib.modules.doc-options-md params) |
72 | ]) | ||
73 | .config | ||
74 | .my | ||
75 | .simple | ||
76 | .module | ||
77 | .outputs | ||
78 | .doc-options-md; | ||
79 | 79 | ||
80 | advanced-manpage = (evalModules [ | 80 | simple-manpage = |
81 | simpleModule | 81 | (evalModules [ |
82 | (self.lib.modules.doc-options-md params) | 82 | simpleModule |
83 | (self.lib.modules.manpage params) | 83 | (self.lib.modules.doc-options-md params) |
84 | { | 84 | (self.lib.modules.manpage params) |
85 | my.simple.module.doc.manpage = advanced-manpage; | 85 | { |
86 | } | 86 | my.simple.module.doc.manpage = simple-manpage; |
87 | ]).config.my.simple.module.outputs.manpage; | 87 | } |
88 | ]) | ||
89 | .config | ||
90 | .my | ||
91 | .simple | ||
92 | .module | ||
93 | .outputs | ||
94 | .manpage; | ||
88 | 95 | ||
89 | simple-mdbook = (evalModules [ | 96 | advanced-manpage = |
90 | simpleModule | 97 | (evalModules [ |
91 | (self.lib.modules.doc-options-md params) | 98 | simpleModule |
92 | (self.lib.modules.mdbook params) | 99 | (self.lib.modules.doc-options-md params) |
93 | { | 100 | (self.lib.modules.manpage params) |
94 | my.simple.module.doc.mdbook.src = ./checks/simple-mdbook; | 101 | { |
95 | } | 102 | my.simple.module.doc.manpage = advanced-manpage; |
96 | ]).config.my.simple.module.outputs.mdbook; | 103 | } |
104 | ]) | ||
105 | .config | ||
106 | .my | ||
107 | .simple | ||
108 | .module | ||
109 | .outputs | ||
110 | .manpage; | ||
97 | 111 | ||
98 | }; | 112 | simple-mdbook = |
113 | (evalModules [ | ||
114 | simpleModule | ||
115 | (self.lib.modules.doc-options-md params) | ||
116 | (self.lib.modules.mdbook params) | ||
117 | { | ||
118 | my.simple.module.doc.mdbook.src = ./checks/simple-mdbook; | ||
119 | } | ||
120 | ]) | ||
121 | .config | ||
122 | .my | ||
123 | .simple | ||
124 | .module | ||
125 | .outputs | ||
126 | .mdbook; | ||
127 | }; | ||
99 | 128 | ||
100 | devShell.x86_64-linux = pkgs.mkShell { | 129 | devShell.x86_64-linux = pkgs.mkShell { |
101 | nativeBuildInputs = with pkgs; [ mdbook pandoc ]; | 130 | nativeBuildInputs = with pkgs; [mdbook pandoc]; |
102 | }; | ||
103 | }; | 131 | }; |
132 | }; | ||
104 | } | 133 | } |
diff --git a/manpage.nix b/manpage.nix index bea6b25..c47d88a 100644 --- a/manpage.nix +++ b/manpage.nix | |||
@@ -1,13 +1,16 @@ | |||
1 | { outputAttrPath, optionsAttrPath, optionsInternal ? true, }: | ||
2 | |||
3 | { config, lib, pkgs, ... }: | ||
4 | |||
5 | with lib; | ||
6 | |||
7 | let | ||
8 | cfg = getAttrFromPath (optionsAttrPath ++ [ "manpage" ]) config; | ||
9 | in | ||
10 | { | 1 | { |
2 | outputAttrPath, | ||
3 | optionsAttrPath, | ||
4 | optionsInternal ? true, | ||
5 | }: { | ||
6 | config, | ||
7 | lib, | ||
8 | pkgs, | ||
9 | ... | ||
10 | }: | ||
11 | with lib; let | ||
12 | cfg = getAttrFromPath (optionsAttrPath ++ ["manpage"]) config; | ||
13 | in { | ||
11 | options = setAttrByPath optionsAttrPath { | 14 | options = setAttrByPath optionsAttrPath { |
12 | manpage = { | 15 | manpage = { |
13 | name = mkOption { | 16 | name = mkOption { |
@@ -93,12 +96,12 @@ in | |||
93 | default = ""; | 96 | default = ""; |
94 | internal = optionsInternal; | 97 | internal = optionsInternal; |
95 | }; | 98 | }; |
96 | |||
97 | }; | 99 | }; |
98 | }; | 100 | }; |
99 | 101 | ||
100 | config = setAttrByPath outputAttrPath { | 102 | config = setAttrByPath outputAttrPath { |
101 | manpage = pkgs.runCommand cfg.file | 103 | manpage = |
104 | pkgs.runCommand cfg.file | ||
102 | { | 105 | { |
103 | src = pkgs.writeText "${cfg.file}.md" '' | 106 | src = pkgs.writeText "${cfg.file}.md" '' |
104 | % ${cfg.title} | 107 | % ${cfg.title} |
@@ -128,9 +131,9 @@ in | |||
128 | ${cfg.textAfter} | 131 | ${cfg.textAfter} |
129 | ''; | 132 | ''; |
130 | 133 | ||
131 | nativeBuildInputs = [ pkgs.pandoc ]; | 134 | nativeBuildInputs = [pkgs.pandoc]; |
132 | } '' | 135 | } '' |
133 | pandoc "$src" --from=markdown --to=man --standalone --output="$out" | 136 | pandoc "$src" --from=markdown --to=man --standalone --output="$out" |
134 | ''; | 137 | ''; |
135 | }; | 138 | }; |
136 | } | 139 | } |
@@ -1,15 +1,18 @@ | |||
1 | { outputAttrPath, optionsAttrPath, optionsInternal ? true, }: | ||
2 | |||
3 | { config, lib, pkgs, ... }: | ||
4 | |||
5 | with lib; | ||
6 | |||
7 | let | ||
8 | cfg = getAttrFromPath (optionsAttrPath ++ [ "mdbook" ]) config; | ||
9 | |||
10 | documentation-highlighter = pkgs.callPackage ./documentation-highlighter { }; | ||
11 | in | ||
12 | { | 1 | { |
2 | outputAttrPath, | ||
3 | optionsAttrPath, | ||
4 | optionsInternal ? true, | ||
5 | }: { | ||
6 | config, | ||
7 | lib, | ||
8 | pkgs, | ||
9 | ... | ||
10 | }: | ||
11 | with lib; let | ||
12 | cfg = getAttrFromPath (optionsAttrPath ++ ["mdbook"]) config; | ||
13 | |||
14 | documentation-highlighter = pkgs.callPackage ./documentation-highlighter {}; | ||
15 | in { | ||
13 | options = setAttrByPath optionsAttrPath { | 16 | options = setAttrByPath optionsAttrPath { |
14 | mdbook = { | 17 | mdbook = { |
15 | src = mkOption { | 18 | src = mkOption { |
@@ -21,40 +24,45 @@ in | |||
21 | }; | 24 | }; |
22 | 25 | ||
23 | pages = mkOption { | 26 | pages = mkOption { |
24 | type = with types; attrsOf (submodule ({ name, config, ... }: { | 27 | type = with types; |
25 | options = { | 28 | attrsOf (submodule ({ |
26 | target = mkOption { | 29 | name, |
27 | type = types.str; | 30 | config, |
28 | default = name; | 31 | ... |
29 | description = '' | 32 | }: { |
30 | Where to install the page, relative to the `src/` directory. | 33 | options = { |
31 | ''; | 34 | target = mkOption { |
32 | internal = optionsInternal; | 35 | type = types.str; |
33 | }; | 36 | default = name; |
34 | 37 | description = '' | |
35 | text = mkOption { | 38 | Where to install the page, relative to the `src/` directory. |
36 | type = types.lines; | 39 | ''; |
37 | description = '' | 40 | internal = optionsInternal; |
38 | Content of the page. | 41 | }; |
39 | ''; | 42 | |
40 | internal = optionsInternal; | 43 | text = mkOption { |
44 | type = types.lines; | ||
45 | description = '' | ||
46 | Content of the page. | ||
47 | ''; | ||
48 | internal = optionsInternal; | ||
49 | }; | ||
50 | |||
51 | source = mkOption { | ||
52 | type = types.path; | ||
53 | description = '' | ||
54 | Path of the source file for this page. | ||
55 | |||
56 | If both `text` and `source` are defined, `source` takes | ||
57 | precedence. | ||
58 | ''; | ||
59 | internal = optionsInternal; | ||
60 | }; | ||
41 | }; | 61 | }; |
42 | 62 | ||
43 | source = mkOption { | 63 | config.source = mkDefault (pkgs.writeText name config.text); |
44 | type = types.path; | 64 | })); |
45 | description = '' | 65 | default = {}; |
46 | Path of the source file for this page. | ||
47 | |||
48 | If both `text` and `source` are defined, `source` takes | ||
49 | precedence. | ||
50 | ''; | ||
51 | internal = optionsInternal; | ||
52 | }; | ||
53 | }; | ||
54 | |||
55 | config.source = mkDefault (pkgs.writeText name config.text); | ||
56 | })); | ||
57 | default = { }; | ||
58 | example = { | 66 | example = { |
59 | "my-page.md".text = '' | 67 | "my-page.md".text = '' |
60 | # Title | 68 | # Title |
@@ -89,44 +97,45 @@ in | |||
89 | }; | 97 | }; |
90 | 98 | ||
91 | config = mkMerge [ | 99 | config = mkMerge [ |
92 | (setAttrByPath (optionsAttrPath ++ [ "mdbook" ]) { | 100 | (setAttrByPath (optionsAttrPath ++ ["mdbook"]) { |
93 | pages."options.md".text = '' | 101 | pages."options.md".text = '' |
94 | # Available options | 102 | # Available options |
95 | 103 | ||
96 | You can use the following options: | 104 | You can use the following options: |
97 | 105 | ||
98 | 106 | ||
99 | ${readFile (getAttrFromPath (outputAttrPath ++ [ "doc-options-md" ]) config)} | 107 | ${readFile (getAttrFromPath (outputAttrPath ++ ["doc-options-md"]) config)} |
100 | ''; | 108 | ''; |
101 | }) | 109 | }) |
102 | 110 | ||
103 | (setAttrByPath outputAttrPath { | 111 | (setAttrByPath outputAttrPath { |
104 | # TODO: make pandoc pre-processor | 112 | # TODO: make pandoc pre-processor |
105 | mdbook = pkgs.runCommand "mdbook" | 113 | mdbook = |
114 | pkgs.runCommand "mdbook" | ||
106 | { | 115 | { |
107 | src = cfg.src; | 116 | src = cfg.src; |
108 | nativeBuildInputs = with pkgs; [ mdbook ]; | 117 | nativeBuildInputs = with pkgs; [mdbook]; |
109 | } '' | 118 | } '' |
110 | unpackFile "$src" | 119 | unpackFile "$src" |
111 | chmod -R u+w . | 120 | chmod -R u+w . |
112 | cd */ | 121 | cd */ |
113 | 122 | ||
114 | mkdir theme | 123 | mkdir theme |
115 | cp ${documentation-highlighter}/highlight.min.js theme/highlight.js | 124 | cp ${documentation-highlighter}/highlight.min.js theme/highlight.js |
116 | cp ${documentation-highlighter}/mono-blue.min.css theme/highlight.css | 125 | cp ${documentation-highlighter}/mono-blue.min.css theme/highlight.css |
117 | 126 | ||
118 | ${concatMapStrings (page: '' | 127 | ${concatMapStrings (page: '' |
119 | cp "${page.source}" "src/${page.target}" | 128 | cp "${page.source}" "src/${page.target}" |
120 | '') (attrValues cfg.pages)} | 129 | '') (attrValues cfg.pages)} |
121 | 130 | ||
122 | ${cfg.preBuild} | 131 | ${cfg.preBuild} |
123 | 132 | ||
124 | mdbook build | 133 | mdbook build |
125 | 134 | ||
126 | ${cfg.postBuild} | 135 | ${cfg.postBuild} |
127 | 136 | ||
128 | cp -r book "$out" | 137 | cp -r book "$out" |
129 | ''; | 138 | ''; |
130 | }) | 139 | }) |
131 | ]; | 140 | ]; |
132 | } | 141 | } |