29 lines
823 B
Bash
29 lines
823 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))'
|
|
'-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/secrets" ]]; then
|
|
find "$flake/secrets" -type f -name 'key.txt' | sed -E 's|^.*/secrets/([^/]+)/key.txt$|\1|' | sort -u
|
|
fi
|
|
}
|
|
|
|
_arguments -s $options
|
|
}
|
|
|
|
compdef _nix-install_completion nix-install
|