nix-community.nixvim/docs/default.nix

120 lines
3.3 KiB
Nix
Raw Normal View History

{ helpers, pkgs }:
2024-05-05 19:39:35 +02:00
let
# Extend nixpkg's lib, so that we can handle recursive leaf types such as `either`
lib = pkgs.lib.extend (
final: prev: {
types = prev.types // {
either =
t1: t2:
(prev.types.either t1 t2)
// {
getSubOptions = prefix: (t1.getSubOptions prefix) // (t2.getSubOptions prefix);
};
eitherRecursive = t1: t2: (final.types.either t1 t2) // { getSubOptions = _: { }; };
oneOfRecursive =
ts:
let
head' =
if ts == [ ] then
throw "types.oneOfRecursive needs to get at least one type in its argument"
else
builtins.head ts;
tail' = builtins.tail ts;
in
builtins.foldl' final.types.eitherRecursive head' tail';
2024-05-05 19:39:35 +02:00
};
}
);
pkgsDoc = pkgs // {
inherit lib;
};
nixvimPath = toString ./..;
2023-08-24 14:50:16 +03:30
gitHubDeclaration = user: repo: branch: subpath: {
url = "https://github.com/${user}/${repo}/blob/${branch}/${subpath}";
name = "<${repo}/${subpath}>";
};
2023-08-24 14:50:16 +03:30
2024-05-05 19:39:35 +02:00
transformOptions =
opt:
opt
// {
2024-05-05 19:39:35 +02:00
declarations = map (
decl:
if lib.hasPrefix nixvimPath (toString decl) then
gitHubDeclaration "nix-community" "nixvim" "main" (
lib.removePrefix "/" (lib.removePrefix nixvimPath (toString decl))
)
else if decl == "lib/modules.nix" then
gitHubDeclaration "NixOS" "nixpkgs" "master" decl
else
decl
) opt.declarations;
};
nixvmConfigType = lib.mkOptionType {
name = "nixvim-configuration";
description = "nixvim configuration options";
descriptionClass = "noun";
# Evaluation is irrelevant, only used for documentation.
};
# Construct our own top-level modules, because we want to stub the `files` option
# FIXME: add a way to handle this with specialArgs
2024-05-05 19:39:35 +02:00
topLevelModules = [
../modules
../modules/top-level/output.nix
2024-05-05 19:39:35 +02:00
# Fake module to avoid a duplicated documentation
(lib.setDefaultModuleLocation "${nixvimPath}/wrappers/modules/files.nix" {
options.files = lib.mkOption {
type = lib.types.attrsOf nixvmConfigType;
description = "Extra files to add to the runtimepath";
example = {
"ftplugin/nix.lua" = {
options = {
tabstop = 2;
shiftwidth = 2;
expandtab = true;
};
};
};
2024-05-05 19:39:35 +02:00
};
})
];
2024-05-05 19:39:35 +02:00
hmOptions = builtins.removeAttrs (lib.evalModules {
modules = [ (import ../wrappers/modules/hm.nix { inherit lib; }) ];
}).options [ "_module" ];
in
2024-05-05 19:39:35 +02:00
rec {
options-json =
(pkgsDoc.nixosOptionsDoc {
inherit
(lib.evalModules {
modules = topLevelModules;
specialArgs = {
inherit helpers;
defaultPkgs = pkgsDoc;
};
})
2024-05-05 19:39:35 +02:00
options
;
inherit transformOptions;
2024-05-05 19:39:35 +02:00
warningsAreErrors = false;
}).optionsJSON;
man-docs = pkgsDoc.callPackage ./man { inherit options-json; };
}
# Do not check if documentation builds fine on darwin as it fails:
# > sandbox-exec: pattern serialization length 69298 exceeds maximum (65535)
// lib.optionalAttrs (!pkgsDoc.stdenv.isDarwin) {
docs = pkgsDoc.callPackage ./mdbook {
inherit transformOptions;
modules = topLevelModules;
inherit helpers hmOptions;
};
}