2024-09-04 16:22:17 +01:00
|
|
|
{
|
|
|
|
lib,
|
2024-09-15 18:02:54 +01:00
|
|
|
nixvimConfiguration,
|
2024-09-04 16:22:17 +01:00
|
|
|
linkFarmFromDrvs,
|
2024-12-31 22:22:44 +01:00
|
|
|
runCommandLocal,
|
2024-09-04 16:22:17 +01:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
by-name = ../plugins/by-name;
|
2024-09-15 18:02:54 +01:00
|
|
|
options = lib.collect lib.isOption nixvimConfiguration.options;
|
2024-09-04 16:22:17 +01:00
|
|
|
|
|
|
|
# Option namespaces that we allow by-name plugins to declare
|
|
|
|
knownPluginNamespaces = [
|
|
|
|
"colorschemes"
|
|
|
|
"plugins"
|
|
|
|
];
|
|
|
|
|
|
|
|
# Group by-name children by filetype; "regular", "directory", "symlink" and "unknown".
|
|
|
|
children =
|
|
|
|
let
|
|
|
|
apply =
|
|
|
|
prev: name: type:
|
|
|
|
prev // { ${type} = prev.${type} ++ [ name ]; };
|
|
|
|
|
|
|
|
nil = {
|
|
|
|
regular = [ ];
|
|
|
|
directory = [ ];
|
|
|
|
symlink = [ ];
|
|
|
|
unknown = [ ];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
lib.foldlAttrs apply nil (builtins.readDir by-name);
|
|
|
|
|
|
|
|
# Find plugins by looking for `*.*.enable` options that are declared in `plugins/by-name`
|
|
|
|
by-name-enable-opts =
|
|
|
|
let
|
|
|
|
regex = ''/nix/store/[^/]+/plugins/by-name/(.*)'';
|
|
|
|
optionalPair =
|
|
|
|
opt: file:
|
|
|
|
let
|
|
|
|
result = builtins.match regex file;
|
|
|
|
in
|
|
|
|
lib.optional (result != null) {
|
|
|
|
# Use the file name relative to `plugins/by-name/`
|
|
|
|
name = builtins.head result;
|
|
|
|
# Use only the first two parts of the option location
|
|
|
|
value = lib.genList (builtins.elemAt opt.loc) 2;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
lib.pipe options [
|
|
|
|
(builtins.filter (opt: builtins.length opt.loc == 3 && lib.last opt.loc == "enable"))
|
|
|
|
(builtins.concatMap (opt: (builtins.concatMap (optionalPair opt) opt.declarations)))
|
|
|
|
builtins.listToAttrs
|
|
|
|
];
|
|
|
|
in
|
|
|
|
linkFarmFromDrvs "plugins-by-name" [
|
|
|
|
# Ensures all files matching `plugins/by-name/*` are directories
|
2024-12-31 22:22:44 +01:00
|
|
|
(runCommandLocal "file-types"
|
2024-09-04 16:22:17 +01:00
|
|
|
{
|
|
|
|
__structuredAttrs = true;
|
|
|
|
inherit (children) regular symlink unknown;
|
|
|
|
}
|
|
|
|
''
|
|
|
|
declare -i errs=0
|
|
|
|
|
|
|
|
showErrs() {
|
|
|
|
type="$1"
|
|
|
|
shift
|
|
|
|
|
|
|
|
if (( $# > 0 )); then
|
|
|
|
((++errs))
|
|
|
|
echo "Unexpected $type in plugins/by-name ($#):"
|
|
|
|
for f in "$@"; do
|
|
|
|
echo " - $f"
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
showErrs 'symlinks' "''${symlink[@]}"
|
|
|
|
showErrs 'regular files' "''${regular[@]}"
|
|
|
|
showErrs 'unknown-type files' "''${unknown[@]}"
|
|
|
|
|
|
|
|
if (( $errs > 0 )); then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
touch $out
|
|
|
|
''
|
|
|
|
)
|
|
|
|
|
2024-09-07 00:03:04 +01:00
|
|
|
# Check default.nix files exist for each directory
|
2024-12-31 22:22:44 +01:00
|
|
|
(runCommandLocal "default-nix-exists"
|
2024-09-07 00:03:04 +01:00
|
|
|
{
|
|
|
|
__structuredAttrs = true;
|
|
|
|
missingPlugins = builtins.filter (
|
|
|
|
name: !(builtins.pathExists "${by-name}/${name}/default.nix")
|
|
|
|
) children.directory;
|
|
|
|
missingTests = builtins.filter (
|
|
|
|
name: !(builtins.pathExists "${./test-sources/plugins/by-name}/${name}/default.nix")
|
|
|
|
) children.directory;
|
|
|
|
}
|
|
|
|
''
|
|
|
|
declare -i errs=0
|
|
|
|
|
|
|
|
if (( ''${#missingPlugins[@]} > 0 )); then
|
|
|
|
((++errs))
|
|
|
|
echo "The following (''${#missingPlugins[@]}) directories do not have a default.nix file:"
|
|
|
|
for name in "''${missingPlugins[@]}"; do
|
|
|
|
echo " - plugins/by-name/$name"
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
|
|
|
|
if (( ''${#missingTests[@]} > 0 )); then
|
|
|
|
((++errs))
|
|
|
|
echo "The following (''${#missingTests[@]}) test files do not exist:"
|
|
|
|
for name in "''${missingTests[@]}"; do
|
|
|
|
echo " - tests/test-sources/plugins/by-name/$name/default.nix"
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
|
|
|
|
if (( $errs > 0 )); then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
touch $out
|
|
|
|
''
|
|
|
|
)
|
|
|
|
|
2024-09-04 16:22:17 +01:00
|
|
|
# Ensures all plugin enable options are declared in a directory matching the plugin name
|
2024-12-31 22:22:44 +01:00
|
|
|
(runCommandLocal "mismatched-plugin-names"
|
2024-09-04 16:22:17 +01:00
|
|
|
{
|
|
|
|
__structuredAttrs = true;
|
|
|
|
|
|
|
|
options = lib.pipe by-name-enable-opts [
|
|
|
|
(lib.filterAttrs (file: loc: file != lib.last loc))
|
|
|
|
(lib.mapAttrs (file: loc: lib.showOption loc))
|
|
|
|
];
|
|
|
|
|
|
|
|
passthru = {
|
2024-09-15 18:02:54 +01:00
|
|
|
inherit nixvimConfiguration;
|
2024-09-04 16:22:17 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
''
|
|
|
|
if (( ''${#options[@]} > 0 )); then
|
|
|
|
echo "Found plugin modules with mismatched option & directory names (''${#options[@]})"
|
|
|
|
for file in "''${!options[@]}"; do
|
|
|
|
echo "- ''${options[$file]} is declared in '$file'"
|
|
|
|
done
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
touch $out
|
|
|
|
''
|
|
|
|
)
|
|
|
|
|
|
|
|
# Ensure all plugin enable option are declared under an expected namespace
|
2024-12-31 22:22:44 +01:00
|
|
|
(runCommandLocal "unknown-plugin-namespaces"
|
2024-09-04 16:22:17 +01:00
|
|
|
{
|
|
|
|
__structuredAttrs = true;
|
|
|
|
|
|
|
|
# I'm sorry, I couldn't help implementing oxford-comma...
|
|
|
|
expected =
|
|
|
|
let
|
|
|
|
len = builtins.length knownPluginNamespaces;
|
|
|
|
in
|
|
|
|
lib.concatImapStringsSep ", " (
|
|
|
|
i: str: lib.optionalString (i > 1 && i == len) "or " + "`${str}`"
|
|
|
|
) knownPluginNamespaces;
|
|
|
|
|
|
|
|
options = lib.pipe by-name-enable-opts [
|
|
|
|
(lib.filterAttrs (file: loc: !(builtins.elem (builtins.head loc) knownPluginNamespaces)))
|
|
|
|
(lib.mapAttrs (file: loc: "`${lib.showOption loc}`"))
|
|
|
|
];
|
|
|
|
|
|
|
|
passthru = {
|
2024-09-15 18:02:54 +01:00
|
|
|
inherit nixvimConfiguration;
|
2024-09-04 16:22:17 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
''
|
|
|
|
if (( ''${#options[@]} > 0 )); then
|
|
|
|
echo "Found plugin modules with unknown option namespaces (''${#options[@]})"
|
|
|
|
echo "Expected all plugins to be scoped as $expected"
|
|
|
|
for file in "''${!options[@]}"; do
|
|
|
|
echo "- ''${options[$file]} is declared in '$file'"
|
|
|
|
done
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
touch $out
|
|
|
|
''
|
|
|
|
)
|
|
|
|
]
|