Skip to content

Commit

Permalink
wrappers: add meta.wrappers options to wrappers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MattSturgeon committed Oct 22, 2024
1 parent 574ae92 commit b076f00
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
33 changes: 30 additions & 3 deletions docs/mdbook/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 1 addition & 13 deletions docs/modules/wrapper-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@

<!-- TODO: Add @STANDALONE_OPTIONS@ if we ever have standalone-specific options -->
@WRAPPER_OPTIONS@

4 changes: 4 additions & 0 deletions wrappers/modules/darwin.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
imports = [ ./shared.nix ];

config = {
meta.wrapper.name = "nix-darwin";
};
}
1 change: 1 addition & 0 deletions wrappers/modules/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
config = {
wrapRc = lib.mkOptionDefault false;
impureRtp = lib.mkOptionDefault true;
meta.wrapper.name = "home-manager";
};
}
4 changes: 4 additions & 0 deletions wrappers/modules/nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
};

imports = [ ./shared.nix ];

config = {
meta.wrapper.name = "NixOS";
};
}
8 changes: 8 additions & 0 deletions wrappers/modules/shared.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
}

0 comments on commit b076f00

Please sign in to comment.