_nix-install_completion() { local -a options 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))' '-p[LUKS password file to use for encryption]:password_file:_files' '-c[Copy configuration to target]' '-r[Reboot after completion]' ) _list_hosts() { 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() { 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