nix: ensure argv0 is correct when generating completions

This commit is contained in:
2025-12-03 16:25:26 +09:00
parent 3d7cf66648
commit da2358353f

View File

@@ -24,9 +24,12 @@ buildFunction {
nativeBuildInputs = [ installShellFiles ];
postInstall = let
# "$out/bin/${mainProgram}" generate-completions --shell "${shell}" --command "${command}" > "$TMP/muscl.${shell}"
commands = lib.mapCartesianProduct ({ shell, command }: ''
COMPLETE=${shell} "$out/bin/${command}" > "$TMP/${command}.${shell}"
installShellCompletions = lib.mapCartesianProduct ({ shell, command }: ''
(
export PATH="$out/bin:$PATH"
export COMPLETE="${shell}"
"${command}" > "$TMP/${command}.${shell}"
)
installShellCompletion "--${shell}" --cmd "${command}" "$TMP/${command}.${shell}"
'') {
shell = [ "bash" "zsh" "fish" ];
@@ -35,7 +38,9 @@ buildFunction {
in ''
ln -sr "$out/bin/muscl" "$out/bin/mysql-dbadm"
ln -sr "$out/bin/muscl" "$out/bin/mysql-useradm"
'' + lib.concatStringsSep "\n" commands + ''
${lib.concatStringsSep "\n" installShellCompletions}
install -Dm444 assets/systemd/muscl.socket -t "$out/lib/systemd/system"
install -Dm644 assets/systemd/muscl.service -t "$out/lib/systemd/system"
substituteInPlace "$out/lib/systemd/system/muscl.service" \