ci/eval: add rebuildsByPlatform to the comparison result (#363751)
[NixPkgs.git] / pkgs / os-specific / linux / nixos-rebuild / _nixos-rebuild
blob31e23136528d4ff7d00bf982403b99573f7017aa
1 #!/usr/bin/env bash
3 # We're faking a `nix build` command-line to re-use Nix's own completion
4 # for the few options passed through to Nix.
5 _nixos-rebuild_pretend-nix() {
6 COMP_LINE="nix build ${COMP_LINE}"
7 # number of prepended chars
8 (( COMP_POINT = COMP_POINT + 10))
10 COMP_WORDS=(
11 nix build
12 "${COMP_WORDS[@]}"
14 # Add the amount of prepended words
15 (( COMP_CWORD = COMP_CWORD + 2))
16 _complete_nix "nix"
19 _nixos-rebuild() {
20 local curr="$2"
21 local prev="$3"
22 local subcommandGiven=0
23 local word
24 local subcommand
26 __load_completion nix
28 # Arrays are re-ordered by the completion, so it's fine to sort them in logical chunks
29 local all_args=(
30 --verbose -v
32 # nixos-rebuild options
33 --fast
34 --no-build-nix
35 --profile-name -p # name
36 --rollback
37 --specialisation -c # name
38 --use-remote-sudo
39 --no-ssh-tty
40 --build-host # host
41 --target-host # host
42 # Used with list-generations
43 --json
45 # generation switching options
46 --install-bootloader
48 # nix-channel options
49 --upgrade
50 --upgrade-all
52 # flakes options
53 --commit-lock-file
54 --flake # flake-uri
55 --override-input # input-name flake-uri
56 --recreate-lock-file
57 --update-input
58 --no-flake
59 --no-registries
60 --no-update-lock-file
61 --no-write-lock-file
63 # Nix-copy options
64 --use-substitutes --substitute-on-destination -s
66 # Nix options
67 --option
68 --impure
69 --builders # builder-spec
70 --show-trace
71 --keep-failed -K
72 --keep-going -k
73 --max-jobs -j # number
74 --log-format # format
75 -I # NIX_PATH
78 local all_subcommands=(
79 boot
80 build
81 build-vm
82 build-vm-with-bootloader
83 dry-activate
84 dry-build
85 edit
86 list-generations
87 switch
88 test
91 # Suggest arguments that can be consumed under some conditions only
92 for word in "${COMP_WORDS[@]}"; do
93 for subcommand in "${all_subcommands[@]}"; do
94 if [[ "$word" == "$subcommand" ]]; then
95 subcommandGiven=1
97 done
98 done
100 # Fake out a way to complete the second arg to some options
101 case "${COMP_WORDS[COMP_CWORD-2]}" in
102 "--override-input")
103 prev="--override-input_2"
105 "--option")
106 prev="--option_2"
108 esac
110 case "$prev" in
111 --max-jobs|-j)
112 COMPREPLY=( )
115 --profile-name|-p)
116 if [[ "$curr" == "" ]]; then
117 COMPREPLY=( /nix/var/nix/profiles/* )
118 else
119 COMPREPLY=( "$curr"* )
123 --build-host|--target-host|-t|-h)
124 _known_hosts_real "$curr"
127 --specialisation|-c)
128 COMPREPLY=()
132 _nixos-rebuild_pretend-nix
134 --builders)
135 _nixos-rebuild_pretend-nix
137 --flake)
138 _nixos-rebuild_pretend-nix
140 --override-input)
141 _nixos-rebuild_pretend-nix
143 --override-input_2)
144 _nixos-rebuild_pretend-nix
146 --log-format)
147 _nixos-rebuild_pretend-nix
149 --option)
150 _nixos-rebuild_pretend-nix
152 --option_2)
153 _nixos-rebuild_pretend-nix
157 if [[ "$curr" == -* ]] || (( subcommandGiven )); then
158 COMPREPLY=( $(compgen -W "${all_args[*]}" -- "$2") )
159 else
160 COMPREPLY=( $(compgen -W "${all_subcommands[*]}" -- "$2") )
163 esac
166 complete -F _nixos-rebuild nixos-rebuild