Skip to content

Commit 14a9e57

Browse files
committed
Docs for modular modules
1 parent 33f8e18 commit 14a9e57

File tree

4 files changed

+62
-6
lines changed

4 files changed

+62
-6
lines changed

docs/api.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ import { RenderDocs } from "easy-nix-documentation";
1414

1515
## Main API
1616

17-
<RenderDocs :options="data" :exclude="[/^_module\.args$/, /^build\.*/, /programs/]" />
17+
<RenderDocs :options="data" :exclude="[/^_module\.args$/, /^build\.*/, /programs/, /^\<imports = \[ .* \]\>/]" />
1818

1919
## Program configuration
2020

2121
<RenderDocs :options="data" :include="[/programs/]" />
2222

23+
## Modular modules
24+
25+
<RenderDocs :options="data" :include="[/^\<imports = \[ .* \]\>/]" />
26+
2327
## Outputs
2428

2529
<RenderDocs :options="data" :include="/^build\.*/" />

docs/modular-modules.nix

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# https://github.com/NixOS/nixpkgs/blob/52c032768a8bd0c7a23fdad4232e50a2962079c2/nixos/modules/misc/documentation/modular-services.nix
2+
{ lib, pkgs, ... }:
3+
let
4+
fakeSubmodule =
5+
module:
6+
lib.mkOption {
7+
type = lib.types.submodule [
8+
module
9+
{
10+
_file = ../modules;
11+
options.wrappers =
12+
lib.mapAttrs
13+
(
14+
name: _:
15+
lib.mkOption {
16+
type = lib.types.submodule ../modules/wrapper.nix;
17+
description = "Wrapper created by option `${name}`.";
18+
}
19+
)
20+
(lib.evalModules {
21+
modules = [
22+
module
23+
{
24+
options.wrappers = lib.mkOption {
25+
type = lib.types.attrsOf (lib.types.submodule ../modules/wrapper.nix);
26+
};
27+
}
28+
];
29+
}).config.wrappers;
30+
}
31+
];
32+
description = "This is a modular module (inspired by [modular service](https://nixos.org/manual/nixos/unstable/#modular-services)), which can be imported into a wrapper-manager configuration using the `wrappers` option.";
33+
};
34+
35+
modularModulesModule = {
36+
_file = "${__curPos.file}#L${toString __curPos.line}";
37+
options = { };
38+
};
39+
in
40+
modularModulesModule

docs/package.nix

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ let
99
options_json =
1010
(nixosOptionsDoc {
1111
options =
12-
((import ../.).lib {
13-
inherit pkgs;
14-
modules = [ ];
15-
}).options;
12+
lib.recursiveUpdate
13+
((import ../.).lib {
14+
inherit pkgs;
15+
modules = [ ./modular-modules.nix ];
16+
}).options
17+
{
18+
wrappers.type = lib.types.attrsOf (
19+
lib.types.submodule [
20+
../modules/wrapper.nix
21+
(pkgs.extend (import ../.).overlays.default).mkWrapper.modules.wrapped
22+
]
23+
);
24+
};
1625
}).optionsJSON;
1726
in
1827
buildNpmPackage {

modules/default.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ in
7777
./wrapper.nix
7878
];
7979
});
80-
description = "Wrappers to create.";
80+
description = ''
81+
Wrappers to create.
82+
83+
Also a collection of [modular modules](#modular-modules) that are configured as wrappers.'';
8184
example = lib.literalExpression ''
8285
{
8386
hello = {

0 commit comments

Comments
 (0)