nix-community.nixvim/docs/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
3 KiB
Nix
Raw Normal View History

2024-07-08 07:32:53 +01:00
{
pkgs ? import <nixpkgs> { config.allowUnfree = true; },
nuschtosSearch,
2024-07-08 07:32:53 +01: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);
};
};
}
);
# Extended nixpkgs instance, with patches to nixos-render-docs
pkgsDoc = pkgs.extend (
final: prev: {
inherit lib;
nixos-render-docs = prev.nixos-render-docs.overrideAttrs (old: {
patches = old.patches or [ ] ++ [
# Adds support for GFM-style admonitions in rendered commonmark
./0001-Output-GFM-admonition.patch
# TODO:add support for _parsing_ GFM admonitions too
# https://github.com/nix-community/nixvim/issues/2217
];
});
}
);
2024-07-08 07:32:53 +01:00
helpers = import ../lib/helpers.nix {
inherit lib;
pkgs = pkgsDoc;
};
2024-07-06 00:22:17 +01:00
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
transformOptions =
opt:
opt
// {
declarations = map (
decl:
if lib.hasPrefix nixvimPath (toString decl) then
gitHubDeclaration "nix-community" "nixvim" "main" (
lib.removePrefix "/" (lib.removePrefix nixvimPath (toString decl))
2024-05-05 19:39:35 +02:00
)
else if decl == "lib/modules.nix" then
gitHubDeclaration "NixOS" "nixpkgs" "master" decl
else
decl
) opt.declarations;
};
2024-08-02 01:45:45 +01:00
evaledModules = lib.evalModules {
inherit (helpers.modules) specialArgs;
modules = [
../modules/top-level
{ isDocs = true; }
];
};
2024-05-05 19:39:35 +02:00
2024-08-02 01:45:45 +01:00
hmOptions = builtins.removeAttrs (lib.evalModules { modules = [ ../wrappers/modules/hm.nix ]; })
.options [ "_module" ];
options-json =
(pkgsDoc.nixosOptionsDoc {
2024-08-02 01:45:45 +01:00
inherit (evaledModules) options;
inherit transformOptions;
warningsAreErrors = false;
}).optionsJSON;
in
{
inherit options-json;
man-docs = pkgsDoc.callPackage ./man { inherit options-json; };
2024-05-05 19:39:35 +02:00
}
// lib.optionalAttrs (!pkgsDoc.stdenv.isDarwin) (
let
mkSearch =
baseHref:
nuschtosSearch.packages.mkSearch {
optionsJSON = options-json + "/share/doc/nixos/options.json";
urlPrefix = "https://github.com/nix-community/nixvim/tree/main";
inherit baseHref;
};
in
{
# NuschtOS/search does not seem to work on darwin
search = mkSearch "/";
# Do not check if documentation builds fine on darwin as it fails:
# > sandbox-exec: pattern serialization length 69298 exceeds maximum (65535)
docs = pkgsDoc.callPackage ./mdbook {
2024-08-02 01:45:45 +01:00
inherit evaledModules hmOptions transformOptions;
# TODO: Find how to handle stable when 24.11 lands
search = mkSearch "/nixvim/search/";
};
}
)