From b076f006c6b0cc6644a651bd21d4449cc3e7e56d Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 22 Oct 2024 10:03:37 +0100 Subject: [PATCH] wrappers: add `meta.wrappers` options to wrappers Allows the docs to be a little less hard-coded. Lays the groundwork for splitting up the platform-specific option docs on a per-page basis. --- docs/mdbook/default.nix | 33 ++++++++++++++++++++++++++++++--- docs/modules/wrapper-options.md | 14 +------------- wrappers/modules/darwin.nix | 4 ++++ wrappers/modules/hm.nix | 1 + wrappers/modules/nixos.nix | 4 ++++ wrappers/modules/shared.nix | 8 ++++++++ 6 files changed, 48 insertions(+), 16 deletions(-) diff --git a/docs/mdbook/default.nix b/docs/mdbook/default.nix index b71d07b88..b55212968 100644 --- a/docs/mdbook/default.nix +++ b/docs/mdbook/default.nix @@ -224,6 +224,35 @@ let in "${padding}- [${name}](${path})" ) docs.modules; + + wrapperOptionFiles = lib.mapAttrs' (name: options: { + name = options.meta.wrapper.name.value; + # TODO: + # value.path = "./modules/${name}.md"; + value.file = mkMDDoc options; + }) wrapperOptions; + + wrapperOptionDocs = + pkgs.runCommandNoCCLocal "wrapper-option-doc" + { + __structuredAttrs = true; + files = lib.mapAttrs (name: value: value.file) mdbook.wrapperOptionFiles; + # TODO: + # paths = lib.mapAttrs (name: value: value.path) mdbook.wrapperOptionFiles; + } + '' + for name in "''${!files[@]}" + do + # $file contains the docs built by mkMDDoc + file="''${files[$name]}" + # TODO: consider putting wrapper docs in separate files: + # path="''${paths[$name]}" + echo >> "$out" + echo "## $name" >> "$out" + echo >> "$out" + cat "$file" >> $out + done + ''; }; wrapperOptions = @@ -266,9 +295,7 @@ let --replace-fail "@NIXVIM_OPTIONS@" "$(cat ${pkgs.writeText "nixvim-options-summary.md" mdbook.nixvimOptions})" substituteInPlace ./modules/wrapper-options.md \ - --replace-fail "@NIXOS_OPTIONS@" "$(cat ${mkMDDoc wrapperOptions.nixos})" \ - --replace-fail "@HM_OPTIONS@" "$(cat ${mkMDDoc wrapperOptions.hm})" \ - --replace-fail "@DARWIN_OPTIONS@" "$(cat ${mkMDDoc wrapperOptions.darwin})" + --replace-fail "@WRAPPER_OPTIONS@" "$(cat ${mdbook.wrapperOptionDocs})" ''; in pkgs.stdenv.mkDerivation { diff --git a/docs/modules/wrapper-options.md b/docs/modules/wrapper-options.md index 039da5cfa..2bc5a3486 100644 --- a/docs/modules/wrapper-options.md +++ b/docs/modules/wrapper-options.md @@ -8,17 +8,5 @@ See [Standalone Usage](./standalone.md) for more info. There are a few wrapper specific options that are documented below: -## NixOS - -@NIXOS_OPTIONS@ - -## home-manager - -@HM_OPTIONS@ - -## nix-darwin - -@DARWIN_OPTIONS@ - - +@WRAPPER_OPTIONS@ diff --git a/wrappers/modules/darwin.nix b/wrappers/modules/darwin.nix index 0a497b61f..43149a730 100644 --- a/wrappers/modules/darwin.nix +++ b/wrappers/modules/darwin.nix @@ -1,3 +1,7 @@ { imports = [ ./shared.nix ]; + + config = { + meta.wrapper.name = "nix-darwin"; + }; } diff --git a/wrappers/modules/hm.nix b/wrappers/modules/hm.nix index baa8353cd..d5b2a4c47 100644 --- a/wrappers/modules/hm.nix +++ b/wrappers/modules/hm.nix @@ -17,5 +17,6 @@ config = { wrapRc = lib.mkOptionDefault false; impureRtp = lib.mkOptionDefault true; + meta.wrapper.name = "home-manager"; }; } diff --git a/wrappers/modules/nixos.nix b/wrappers/modules/nixos.nix index c1e14607d..c69c1c0ce 100644 --- a/wrappers/modules/nixos.nix +++ b/wrappers/modules/nixos.nix @@ -5,4 +5,8 @@ }; imports = [ ./shared.nix ]; + + config = { + meta.wrapper.name = "NixOS"; + }; } diff --git a/wrappers/modules/shared.nix b/wrappers/modules/shared.nix index 3b9ace88d..3aa9f7c55 100644 --- a/wrappers/modules/shared.nix +++ b/wrappers/modules/shared.nix @@ -2,5 +2,13 @@ { options = { enable = lib.mkEnableOption "nixvim"; + + meta.wrapper = { + name = lib.mkOption { + type = lib.types.str; + description = "The human-readable name of this nixvim wrapper. Used in documentation."; + internal = true; + }; + }; }; }