Files
nix/hosts/common/configs/system/nix-install/install.completion.zsh
2025-09-01 14:37:59 +01:00

30 lines
932 B
Bash

_nix-install_completion() {
local options=(
'1:flake:_directories'
'-m[Mode: 'install' or 'repair']:mode:(install repair)'
'-h[Host to configure]:host:($(_list_hosts))'
'-k[Key file to copy to user config]:key:($(_list_keys))'
'-s[Enroll secure boot keys on current device]'
'-c[Copy configuration to target]'
'-r[Reboot after completion]'
)
_list_hosts() {
local flake="$(realpath ${words[2]})"
if [[ -f "$flake/flake.nix" ]]; then
nix flake show --quiet --json "$flake" 2>/dev/null | jq -r '.nixosConfigurations | keys[]'
fi
}
_list_keys() {
local flake="$(realpath ${words[2]})"
if [[ -d "$flake/submodules/secrets/domains" ]]; then
find "$flake/submodules/secrets/domains" -type f -name 'key.txt' | sed -E 's|^.*/submodules/secrets/domains/([^/]+)/key.txt$|\1|' | sort -u
fi
}
_arguments -s $options
}
compdef _nix-install_completion nix-install