Skip to content

Commit

Permalink
refactor: optimize docs definition
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkolenz committed Jan 20, 2025
1 parent 0dfe6f7 commit 11b6c7e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/book.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
nixdoc,
writeShellApplication,
python3,
dockerManifestMarkdown,
optionsMarkdown,
}:
stdenvNoCC.mkDerivation (finalAttrs: {
name = "book";
Expand All @@ -23,7 +23,7 @@ stdenvNoCC.mkDerivation (finalAttrs: {
buildPhase = ''
runHook preBuild
ln -s ${dockerManifestMarkdown} src/docker-manifest.md
cp ${optionsMarkdown}/*.md src
ln -s ${../README.md} src/README.md
nixdoc \
--category "" \
Expand Down
7 changes: 3 additions & 4 deletions docs/options.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
lib,
pkgs,
module,
...
nixosOptionsDoc,
}:
module:
let
eval = lib.evalModules {
modules = [
Expand All @@ -17,7 +16,7 @@ let
)
];
};
docs = pkgs.nixosOptionsDoc {
docs = nixosOptionsDoc {
inherit (eval) options;
# hide /nix/store/* prefix
transformOptions = opt: lib.removeAttrs opt [ "declarations" ];
Expand Down
19 changes: 14 additions & 5 deletions modules/docs.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
{ ... }:
{ lib, ... }:
{
perSystem =
{ pkgs, config, ... }:
let
mkOptions = pkgs.callPackage ../docs/options.nix { };
mkOptionLinks = lib.mapAttrsToList (
name: value: {
name = "${name}.md";
path = mkOptions value;
}
);
in
{
packages = {
dockerManifestMarkdown = pkgs.callPackage ../docs/options.nix {
module = ../src/docker-manifest/module.nix;
};
optionsMarkdown = pkgs.linkFarm "options-markdown" (mkOptionLinks {
docker-manifest = ../src/docker-manifest/module.nix;
});
book = pkgs.callPackage ../docs/book.nix {
inherit (config.packages) dockerManifestMarkdown;
inherit (config.packages) optionsMarkdown;
};
docs = config.packages.book;
};
Expand Down

0 comments on commit 11b6c7e

Please sign in to comment.