#compdef nix-channel
#autoload

local context state state_descr line
typeset -A opt_args

_nix-common-options

_arguments \
  '(- *)--add[Subscribe to a channel]:Channel URL:_urls::Channel Name:( )'\
  '(- *)--remove[Unsubscribe from a channel]:Channel Name:->nix_channels'\
  '(- *)--list[List subscribed channels]'\
  '(- *)--update[Update and activate channels]:Channel Name:->nix_channels'\
  '(- *)--rollback[Revert the previous nix-channel --update]'

case $state in
    nix-channels)
        local -a channels=(${${(f)"$(nix-channel --list)"}%% *})
        _values 'Nix Channels' ${channels}
esac