fix module

This commit is contained in:
atagen 2026-03-23 13:15:50 +11:00
parent f2d0a42fd7
commit c2c8b32305
2 changed files with 63 additions and 98 deletions

View file

@ -30,57 +30,45 @@ in
package = lib.mkOption {
type = lib.types.package;
description = "The inshellah package to use for indexing completions.";
description = "package to use for indexing completions";
};
completionsPath = lib.mkOption {
type = lib.types.str;
default = "/share/inshellah";
description = ''
Subdirectory within the merged environment where completion files
are placed. Used as the system-dir for the completer.
subdirectory within the system profile where completion files
are placed. used as --system-dir for the completer.
'';
};
ignoreCommands = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [];
example = [ "meat" "problematic-tool" ];
default = [ ];
example = [ "problematic-tool" ];
description = ''
List of command names to skip during completion indexing.
list of command names to skip during completion indexing
'';
};
snippet = lib.mkOption {
type = lib.types.str;
readOnly = true;
};
};
config = lib.mkIf cfg.enable {
environment.pathsToLink = [ cfg.completionsPath ];
envionrment.systemPackages = [ config.programs.inshellah.package ];
environment.extraSetup =
let
inshellah = "${cfg.package}/bin/inshellah";
destDir = "$out${cfg.completionsPath}";
segments = lib.filter (s: s != "") (lib.splitString "/" cfg.completionsPath);
derefPath = lib.concatMapStringsSep "\n " (seg: ''
_cur="$_cur/${seg}"
if [ -L "$_cur" ]; then
_target=$(readlink "$_cur")
rm "$_cur"
mkdir -p "$_cur"
if [ -d "$_target" ]; then
cp -rT "$_target" "$_cur"
chmod -R u+w "$_cur"
fi
fi'') segments;
ignoreFile = pkgs.writeText "inshellah-ignore" (lib.concatStringsSep "\n" cfg.ignoreCommands);
ignoreFlag = lib.optionalString (cfg.ignoreCommands != []) " --ignore ${ignoreFile}";
ignoreFlag = lib.optionalString (cfg.ignoreCommands != [ ]) " --ignore ${ignoreFile}";
in
''
_cur="$out"
${derefPath}
mkdir -p ${destDir}
# Index completions in one pass:
# native generators > manpages > --help fallback
if [ -d "$out/bin" ] && [ -d "$out/share/man" ]; then
${inshellah} index "$out" --dir ${destDir}${ignoreFlag} \
2>/dev/null || true