treewide: Reformat with nixfmt

This commit is contained in:
traxys 2024-05-05 19:39:35 +02:00
parent c6281260dc
commit 62f32bfc71
459 changed files with 28139 additions and 26377 deletions

View file

@ -2,18 +2,19 @@
rawModules,
helpers,
pkgs,
}: let
}:
let
pkgsDoc =
import (pkgs.applyPatches {
name = "nixpkgs-nixvim-doc";
src = pkgs.path;
patches = [
./either_recursive.patch
];
}) {
inherit (pkgs) system;
config.allowUnfree = true;
};
import
(pkgs.applyPatches {
name = "nixpkgs-nixvim-doc";
src = pkgs.path;
patches = [ ./either_recursive.patch ];
})
{
inherit (pkgs) system;
config.allowUnfree = true;
};
inherit (pkgsDoc) lib;
@ -24,21 +25,21 @@
name = "<${repo}/${subpath}>";
};
transformOptions = opt:
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)))
else if decl == "lib/modules.nix"
then gitHubDeclaration "NixOS" "nixpkgs" "master" decl
else decl
)
opt.declarations;
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 {
@ -48,61 +49,51 @@
# Evaluation is irrelevant, only used for documentation.
};
topLevelModules =
[
../wrappers/modules/output.nix
# 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;
};
topLevelModules = [
../wrappers/modules/output.nix
# 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;
};
};
};
})
]
++ (rawModules pkgsDoc);
hmOptions =
builtins.removeAttrs
(lib.evalModules {
modules = [
(import ../wrappers/modules/hm.nix {inherit lib;})
];
};
})
.options
["_module"];
] ++ (rawModules pkgsDoc);
hmOptions = builtins.removeAttrs (lib.evalModules {
modules = [ (import ../wrappers/modules/hm.nix { inherit lib; }) ];
}).options [ "_module" ];
in
rec {
options-json =
(pkgsDoc.nixosOptionsDoc
{
inherit
(lib.evalModules {
modules = topLevelModules;
specialArgs.helpers = helpers;
})
options
;
inherit transformOptions;
warningsAreErrors = false;
rec {
options-json =
(pkgsDoc.nixosOptionsDoc {
inherit
(lib.evalModules {
modules = topLevelModules;
specialArgs.helpers = helpers;
})
.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 {
options
;
inherit transformOptions;
modules = topLevelModules;
inherit helpers hmOptions;
};
}
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;
};
}

View file

@ -4,7 +4,8 @@
installShellFiles,
nixos-render-docs,
pandoc,
}: let
}:
let
manualFilter = ''
local text = pandoc.text
@ -23,26 +24,34 @@
end
'';
manHeader = let
mkMDSection = file: "<(pandoc --lua-filter <(echo \"$manualFilter\") -f gfm -t man ${file})";
in
runCommand "nixvim-general-doc-manpage" {
nativeBuildInputs = [pandoc];
inherit manualFilter;
} ''
mkdir -p $out
cat \
${./nixvim-header-start.5} \
${mkMDSection ../user-guide/helpers.md} \
${mkMDSection ../user-guide/faq.md} \
${./nixvim-header-end.5} \
>$out/nixvim-header.5
'';
# FIXME add platform specific docs to manpage
manHeader =
let
mkMDSection = file: "<(pandoc --lua-filter <(echo \"$manualFilter\") -f gfm -t man ${file})";
in
runCommand "nixvim-general-doc-manpage"
{
nativeBuildInputs = [ pandoc ];
inherit manualFilter;
}
''
mkdir -p $out
cat \
${./nixvim-header-start.5} \
${mkMDSection ../user-guide/helpers.md} \
${mkMDSection ../user-guide/faq.md} \
${./nixvim-header-end.5} \
>$out/nixvim-header.5
'';
in
runCommand "nixvim-configuration-reference-manpage" {
nativeBuildInputs = [installShellFiles nixos-render-docs];
} ''
# FIXME add platform specific docs to manpage
runCommand "nixvim-configuration-reference-manpage"
{
nativeBuildInputs = [
installShellFiles
nixos-render-docs
];
}
''
# Generate man-pages
mkdir -p $out/share/man/man5
nixos-render-docs -j $NIX_BUILD_CORES options manpage \

View file

@ -7,22 +7,26 @@
transformOptions,
hmOptions,
}:
with lib; let
with lib;
let
options = lib.evalModules {
inherit modules;
specialArgs = {inherit pkgs lib helpers;};
specialArgs = {
inherit pkgs lib helpers;
};
};
inherit (options.config.meta) nixvimInfo;
mkMDDoc = options:
mkMDDoc =
options:
(nixosOptionsDoc {
inherit options transformOptions;
warningsAreErrors = false;
})
.optionsCommonMark;
}).optionsCommonMark;
removeUnwanted = attrs:
removeUnwanted =
attrs:
builtins.removeAttrs attrs [
"_module"
"_freeformOptions"
@ -31,215 +35,199 @@ with lib; let
"content"
];
removeWhitespace = builtins.replaceStrings [" "] [""];
removeWhitespace = builtins.replaceStrings [ " " ] [ "" ];
getSubOptions = opts: path: removeUnwanted (opts.type.getSubOptions path);
isVisible = opts:
if isOption opts
then attrByPath ["visible"] true opts
else if opts.isOption
then attrByPath ["index" "options" "visible"] true opts
else let
filterFunc =
filterAttrs
(
_: v:
if isAttrs v
then isVisible v
else true
);
isVisible =
opts:
if isOption opts then
attrByPath [ "visible" ] true opts
else if opts.isOption then
attrByPath [
"index"
"options"
"visible"
] true opts
else
let
filterFunc = filterAttrs (_: v: if isAttrs v then isVisible v else true);
hasEmptyIndex = (filterFunc opts.index.options) == {};
hasEmptyComponents = (filterFunc opts.components) == {};
in
hasEmptyIndex = (filterFunc opts.index.options) == { };
hasEmptyComponents = (filterFunc opts.components) == { };
in
!hasEmptyIndex || !hasEmptyComponents;
wrapModule = path: opts: isOpt: rec {
index = {
options =
if isOpt
then opts
else filterAttrs (_: component: component.isOption && (isVisible component)) opts;
if isOpt then
opts
else
filterAttrs (_: component: component.isOption && (isVisible component)) opts;
path = removeWhitespace (concatStringsSep "/" path);
moduleDoc =
if builtins.length path >= 2 && lib.hasAttrByPath path nixvimInfo
then let
info = lib.getAttrFromPath path nixvimInfo;
maintainers = lib.unique (options.config.meta.maintainers.${info.file} or []);
maintainersNames = builtins.map (m: m.name) maintainers;
in
if builtins.length path >= 2 && lib.hasAttrByPath path nixvimInfo then
let
info = lib.getAttrFromPath path nixvimInfo;
maintainers = lib.unique (options.config.meta.maintainers.${info.file} or [ ]);
maintainersNames = builtins.map (m: m.name) maintainers;
in
"# ${lib.last path}\n\n"
+ (lib.optionalString (info.description != null) "${info.description}\n\n")
+ (lib.optionalString (info.url != null) "**Url:** [${info.url}](${info.url})\n\n")
+ (lib.optionalString (builtins.length maintainers > 0)
"**Maintainers:** ${lib.concatStringsSep ", " maintainersNames}\n\n")
else null;
+ (lib.optionalString (
builtins.length maintainers > 0
) "**Maintainers:** ${lib.concatStringsSep ", " maintainersNames}\n\n")
else
null;
};
components =
if isOpt
then {}
else filterAttrs (_: component: !component.isOption && (isVisible component)) opts;
if isOpt then
{ }
else
filterAttrs (_: component: !component.isOption && (isVisible component)) opts;
hasComponents = components != {};
hasComponents = components != { };
isOption = isOpt;
};
processModulesRec = modules: let
recurse = path: mods: let
g = name: opts:
if !isOption opts
then wrapModule (path ++ [name]) (recurse (path ++ [name]) opts) false
else let
subOpts = getSubOptions opts (path ++ [name]);
processModulesRec =
modules:
let
recurse =
path: mods:
let
g =
name: opts:
if !isOption opts then
wrapModule (path ++ [ name ]) (recurse (path ++ [ name ]) opts) false
else
let
subOpts = getSubOptions opts (path ++ [ name ]);
in
if subOpts != { } then
wrapModule (path ++ [ name ]) (
(recurse (path ++ [ name ]) subOpts)
// {
# This is necessary to include the submodule option's definition in the docs (description, type, etc.)
# For instance, this helps submodules like "autoCmd" to include their base definitions and examples in the docs
# Though there might be a better, less "hacky" solution than this.
${name} = recursiveUpdate opts {
isOption = true;
type.getSubOptions = _: _: { }; # Used to exclude suboptions from the submodule definition itself
};
}
) false
else
wrapModule (path ++ [ name ]) opts true;
in
if subOpts != {}
then
wrapModule
(path ++ [name])
(
(recurse (path ++ [name]) subOpts)
// {
# This is necessary to include the submodule option's definition in the docs (description, type, etc.)
# For instance, this helps submodules like "autoCmd" to include their base definitions and examples in the docs
# Though there might be a better, less "hacky" solution than this.
${name} = recursiveUpdate opts {
isOption = true;
type.getSubOptions = _: _: {}; # Used to exclude suboptions from the submodule definition itself
};
}
)
false
else wrapModule (path ++ [name]) opts true;
mapAttrs g mods;
in
mapAttrs g mods;
in
foldlAttrs
(
acc: name: opts: let
group =
if !opts.hasComponents
then "Neovim Options"
else "none";
foldlAttrs (
acc: name: opts:
let
group = if !opts.hasComponents then "Neovim Options" else "none";
last =
acc.${group}
or {
acc.${group} or {
index = {
options = {};
options = { };
path = removeWhitespace "${group}";
moduleDoc = null;
};
components = {};
components = { };
isGroup = true;
hasComponents = false;
};
isOpt = !opts.hasComponents && (isOption opts.index.options);
in
acc
// {
${group} = recursiveUpdate last {
index.options = optionalAttrs isOpt {
${name} = opts.index.options;
};
acc
// {
${group} = recursiveUpdate last {
index.options = optionalAttrs isOpt { ${name} = opts.index.options; };
components = optionalAttrs (!isOpt) {
${name} = recursiveUpdate opts {
index.path =
removeWhitespace
(
concatStringsSep "/"
(
(optional (group != "none") group) ++ [opts.index.path]
)
);
hasComponents = true;
};
components = optionalAttrs (!isOpt) {
${name} = recursiveUpdate opts {
index.path = removeWhitespace (
concatStringsSep "/" ((optional (group != "none") group) ++ [ opts.index.path ])
);
hasComponents = true;
};
hasComponents = last.components != {};
};
}
)
{}
(recurse [] modules);
mapModulesToString = f: modules: let
recurse = mods: let
g = name: opts:
if (opts ? "isGroup")
then
if name != "none"
then (f name opts) + ("\n" + recurse opts.components)
else recurse opts.components
else if opts.hasComponents
then (f name opts) + ("\n" + recurse opts.components)
else f name opts;
hasComponents = last.components != { };
};
}
) { } (recurse [ ] modules);
mapModulesToString =
f: modules:
let
recurse =
mods:
let
g =
name: opts:
if (opts ? "isGroup") then
if name != "none" then (f name opts) + ("\n" + recurse opts.components) else recurse opts.components
else if opts.hasComponents then
(f name opts) + ("\n" + recurse opts.components)
else
f name opts;
in
concatStringsSep "\n" (mapAttrsToList g mods);
in
concatStringsSep "\n" (mapAttrsToList g mods);
in
recurse modules;
docs = rec {
modules = processModulesRec (removeUnwanted options.options);
commands =
mapModulesToString
(
name: opts: let
isBranch =
if (hasSuffix "index" opts.index.path)
then true
else opts.hasComponents;
path =
if isBranch
then "${opts.index.path}/index.md"
else "${opts.index.path}.md";
in
(optionalString isBranch
"mkdir -p ${opts.index.path}\n")
+ (
if opts.index.moduleDoc == null
then "cp ${mkMDDoc opts.index.options} ${path}"
else
# Including moduleDoc's text directly will result in bash interpreting special chars,
# write it to the nix store and `cat` the file instead.
''
{
cat ${pkgs.writeText "module-doc" opts.index.moduleDoc}
cat ${mkMDDoc opts.index.options}
} > ${path}
''
)
commands = mapModulesToString (
name: opts:
let
isBranch = if (hasSuffix "index" opts.index.path) then true else opts.hasComponents;
path = if isBranch then "${opts.index.path}/index.md" else "${opts.index.path}.md";
in
(optionalString isBranch "mkdir -p ${opts.index.path}\n")
+ (
if opts.index.moduleDoc == null then
"cp ${mkMDDoc opts.index.options} ${path}"
else
# Including moduleDoc's text directly will result in bash interpreting special chars,
# write it to the nix store and `cat` the file instead.
''
{
cat ${pkgs.writeText "module-doc" opts.index.moduleDoc}
cat ${mkMDDoc opts.index.options}
} > ${path}
''
)
modules;
) modules;
};
mdbook = {
nixvimOptions =
mapModulesToString
(
name: opts: let
isBranch =
if name == "index"
then true
else opts.hasComponents && opts.index.options != {};
nixvimOptions = mapModulesToString (
name: opts:
let
isBranch = if name == "index" then true else opts.hasComponents && opts.index.options != { };
path =
if isBranch
then "${opts.index.path}/index.md"
else if !opts.hasComponents
then "${opts.index.path}.md"
else "";
path =
if isBranch then
"${opts.index.path}/index.md"
else if !opts.hasComponents then
"${opts.index.path}.md"
else
"";
indentLevel = with builtins; length (filter isString (split "/" opts.index.path)) - 1;
indentLevel = with builtins; length (filter isString (split "/" opts.index.path)) - 1;
padding = concatStrings (builtins.genList (_: "\t") indentLevel);
in "${padding}- [${name}](${path})"
)
docs.modules;
padding = concatStrings (builtins.genList (_: "\t") indentLevel);
in
"${padding}- [${name}](${path})"
) docs.modules;
};
prepareMD = ''
@ -262,19 +250,23 @@ with lib; let
--replace-fail "@HM_OPTIONS@" "$(cat ${mkMDDoc hmOptions})"
'';
in
pkgs.stdenv.mkDerivation {
name = "nixvim-docs";
pkgs.stdenv.mkDerivation {
name = "nixvim-docs";
phases = ["buildPhase"];
phases = [ "buildPhase" ];
buildInputs = [pkgs.mdbook];
inputs = sourceFilesBySuffices ./. [".md" ".toml" ".js"];
buildInputs = [ pkgs.mdbook ];
inputs = sourceFilesBySuffices ./. [
".md"
".toml"
".js"
];
buildPhase = ''
dest=$out/share/doc
mkdir -p $dest
${prepareMD}
mdbook build
cp -r ./book/* $dest
'';
}
buildPhase = ''
dest=$out/share/doc
mkdir -p $dest
${prepareMD}
mdbook build
cp -r ./book/* $dest
'';
}