Skip to content

Commit

Permalink
Embedd module options into our own docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tfc committed Mar 27, 2024
1 parent 6c128f6 commit 4c40245
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
4 changes: 4 additions & 0 deletions documentation/docs/integration/flake-parts.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ This will create an empty project with a `flake.nix` file (like the example
above) and a minimal mkdocs project.

Here, you can run `nix build .#documentation` or `nix run .#watch-documentation`

## Options Reference

<!-- placeholder -->
44 changes: 40 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,47 @@
tag = "latest";
config.Cmd = [ "${config.packages.mkdocs}/bin/mkdocs" ];
};
};

documentation = {
mkdocs-root = ./documentation;
strict = true;
flake-parts-options =
let
minimalOptions = { lib, ... }:
let
fakeOption = lib.mkOption { internal = true; };
in
{
options = {
apps = fakeOption;
packages = fakeOption;
};
};
eval = pkgs.lib.evalModules {
modules = [
minimalOptions
./modules/documentation.nix
];
};
optionsDoc = pkgs.nixosOptionsDoc {
options = {
inherit (eval.options) documentation;
};
documentType = "none";
};
in
optionsDoc.optionsCommonMark;

documentation =
let
mkdocs-root = pkgs.runCommand "documentation" {} ''
cp -r ${./documentation} $out
substituteInPlace $out/docs/integration/flake-parts.md \
--replace "<!-- placeholder -->" "$(cat ${config.packages.flake-parts-options})"
'';
in
pkgs.runCommand "mkdocs-flake-documentation" {} ''
cd ${mkdocs-root}
${config.packages.mkdocs}/bin/mkdocs build --strict --site-dir $out
sed -i 's|/nix/store/[^/]\+/||g' $out/integration/flake-parts.html
'';
};

apps = {
Expand Down
5 changes: 3 additions & 2 deletions modules/documentation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ in
mkdocs-root = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = lib.mdDoc "Path to a mkdocs documentation project";
description = "Path to your mkdocs documentation project with mkdocs.yml";
};

mkdocs-package = lib.mkOption {
type = lib.types.package;
default = mkdocs-flake.withSystem system ({ config, ... }: config.packages.mkdocs);
description = lib.mdDoc "The mkdocs package to use.";
defaultText = ''mkdocs-flake.packages.''${system}.mkdocs'';
description = "The mkdocs package to use.";
};

strict = lib.mkEnableOption "build the documentation with `--strict`";
Expand Down

0 comments on commit 4c40245

Please sign in to comment.