J7MW6ZYFKISU4ZRTEJZWZ5GY42EB2L6O5OSWVNZ2HNXPF4LHVASAC ZERMM5MUM6JLYFSVV3CXGYPMNAJSUKM265FCZDNZISEUH7XY2SUAC RXCY7LD6ZRIOIKZEYKLMCYPMQPXF4DOEEFBDLVR2B22BXLZJFFBQC A3TVGLVHSVLMEHLHB3TPBSD3QGNVGX3DIK6BEBDTTHWBNW4ALMRAC UIXIJMKKE7STQ65EALHSRFO7J64YCRPRQOQRAX7FJ27455W4X3WAC IOVPOFAVXEQIZ7BCFVVAWFW3RYFXPK2GOILDWA6N6QHQHLAJ4XTAC 7XDDBWIHI2COD5CEUUTJUPHH24ZYCTZDIMXUXNKZZTUDGMADO6HAC JTRP2ARQSAGWARGV5IBBXE3QBEAB4HUUXAV6EVOGNCZZAMDWUOSQC BTKV63XMOYQMYINDWLI6G7MYYJCLRX7UEDH7Y5X5WJVKWO2IZVMQC 5FLRDDUAB7NCOKJKK57IVQBETGX7JTT7GVKFT46ORSZ7OJ7Q2UFQC BF27BSQ5ZOD342GPS7NDCFRRJ2JPAYAX26TZHGJOV2T5BWW6H75AC RXWXT4IQ4JGRLN6CAYSDZFKUMNZNAKCATUQBUAYCGIYLVKASU6PAC LLYVKGN7DJCTBROIXC2RIEKXPEPN2J63F3FPXZRHOXKKXJEAT72AC NT73J6RN2BBIN2QY3N5VY42BXOLFKWEOYWPX7QGNKTAWWYPJYE4QC TLDTHX24SHB5LCAPGU2PBXKQWSWTVMVIEPT6TRJKQK3YGOS74JZAC (comment(use-package org-brain :ensure t:init(setq org-brain-path "~/org-brain/"):config(eval-after-load 'evil'(evil-set-initial-state 'org-brain-visualize-mode 'emacs))(push '("B" "Brain" plain (function org-brain-goto-end)"* %i%?" :empty-lines 1)org-capture-templates)(setq org-id-track-globally torg-id-locations-file "~/.emacs.d/.org-id-locations"org-brain-visualize-default-choices 'allorg-brain-title-max-length 0)))
# Nix Installalias ni='nix-env -iA'# Nix Searchalias ns='nix-env -qaP'function prompt_nix_shell_precmd {if [[ ${IN_NIX_SHELL} -eq 1 ]] thenif [[ -n ${IN_WHICH_NIX_SHELL} ]] thenNIX_SHELL_NAME=": ${IN_WHICH_NIX_SHELL}"fiNIX_PROMPT="%F{8}[%F{3}nix-shell${NIX_SHELL_NAME}%F{8}]%f"if [[ $PROMPT != *"$NIX_PROMPT"* ]] thenPROMPT="$NIX_PROMPT $PROMPT"fifi}function prompt_nix_shell_setup {autoload -Uz add-zsh-hookadd-zsh-hook precmd prompt_nix_shell_precmd}prompt_nix_shell_setup "$@"
nix-zsh-completions.plugin.zsh
# Nix Installalias ni='nix-env -iA'# Nix Searchalias ns='nix-env -qaP'function prompt_nix_shell_precmd {if [[ -n ${IN_NIX_SHELL} && ${IN_NIX_SHELL} != "0" || ${IN_NIX_RUN} && ${IN_NIX_RUN} != "0" ]]; thenif [[ -n ${IN_WHICH_NIX_SHELL} ]] thenNIX_SHELL_NAME=": ${IN_WHICH_NIX_SHELL}"fiif [[ -n ${IN_NIX_SHELL} && ${IN_NIX_SHELL} != "0" ]]; thenNAME="nix-shell"elseNAME="nix-run"fiNIX_PROMPT="%F{8}[%F{3}${NAME}${NIX_SHELL_NAME}%F{8}]%f"if [[ $PROMPT != *"$NIX_PROMPT"* ]] thenPROMPT="$NIX_PROMPT $PROMPT"fifi}function prompt_nix_shell_setup {autoload -Uz add-zsh-hookadd-zsh-hook precmd prompt_nix_shell_precmd}# Add this to your zshrc if you want the prompt prefixed with `[nix-shell]`# when you're in a nix-shell environment.# prompt_nix_shell_setup "$@"
'(- *)'{--hash,--revision}'[Print only the git hash of the channel]'\
'(- *)'{--hash,--revision}'[Show the full SHA1 hash of the Git commit from which this configuration was built.]'\'--configuration-revision[Show the configuration revision if available.]'\'--json[Print a JSON representation of the versions of NixOS and the top-level configuration flake.]'
'switch:Build, activate, and update boot default'\'boot:Build and update boot default without activating'\'test:Build and activate without updating boot default'\'build:Build without activating or updating boot default'\'dry-build:Show what store paths would be built or downloaded without building'\'dry-activate:Build and show what changes would be performed by the activation'\'build-vm:Create a script which starts a VM with the built configuration'\
'switch:Build, activate, and update boot default''boot:Build and update boot default without activating''test:Build and activate without updating boot default''build:Build without activating or updating boot default''dry-build:Show what store paths would be built or downloaded without building''dry-activate:Build and show what changes would be performed by the activation''build-vm:Create a script which starts a VM with the built configuration'
#compdef nixos-option#autoload_nix-common-options # import _nix_attr_paths etc._nixos-option-opts() {local mods=if [[ -n "$NIX_PATH" && "$NIX_PATH" =~ "nixos-config=" ]]; thenmods="(import <nixos-config>)"filocal options='with import <nixpkgs/lib>;(evalModules {modules = import <nixpkgs/nixos/modules/module-list.nix> ++ [ '"$mods"' ];}).config'_nix_attr_paths $options}_arguments \$__nix_search_path_args \'--all[Print the values of all options.]' \':NixOS module options:_nixos-option-opts'
$_nix_search_path_args \'--root[Treat the given directory as the root of the NixOS installation]:Installation Root:_files -/'\
$__nix_search_path_args \'--root[Treat the given directory as the root of the NixOS installation]:Installation Root:_path_files -/'\
'--root[Directory to treat as root of filesystem]:Root directory:_files -/'\'--dir[Directory to write configuration files to (Default /etc/nixos)]:Output directory:_files -/'\
'--root[Directory to treat as root of filesystem]:Root directory:_path_files -/'\'--dir[Directory to write configuration files to (Default /etc/nixos)]:Output directory:_path_files -/'\
'--auto-start[Start the container immediately]'
'--auto-start[Start the container immediately]'\'--nixos-path[Path to <nixpkgs/nixos>]:Path:_files'\'--host-address[Host IP of the veth interface]:host address:'\'--local-address[IPv4 address assined to the interface in the container]:local address:'\'--bridge[Put the host-side of the veth-pair into the named bridge]:Bridge interface'\'--port[Port forwarding]:port forwarding'
local -a _1st_arguments_1st_arguments=({--realise,-r}':Build the specified store paths' \'--gc:Perform garbage collection on the Nix store' \'--delete:Delete store paths from the Nix store if it is safe to do so' \{--query,-q}':Display information about store paths' \'--add:Add paths to the Nix store' \'--verify:Verify the consistency of the Nix database and store' \'--verify-path:Compare the contents of each store path to the hashes stored in the database' \'--repair-path:Attempt to repair the specified paths by redownloading them' \'--dump:Produce a NAR file containing the contents of the given path' \'--restore:Unpack a NAR archive, read from stdin, to the given path' \'--export:Serialize the specified store paths to stdout in a format which can be imported' \'--import:Read searialized store paths from stdin and add them to the Nix store' \'--optimise:Find identical files in the Nix store and hardlink them together to reduce disk usage'\{--read-log,-l}':Print the build log of the specified store paths' \'--dump-db:Dump Nix database to stdout' \'--load-db:Read a dump of the Nix database' \'--print-env:Print the environment of a derivation as shell code' \'--query-failed-paths:Print out store paths which failed to build' \'--clear-failed-paths:Clear the "failed" state of the given store path' \)
local context state state_descr linetypeset -A opt_args
case "$words[1]" in--realise|-r)_arguments \$_nix_dry_run \'--ignore-unknown[Silently ignore non-derivation paths with no substitute]' \'*:Store Paths:_files';;--gc)_arguments \$_nix_gc_common \'--max-freed[Stop garbage collection once this many bytes has been freed]:Bytes:( )';;--delete)_arguments \'--ignore-liveness[Ignore reachability from roots]';;--query|-q)local -a _queries_queries=('--outputs:Print the output paths of the given store derivations' \{--requisites,-R}':Print the closure of the given store paths' \'--references:Print immediate dependencies of the given store paths' \'--referrers:Print store paths which refer to these paths' \'--referrers-closure:Print the closure under the referrers relation' \'--deriver:Print the deriver of the store paths' \'--graph:Print the references graph of the store paths in Graphviz format' \'--tree:Print the references graph of the store paths as an ASCII tree' \'--binding:Print the value of an attribute of the store derivations' \'--hash:Print the SHA-256 hash of the contents of the store paths' \'--size:Print the size in bytes of the contents of the store paths' \'--roots:Print the garbage collector roots that point to the store paths' \)
local -a cmd_arguments=($__nix_boilerplate_opts{--realise,-r}'[Build the specified store paths]''--serve[provide access to the nix store over stdin/stdout]''--gc[Perform garbage collection on the Nix store]''--delete[Delete store paths from the Nix store if it is safe to do so]'{--query,-q}'[Display information about store paths]''--add[Add paths to the Nix store]''--verify[Verify the consistency of the Nix database and store]''--verify-path[Compare the contents of each store path to the hashes stored in the database]''--repair-path[Attempt to repair the specified paths by redownloading them]''--dump[Produce a NAR file containing the contents of the given path]''--restore[Unpack a NAR archive, read from stdin, to the given path]''--export[Serialize the specified store paths to stdout in a format which can be imported]''--import[Read searialized store paths from stdin and add them to the Nix store]''--optimise[Find identical files in the Nix store and hardlink them together to reduce disk usage]'{--read-log,-l}'[Print the build log of the specified store paths]''--dump-db[Dump Nix database to stdout]''--load-db[Read a dump of the Nix database]''--print-env[Print the environment of a derivation as shell code]''--query-failed-paths[Print out store paths which failed to build]''--clear-failed-paths[Clear the "failed" state of the given store path]''--generate-binary-cache-key[generate an Ed25519 key pair to sign build outputs]:key-name::secret-key-file:_files:public-key-file:_files')
local -a _query_common_query_common=('(--use-output -u)'{--use-output,-u}'[Apply the query to the output path of any store derivations]' \'(--force-realise -f)'{--force-realise,-f}'[Realise each argument to the query first]' \)
# Common nix-store optionslocal -a common_opts=('*:Store Paths:_files'$__nix_repair$__nix_common_store_opts$__nix_common_nixos_rebuild$__nix_extra_build_opts)
if (( CURRENT == 2 )); then_describe -t commands "Query subcommands" _queriesreturnfi
local -a command_optionslocal optfor opt in $words; docase "$opt" in--realise|-[^-]#r[^-]#)command_options=($common_opts$__nix_store_realise_opts)break;;--serve)command_options=($common_opts'--write[allow writing to the nix store]')break;;--gc)command_options=($common_opts$__nix_gc_common'--max-freed[stop the gc after freeing n bytes]:bytes:')break;;--delete)command_options=($common_opts'--ignore-liveness[Ignore reachability from roots]')break;;--query|-[^-]#q[^-]#)command_options+=('(--use-output -u)'{--use-output,-u}'[Apply the query to the output path of any store derivations]''(--force-realise -f)'{--force-realise,-f}'[Realise each argument to the query first]')
case "$words[2]" in--requisites|-R)_arguments $_query_common \'--include-outputs[Also include the output paths of store derivations]' \'*: :_files';;*)_arguments $_query_common \'*: :_files';;esac
local suboptfor subopt in $words; docase "$subopt" in--requisites|-R)command_options+=($common_opts'--include-outputs[Also include the output paths of store derivations]')break;;--outputs|--references|--referrers|--referrers-closure|--deriver|-d|--graph|--tree|--binding|-b|--hash|--size|--roots)command_options+=($common_opts)break;;esacdone
;;--verify)_arguments \'--check-contents[Compute and validate the SHA-256 hash of each store item]' \'--repair[Attempt to repair invalid or missing paths by redownloading them]';;--dump-db|--load-db|--query-failed-paths)# Nothing to complete;;*)_arguments \'*: :_files';;
command_options+=(+ '(query_subcmds)''--outputs[Print the output paths of the given store derivations]'{--requisites,-R}'[Print the closure of the given store paths]''--references[Print immediate dependencies of the given store paths]''--referrers[Print store paths which refer to these paths]''--referrers-closure[Print the closure under the referrers relation]''--deriver[Print the deriver of the store paths]''--graph[Print the references graph of the store paths in Graphviz format]''--tree[Print the references graph of the store paths as an ASCII tree]'{--binding,-b}'[Print the value of an attribute of the store derivations]:name:''--hash[Print the SHA-256 hash of the contents of the store paths]''--size[Print the size in bytes of the contents of the store paths]''--roots[Print the garbage collector roots that point to the store paths]')break;;--verify)command_options=($common_opts'--check-contents[Compute and validate the SHA-256 hash of each store item]')break;;--add|--verify-path|--repair-path|--dump|--restore|--export|--read-log|-l|--print-env)command_options=($common_opts)break;;--dump-db|--load-db|--query-failed-paths|--optimise)# nothing to completereturn;;--[^-]*|-[^-]#)# Complete common options if the user has started writing something elsecommand_options=($common_opts);;
done_arguments -s \$command_options \+ '(main_options)' \$cmd_arguments && return 0
local -a _nix_shell_opts_nix_shell_opts=('--command[Run a command instead of starting an interactive shell]:Command:_command_names' \'--exclude[Do not build any dependencies which match this regex]:Regex:( )' \'--pure[Clear the environment before starting the interactive shell]' \'(--packages -p)'{--packages,-p}'[Set up an environment where the given packages are present]:*:Packages: _nix_attr_paths "<nixpkgs>"' \
local -a _nix_shell_opts=('--command[Run a command instead of starting an interactive shell]:Command:_command_names''--exclude[Do not build any dependencies which match this regex]:Regex:( )''--pure[Clear the environment before starting the interactive shell]''--run[Run a command in a non-interactive shell instead of starting an interactive shell]:Command:_command_names''*'{--attr,-A}"[setup a build shell for package]:package:_nix_complete_attr_paths"
'--type[Use the specified cryptographic hash algorithm]:Hash Algorithm:(md5 sha1 sha256)'\'1:URL:_urls'\
$__nix_search_path_args \'--unpack[Unpack tarball/zip first]'\'--print-path[Print the resulting store path]'\'--type[Use the specified hash algorithm]:Hash Algorithm:(md5 sha1 sha256 sha512)'\'--name[Override the resulting nix store filename]:nix store filename:'\'*'{--attr,-A}'[Fetch the src of derivation (eg. mpv.src)]:src (eg. mpv.src): _nix_complete_attr_paths'\'1:URL or a local nix file:_resource'\
$_nix_boilerplate_opts \$_nix_common_opts \
- regular \$__nix_boilerplate_opts \$__nix_common_opts \$__nix_common_store_opts \$__nix_expr_opts \'*'{--attr,-A}'[build a .drv from file (default: ./default.nix)]:package:_nix_complete_attr_paths' \
'*:File to instantiate (default\: ./default.nix):_nix_path' \- find-file \"--find-file[Look up the given files on Nix's search path]:*:Lookup file using <...> logic:"\
{--install,-i}":Install package"\{--upgrade,-u}":Upgrade package"\{--uninstall,-e}":Uninstall package"\"--set-flag:Modify meta attribute of installed package"\{--query,-q}":List information about derivations"\{--switch-profile,-S}":Set the current profile path"\"--list-generations:Print a list of all generations in the active profile"\"--delete-generations:Delete specified generations"\{--switch-generation,-G}":Activate specified generation"\"--rollback:Switch to the previous generation of active profile")
{--install,-i}"[Install package]"{--upgrade,-u}"[Upgrade package]"{--uninstall,-e}"[Uninstall package]"--set-flag'[Modify meta attribute of installed package]:Name:->flag_name:Value:->flag_value:*:Packages: _nix_installed_packages'{--query,-q}"[List information about derivations]"{--switch-profile,-S}"[Set the current profile path]""--list-generations[Print a list of all generations in the active profile]""--delete-generations[Delete specified generations]"{--switch-generation,-G}"[Activate specified generation]""--rollback[Switch to the previous generation of active profile]")
local -a _nix_env_common_opts_nix_env_common_opts=($_nix_common_opts \'(--file -f)'{--file,-f}'[Specify Nix expression used to obtain derivations]:Path to file:_nix_path'\'(--profile -p)'{--profile,-p}'[Specify the profile to use]:Path:_nix_profiles'\$_nix_dry_run \'--system-filter[Only show derivations matching the specified platform]:system:_nix_systems'\
local -a _nix_env_common_opts=($__nix_common_opts'(--profile -p)'{--profile,-p}'[Specify the profile to use]:Path:_nix_profiles'$__nix_dry_run'--system-filter[Only show derivations matching the specified platform]:system:_nix_systems'
case "$words[1]" in--install|-[^-]#i[^-]#)_arguments -s \$_nix_env_common_opts \$_nix_env_b \$_nix_env_from_profile \'(--preserve-installed -P)'{--preserve-installed,-P}'[Do not remove derivations with the same name]' \'(--remove-all -r)'{--remove-all,-r}'[Remove all previously installed packages prior to installing]' \'*:Package:{if $expect_attr_paths; then _nix_attr_paths ; fi}'\;;--upgrade|-[^-]#u[^-]#)_arguments -s $_nix_env_common_opts \$_nix_env_b \$_nix_env_from_profile \'(-lt -leq -eq --always)--lt[Upgrade derivations with newer versions (default)]' \'(-lt -leq -eq --always)--leq[Upgrade derivations with the same or newer version]' \'(-lt -leq -eq --always)--eq[Upgrade derivations with equivalent versions]' \'(-lt -leq -eq --always)--always[Upgrade even if version number decreases]' \'*:Packages:_nix_installed_packages';;--uninstall|-[^-]#e[^-]#)_arguments -s '*::Packages:_nix_installed_packages';;--set-flag)_set_flag_attrs=('priority:Resolve package name conflicts' \'keep:Prevent package from being upgraded' \'active:Package is symlinked to profile' \)
local -a command_options=()# Look for a main option in the input and setup command_options appropriatelyfor opt in $words; docase "$opt" in--install|-[^-]#i[^-]#)command_options=($_nix_env_common_opts'(--attr -A)'{--attr,-A}'[Specify packages by attribute path instead of name]'$_nix_env_b$_nix_env_from_profile'(--preserve-installed -P)'{--preserve-installed,-P}'[Do not remove derivations with the same name]''(--remove-all -r)'{--remove-all,-r}'[Remove all previously installed packages prior to installing]''*:Package:{if $expect_attr_paths; then_nix_complete_attr_paths;else_nix_installed_packages "(use -A/--attr to access all packages)"fi}')break;;--upgrade|-[^-]#u[^-]#)command_options=($_nix_env_common_opts$_nix_env_b$_nix_env_from_profile'(-lt -leq -eq --always)--lt[Upgrade derivations with newer versions (default)]''(-lt -leq -eq --always)--leq[Upgrade derivations with the same or newer version]''(-lt -leq -eq --always)--eq[Upgrade derivations with equivalent versions]''(-lt -leq -eq --always)--always[Upgrade even if version number decreases]''*:Packages: _nix_installed_packages')break;;--uninstall|-[^-]#e[^-]#)command_options=(${_nix_env_common_opts:#'(--attr -A)'*}'*::Packages: _nix_installed_packages')break;;--set-flag)break;;--query|-[^-]#q[^-]#)command_options=($_nix_env_common_opts'(--available -a)'{--available,-a}'[display all installable derivations]'$_nix_env_b'(--status -s)'{--status,-s}'[print status of derivation]''(--attr-path -P)'{--attr-path,-P}'[print attribute path of derivations]''--no-name[suppress printing of name attribute]''(--compare-versions -c)'{--compare-versions,-c}'[compare installed and available version]''--system[print system attribute]''--drv-path[print store derivation path]''--out-path[print output path]''--description[print description]''--xml[print output as xml]''--json[print output as json]''--meta[Print all meta attributes: only available with --xml]')break;;--switch-profile|-[^-]#S[^-]#)command_options=($_nix_env_common_opts ':Profile:_nix_profiles')break;;--delete-generations)command_options=($_nix_env_common_opts '*::Generations:_nix_generations')break;;--switch-generation|-[^-]#G[^-]#)command_options=($_nix_env_common_opts '::Generations:_nix_generations')break;;--list-generations)command_options=($_nix_env_common_opts)break;;--[^-]*|-[^-]#)# Complete common options if the user has started writing something elsecommand_options=($_nix_env_common_opts);;esacdone
if (( CURRENT==2 )); then_describe -t commands "nix-env subcommands" _set_flag_attrsreturnfi
# Let _arguments handle the rest, with _1st_arguments being mutually exclusive# under the main_options group_arguments -s $command_options \'*'{--file,-f}'[Specify Nix expression used to obtain derivations]:Path to file:_nix_path'\'-f.[evaluate ./default.nix rather than the default]' \$__nix_boilerplate_opts \- '(main_options)' \$_1st_arguments
if (( CURRENT==3 )); thencase "$words[2]" in
# Handle the --set-flag optioncase $state inflag_name)local -a _set_flag_attrs=('priority:Resolve package name conflicts''keep:Prevent package from being upgraded''active:Package is symlinked to profile')_describe -t commands "Package flag" _set_flag_attrsbreak;;flag_value)local flag_name=$words[$(($CURRENT - 1))]case $flag_name in
else_nix_installed_packagesfi;;--query|-[^-]#q[^-]#)_arguments -s -O options $_nix_env_common_opts \'(--available -a)'{--available,-a}'[Display all installable derivations]' \$_nix_output_opts \$_nix_env_b \'(--status -s)'{--status,-s}'[Print status of derivation]' \'(--attr-path -P)'{--attr-path,-P}'[Print attribute path of derivations]' \'--no-name[Suppress printing of name attribute]' \'(--compare-versions -c)'{--compare-versions,-c}'[Compare installed and available version]' \'--system[Print system attribute]' \'--drv-path[Print store derivation path]' \'--out-path[Print output path]' \'--description[Print description]' \'--xml[Print output as XML]'\'--json[Print output as JSON]'\'--meta[Print all meta attributes: only available with --xml]'\;;--switch-profile|-[^-]#S[^-]#)_arguments ':Profile:_nix_profiles';;--delete-generations)_arguments \'*::Generations:_nix_generations';;--switch-generation|-[^-]#G[^-]#)_arguments '::Generations:_nix_generations';;
;;
_path_files '-g' '*.nix(N) *(N-/)'
_alternative \"file:Local file:_path_files -g '*.nix(N) *(N-/)'" \'shortcuts:Shortcuts:_nix_shortcuts' \'channel:Channel:(channel:channel:nixos-13.10channel:nixos-14.04 channel:nixos-14.04-smallchannel:nixos-14.12 channel:nixos-14.12-smallchannel:nixos-15.09 channel:nixos-15.09-smallchannel:nixos-16.03 channel:nixos-16.03-smallchannel:nixos-16.09 channel:nixos-16.09-smallchannel:nixos-17.03 channel:nixos-17.03-smallchannel:nixos-17.09 channel:nixos-17.09-smallchannel:nixos-18.03 channel:nixos-18.03-smallchannel:nixos-18.09 channel:nixos-18.09-smallchannel:nixos-19.03 channel:nixos-19.03-smallchannel:nixos-19.09 channel:nixos-19.09-smallchannel:nixos-20.03 channel:nixos-20.03-smallchannel:nixos-20.09 channel:nixos-20.09-smallchannel:nixos-21.05 channel:nixos-21.05-smallchannel:nixos-21.11 channel:nixos-21.11-smallchannel:nixos-22.05 channel:nixos-22.05-smallchannel:nixos-22.11 channel:nixos-22.11-smallchannel:nixos-unstable channel:nixos-unstable-smallchannel:nixpkgs-unstable)' \'url:URL:(https:// http://)'} # see: https://channels.nixos.org/_nix_complete_includes () {local cur=${words[$CURRENT]}local -a nixpath=(${(s.:.)NIX_PATH})local -a path_nameslocal pfor p in ${nixpath[*]}; do[[ "$p" == *=* ]] && \path_names+=(${p%=*}:Path:_nix_complete_dotnix_files)doneif [[ $cur == *=* ]]; thenpath_names+=(${cur%=*}:Path:_nix_complete_dotnix_files)fiif [[ "$path_names" ]]; then_alternative \"nixpath:nixpath:_values -s = 'Nix path name' $path_names" \'file:Path:_path_files -/'else_path_files -/fireturn
local generations=($(nix-env --list-generations | awk '{print $1":"$2}'))_describe "Nix Generations" generations
setopt extendedgloblocal -a generations=(${${${(f)"$(nix-env --list-generations)"}## #}/ /:})_describe -V "Nix Generations" generations
local -a packagespackages=($(nix-env -q | perl -pe 's/-[0-9.-].*$//'))_values "Nix Packages" $packages
# with the alternative to specify store pathslocal extra_help=$1local prefix='-P ./'local current_word=$words[$CURRENT]# When referencing an absolute path we can't prefix with ./if [[ -z ${current_word:##(/*|\~/*)} && -n $current_word ]]; thenprefix=""filocal -a packages=(${${(f)"$(nix-env -q)"}%%-[0-9]*})_alternative \"package:packages:_values 'Installed package $extra_help' $packages" \"file:Store path to package:_files ${prefix}"
local -a resultlocal -a queue=($1)
local -A result # name -> path map# Search depth first for directories containing 'default.nix'# nix-env -iA prioritize the user's channels in case of name collision# Not sure how collisions in user-created directories are resolved.local -aU initialQueue=($1/channels $1/channels_root $1/*)local -a queue=($initialQueue)
# Prints the attribute names (whitespace separated) of the given path# Arguments: attribute_path [top_level_expr_path]# top_level_expr is interpreted as 'nix-env --file'# if top_level_expr is omitted it defaults to what 'nix-env -iA' uses# Eg. _nix_attr_names nixos.python2Packages mypkgs.nix_nix_attr_names () {setopt local_options pipefail
# Complete attribute names using $1 as the toplevel expression NB: If calling# this function from an action spec you need to prefix it with a space so that# eg. _arguments won't pass it options which it doesn't expect, ie:# `: _nix_attr_paths`_nix_attr_paths () {
local defexprif [[ -n $defexpr_path ]]; thenif [[ -e $defexpr_path ]]; then# If the path exist use the absolute path to make sure import will# accept it.# (Otherwise the path is likely a <nixpkgs> notation)defexpr_path=${defexpr_path:a}fidefexpr="import $defexpr_path"elif [[ $command_name == nix-env ]]; thendefexpr=$(_nix_gen_defexpr ~/.nix-defexpr)
# Starting with '.' causes _sep_parts to complain, so exit early.# This also guards against error output when completion './files' with nix.if [[ $cur == .* ]]; thenreturn
nix-instantiate --eval - \<<NIX_FILE | tr '[]"' ' 'lettop_gen = $defexpr;# --file arguments can be a lambda producing a record tootop = if builtins.typeOf top_gen == "lambda" then top_gen {} else top_gen ;inbuiltins.attrNames $attr_path
local defexpr=$1local attr_path=""if [[ $cur == *.* ]]; thenattr_path=${cur%.*}fi# attr1.attr3 -> ("attr1" "attr2")local -a paths=(${(s,.,)attr_path})# Add quotes in a second step to avoid ("") when emptypaths=(${${paths/%/\"}/#/\"})# Auto call any functions in the attribute path. This isn't a language# feature, but done by nix when passing attributes on the command line.local -a resultresult=($(_nix_eval_stdin <<NIX_FILEletautocall = setOrLambda:if builtins.isFunction setOrLambda thensetOrLambda {}elsesetOrLambda;top = autocall ($defexpr);names = [ ${paths[*]} ];# Returns attr.name calling it if it's a functionreducer = set: name:autocall (builtins.getAttr name set);result = builtins.foldl' reducer top names; #'inif builtins.isAttrs result thenbuiltins.attrNames resultelse""
))# If the eval failed return the error messageif [[ $? > 0 ]]; then_message "Eval failed, can't complete (an URL might not be cached):$result"return 1filocal -a prefix=()if [[ -n $attr_path ]]; thenfor i in ${=attr_path//./ }; doprefix+=("($i)" .)donefilocal package=""_wanted package package "Attribute path" \_sep_parts $prefix result \.return $?}function _nix_eval_stdin () {setopt local_options pipefail# Build up a modified NIX_PATH using -I and --includelocal i override=""for ((i=1; i < ${#words[*]}; i++)); docase "${words[i]}" in-I|--include)override+=${override:+:}${words[$((i+1))]};;esacdoneoverride+=${override:+:}${NIX_PATH}# Resolve channel: syntaxwhile [[ "$override" == *(=|:)channel:* ]]; dolocal channel=${override#*channel:}channel="channel:"${channel%%:*}local url="https://nixos.org/channels/"${channel:8}"/nixexprs.tar.xz"# Replace the channel with its urloverride=${override/"$channel"/"$url"}done
# Resolve any url to a cache, else we might trigger a blocking downloadwhile [[ "$override" == *https://* ]]; do# Find the first urllocal url=${override#*https://}# Strip everything starting with the first colonurl="https://"${url%%:*}local cache=$(_nix_resolve_url "$url")# Replace the url with the cacheoverride=${override/"$url"/"$cache"}doneNIX_PATH=$override nix-instantiate --eval - 2>/dev/null | tr '[]"' ' '
# Complete attribute paths# NB: this function expects an optional argument so the user must make sure# zsh completion functions doesn't supply arguments. eg. when used in a# action spec to _arguments the function should be prefixed with a space:# `: _nix_attr_paths`# Without the space prefix _arguments will inject lots of arguments. These# are available(?) in the `expl` array anyway_nix_attr_paths () {local attr_path=""if [[ $words[CURRENT] == *.* ]]; thenattr_path=${words[CURRENT]%.*}
# Generate the top level expression in all the various ways the different# commands expects it to be built. Then generate completions by calling# _nix_attr_paths $defexpr_nix_complete_attr_paths () {local defexpr=""local file=$(_nix_get_file_arg)if [[ "$file" ]]; then# Extract --arg and --argstr into $argslocal i=1 args="" name="" value=""for ((i=1; i < ${#words[*]}; i++)); docase "${words[$i]}" in--arg)name=${(Q)words[$((i+1))]}value=${(Q)words[$((i+2))]}args+="$name = $value;"i=$((i+2));;--argstr)name=${(Q)words[$((i+1))]}value=${(Q)words[$((i+2))]}args+="$name = \"$value\";"i=$((i+2));;esacdoneargs=${args:+{$args}}local optdefexpr="import $file $args"for opt in $words; docase $opt in--expr|-[^-]#E[^-]#)defexpr="($file) $args"break;;esacdoneelseif [[ $service == nix-env ]]; thendefexpr=$(_nix_gen_defexpr ~/.nix-defexpr)elif [[ $service == nix ]]; then# Extract the channels from NIX_PATH and -I/--includelocal -a channels=(${(s.:.)NIX_PATH})# Add -I/--include afterwards, so they will shadow the NIX_PATHchannels+=(${(s.:.)opt_args[-I]})channels+=(${(s.:.)opt_args[--include]})# Add the names in an associative array to avoid duplicateslocal -A nameslocal channel namefor channel in $channels; doname=${channel%%=*}nix_path=${channel#*=}if [[ $name != $channel ]]; then# Only add paths with a name, not sure how they worknames[$name]=1fidonedefexpr=$'{ 'for name in ${(@k)names}; do# nixos-config isn't useful or possible to complete[[ $name == nixos-config ]] && continuedefexpr+="$name = import <${name}>; "donedefexpr+=' }'fifiif [[ $defexpr ]]; then_nix_attr_paths $defexprfi}function _nix_resolve_url () {local url=$1local version="$($service --version)"local inputif [[ "${version##* }" == 1.11.* ]]; then# works for nix 1.11input="$url"else# works for nix 1.12input="${url##*/}\0$url"filocal shasha=$(nix-hash --flat --base32 --type sha256 <(printf "$input"))local cache=${XDG_CACHE_HOME:-~/.cache}/nix/tarballslocal link="$cache"/"$sha"-fileif [[ -e "$link" ]]; thenecho "$cache/$(basename $(readlink $link))-unpacked"
local defexpr_path=$1if [[ -z $defexpr_path ]]; thenif [[ $command_name == nix-env ]]; thendefexpr_path=$opt_args[-f]if [[ -z $defexpr_path ]]; thendefexpr_path=$opt_args[--file]fielseif [[ $line ]]; thendefexpr_path=$line[1]elif [[ -e shell.nix && $command_name == nix-shell ]]; thendefexpr_path=shell.nixelif [[ -e default.nix ]]; thendefexpr_path=default.nixfifi
function _nix_get_file_arg () {local file=""if [[ "$service" == (nix-env|nix) ]]; thenlocal i# Extract the last seen -f/--file argumentfor ((i=1; i < ${#words[*]}; i++)); docase "${words[i]}" in--file|-f)file=${words[$((i+1))]};;-f\.)# -f. is accepted shorthand for -f .file=.;;esacdoneelif [[ $line ]]; thenfile=$line[1]elif [[ -e shell.nix && $service == nix-shell ]]; thenfile=shell.nixelif [[ -e default.nix ]]; thenfile=default.nix
local -a result # must be on separate line to capture error code..result=( $(_nix_attr_names "$attr_path" $defexpr_path) ) 2>/dev/null
if [[ "file" ]]; then# Expand channel: syntaxif [[ "$file" == channel:* ]]; thenfile="https://nixos.org/channels/"${file:8}"/nixexprs.tar.xz"fiif [[ -e $file ]]; then# If the path exist use the absolute path to make sure import will# accept it.# (Otherwise the path is likely a <nixpkgs> notation)file=${file:a}elif [[ "$file" == https://* ]]; thenfile=$(_nix_resolve_url $file)fifiprint -n -- $file}
function _nix_complete_function_arg () {local file=$(_nix_get_file_arg)local func=${file:+import $file} optlocal i exclude=""for ((i=1; i < ${#words}; i++)); docase "${words[$i]}" in--expr|-[^-]#E[^-]#)func="$file";;--arg|--argstr)# Don't add the name we're currently typing[[ $i == $((CURRENT - 1)) ]] && continueexclude+=${exclude:+|}${words[$((i+1))]};;esacdoneif [[ ! $func ]]; thenreturnfilocal -a namesnames=($(_nix_eval_stdin 2>&1 <<NIX_FILEif builtins.typeOf ($func) == "lambda" thenbuiltins.attrNames (builtins.functionArgs ($func))else""NIX_FILE))
_values -s . "Packages" ${prefix}${^result}
# Either true or false: useful for completing many Nix options_nix_options_bool () {_values true false}# List gathered from: https://nixos.org/nix/manual/#sec-conf-file# TODO: Complete the value as well, not just the key_nix_options () {# Complete nix options with descriptionslocal -a nix_options# Strip the header line, remove leading spaces and replace separating# whitespace with ':'nix_options=(${${${${(f)"$(nix --help-config)"}:1:-1}/# /}/ ##/:})_describe -t nix_options "Option" nix_options}_nix_options_value () {# Print the description of the option we're settinglocal OPTION=$words[$(($CURRENT - 1))]# Remove lines not starting with " $OPTION " and strip eveything up to the# last two consecutive spaceslocal description=${${${(f)"$(nix --help-config)"}:#^( $OPTION *)}/* /}local -a values=()case "$description" inWhether*)_values $description true false;;*)_path_files;;esac
_nix_profiles () {local -a profilesprofiles=($(find /nix/var/nix/profiles))_values "Nix Profiles" $profiles
_nix_run_command_names () {local cmd chanif (( ${+commands[sqlite3]} )); then# Extract the channels from NIX_PATH and -I/--include# Add -I/--include afterwards, so they will shadow the NIX_PATHlocal -a nix_path=(${(s.:.)NIX_PATH}${(s.:.)opt_args[-I]}${(s.:.)opt_args[--include]})# channels: key - channel name, value - path to channellocal -A channelsfor chan in $nix_path; doif [[ $chan = *=* ]]; then# name=pathchannels[${chan%%=*}]=${chan#*=}else# path to directory with channelsfor chan in $chan/*(-/); dochannels[$chan:t]=$chandonefidone# pkg_cmds is list of commands inside packages# This is an associative array to avoid duplicates.local -A pkg_cmdsfor chan in ${(k)channels}; do# Extract args with prefix "$chan."local -a pkgs=( "${${(M)words[@]:#"$chan".*}[@]##"$chan".}" )(( ${#pkgs} )) || continuelocal db=${channels[$chan]}/programs.sqlite[ -f "$db" ] || continuepkgs=( "'${^pkgs[@]//\'/''}'" ) # SQL-quotelocal query="SELECT name FROM programs WHERE package IN (${(j:,:)pkgs})"for cmd in $(sqlite3 "$db" "$query"); dopkg_cmds[$cmd]=donedonecompadd -X 'Package commands' -- ${(k)pkg_cmds}fi_command_names -e -X 'All commands'
_nix_gc_common=('(- --print* --delete)--print-roots[Print roots used by garbage collector]' \'(- --print* --delete)--print-live[Print store paths reachable from roots]' \'(- --print* --delete)--print-dead[Print store paths not reachable from roots]' \'(- --print* --delete)--delete[Garbage collect all dead paths from the store]' \
__nix_gc_common=('(- --print* --delete)--print-roots[Print roots used by garbage collector]''(- --print* --delete)--print-live[Print store paths reachable from roots]''(- --print* --delete)--print-dead[Print store paths not reachable from roots]''(- --print* --delete)--delete[Garbage collect all dead paths from the store]'
_nix_search_path_args=('*-I+[Add path to Nix expression search path]:Include path:_nix_complete_dotnix_files'\
__nix_search_path_args=('*-I[add a path to the list of locations used to look up <...> file names]:include path:_nix_complete_includes'
# Either true or false: useful for completing many Nix options_nix_options_bool () {_values true false}# List gathered from: https://nixos.org/nix/manual/#sec-conf-file# TODO: Complete the value as well, not just the key_nix_options () {_values \'gc-keep-outputs' \'gc-keep-derivations' \'env-keep-derivations' \'build-max-jobs' \'build-cores' \'build-max-silent-time' \'build-timeout' \'build-max-log-size' \'build-users-group' \'build-use-chroot' \'build-chroot-dirs' \'build-extra-chroot-dirs' \'build-use-substitutes' \'build-fallback' \'build-cache-failure' \'build-keep-log' \'build-compress-log' \'use-binary-caches' \'binary-caches' \'binary-caches-files' \'trusted-binary-caches' \'extra-binary-caches' \'signed-binary-caches' \'binary-cache-public-keys' \'binary-caches-parallel-connections' \'verify-https-binary-caches' \'force-manifest' \'system' \'fsync-metadata' \'auto-optimise-store' \'connect-timeout' \'log-servers' \'trusted-users' \'allowed-users' \'restrict-eval' \'pre-build-hook'}
__nix_repair='--repair[Fix corrupted or missing store paths by redownloading or rebuilding]';
_nix_common_nixos_rebuild=('(--verbose -v)*'{--verbose,-v}'[Increase verbosity of diagnostic messages]'\'(--no-build-output -Q)'{--no-build-output,-Q}'[Silence output to stdout and stderr]'\'(--max-jobs -j)'{--max-jobs,-j}'[Set the maximum number of build jobs that Nix will perform in parallel]'\'--cores[Set the parallelism of the individual builders (e.g. -j argument to make)]'\'(--keep-going -k)'{--keep-going,-k}'[Keep going in case of failed builds, to the greatest extent possible]'\'(--keep-failed -K)'{--keep-failed,-K}'[Do not delete the build directory if build fails]'\'--fallback[If binary download fails, fall back on building from source]'\'--show-trace[Print stack trace of evaluation errors]'\'--option[Set Nix configuration option]:Options:_nix_options:Value:( )'\$_nix_repair)
__nix_common_nixos_rebuild=($__nix_search_path_args$__nix_repair'(--verbose -v)*'{--verbose,-v}'[Increase verbosity of diagnostic messages]''(--no-build-output -Q)'{--no-build-output,-Q}'[silence output to stdout and stderr]''(--max-jobs -j)'{--max-jobs,-j}'[max number of build jobs in parallel]:jobs:''--cores[threads per job (e.g. -j argument to make)]:cores:''(--keep-going -k)'{--keep-going,-k}"[keep going until all builds are finished]"'(--keep-failed -K)'{--keep-failed,-K}'[keep failed builds (usually in /tmp)]''--fallback[If binary download fails, fall back on building from source]''--show-trace[Print stack trace of evaluation errors]''*--option[set Nix configuration option]:options:_nix_options:value:_nix_options_value')__nix_common_nixos_build_vms=('*--option[set Nix configuration option]:options:_nix_options:value:_nix_options_value')__nix_common_store_opts=('--add-root[register result as a root of the garbage collector]:path (Hint /nix/var/nix/gcroots):_path_files -/''--indirect[store gc root outside GC roots directory]')# Used in: nix-build, nix-env, nix-instantiate, nix-shell and nix-store__nix_extra_build_opts=('--max-silent-time[max seconds without getting stdout/err from builder]:Seconds:''--timeout[max seconds builders should run]:seconds:''--readonly-mode[do not open Nix database]''--log-format[configure how output is formatted]:output format:((pretty\:"Default" escapes\:"Indicate nesting with escape codes" flat\:"Remove all nesting"))')
_nix_common_opts=($_nix_common_nixos_rebuild \$_nix_search_path_args \'(--attr -A)'{--attr,-A}'[Select an attribute from the top-level Nix expression being evaluated]:Packages: _nix_attr_paths'\'(--expr -E)'{--expr,-E}'[Interpret command line args as Nix expressions]:*:Files:_files'\'*--arg[Argument to pass to the Nix function]:Name:( ):Value:( )'\'--argstr[Like --arg, but the value is a string]: :'\'--max-silent-time[Builder times out after not producing stdout/stderr for x seconds]:Seconds:( )'\'--timeout[Timeout builder after given number of seconds]:Seconds:( )'\'--readonly-mode[Do not open Nix database]'\'--log-type[Configure how output is formatted]:Output format:((pretty\:"Default" escapes\:"Indicate nesting with escape codes" flat\:"Remove all nesting"))'\
__nix_common_opts=($__nix_common_nixos_rebuild$__nix_args_opts$__nix_extra_build_opts'*--include[add a path to the list of locations used to look up <...> file names]:include path:_nix_complete_includes''*--arg[argument to pass to the Nix function]:Name:_nix_complete_function_arg:Value: ''*--argstr[pass a string]:Name:_nix_complete_function_arg:String: ')# Options for nix-store --realise, used by nix-build__nix_store_realise_opts=($__nix_dry_run'--check[rebuild and see if output is deterministic]'
case $state innix-channels)local -a channels=(${${(f)"$(nix-channel --list)"}%% *})_values 'Nix Channels' ${channels}esac
local -a _nix_build_opts_nix_build_opts=('--drv-link[Add a symlink to the store derivation]:Symlink Name:( )' \'--add-drv-link[Shorthand for --drv-link ./derivation]' \'--no-out-link[Do not create a symlink to the output path]' \{--out-link,-o}'[Name of the output symlink]:Output Symlink Name:( )' \
local -a _nix_build_opts=($__nix_expr_opts$__nix_common_store_opts'*'{--attr,-A}'[build a package from file (default: ./default.nix)]:package:_nix_complete_attr_paths'--check'[Rebuild derivation]''--drv-link[Add a symlink to the store derivation]:Symlink Name:( )''--add-drv-link[Shorthand for --drv-link ./derivation]''--no-out-link[Do not create a symlink to the output path]'{--out-link,-o}'[Name of the output symlink]:Output Symlink Name:( )'
Set `programs.zsh.enableCompletion = true` in `/etc/nix/configuration.nix` and either add `nix-zsh-completions` to `systemPackages` or install it locally: `nix-env -iA nixos.nix-zsh-completions`
Setting `programs.zsh.enable = true` in `/etc/nixos/configuration.nix` will automatically install and enable `nix-zsh-compeletions`.
<!--Thank you for reporting an issue :) broken software is no fun for anyone :(To quickly figure out any problem there's some information that's often useful.Namely your system and a step by step explanation on how to reproduce theproblem (or a completion trace if reproduction isn't clear)If the issue is a feature request or doesn't require this information you canomit it, deleting the `System` and `Completion trace` headersLines wrapped with \<!-- ... --\> will be ignored, so you don't have to delete them.-->### Description### Reproduction steps<!--Steps to reproduce the problem-->### System- nix-zsh-completions version: <!-- version or git commit -->- ZSH version: <!-- print $ZSH_VERSION -->- NIX_PATH: <!-- print $NIX_PATH --><!--also run `nix-shell -p nix-info --run "nix-info -m"` and paste the result here-->### Completion trace<!--If the issue is elusive and you're unable to reproduce it conistently a completion trace of the failure can be useful.To produce a trace do this:Use the `Ctr-x ?` keybinding instead of tab (at the place tab fails).This will give you a file in `/tmp` with a full trace.Post the file to a gist service and include the link here.-->
# Nix Installalias ni='nix-env -iA'# Nix Searchalias ns='nix-env -qaP'function prompt_nix_shell_precmd {if [[ -n ${IN_NIX_SHELL} && ${IN_NIX_SHELL} != "0" || ${IN_NIX_RUN} && ${IN_NIX_RUN} != "0" ]]; thenif [[ -n ${IN_WHICH_NIX_SHELL} ]] thenNIX_SHELL_NAME=": ${IN_WHICH_NIX_SHELL}"fiif [[ -n ${IN_NIX_SHELL} && ${IN_NIX_SHELL} != "0" ]]; thenNAME="nix-shell"elseNAME="nix-run"fiNIX_PROMPT="%F{8}[%F{3}${NAME}${NIX_SHELL_NAME}%F{8}]%f"if [[ $PROMPT != *"$NIX_PROMPT"* ]] thenPROMPT="$NIX_PROMPT $PROMPT"fifi}function prompt_nix_shell_setup {autoload -Uz add-zsh-hookadd-zsh-hook precmd prompt_nix_shell_precmd}# Add this to your zshrc if you want the prompt prefixed with `[nix-shell]`# when you're in a nix-shell environment.# prompt_nix_shell_setup "$@"
#compdef nixos-option#autoload_nix-common-options # import _nix_attr_paths etc._nixos-option-opts() {local mods=if [[ -n "$NIX_PATH" && "$NIX_PATH" =~ "nixos-config=" ]]; thenmods="(import <nixos-config>)"filocal options='with import <nixpkgs/lib>;(evalModules {modules = import <nixpkgs/nixos/modules/module-list.nix> ++ [ '"$mods"' ];}).config'_nix_attr_paths $options}_arguments \$__nix_search_path_args \'--all[Print the values of all options.]' \':NixOS module options:_nixos-option-opts'
<!--Thank you for reporting an issue :) broken software is no fun for anyone :(To quickly figure out any problem there's some information that's often useful.Namely your system and a step by step explanation on how to reproduce theproblem (or a completion trace if reproduction isn't clear)If the issue is a feature request or doesn't require this information you canomit it, deleting the `System` and `Completion trace` headersLines wrapped with \<!-- ... --\> will be ignored, so you don't have to delete them.-->### Description### Reproduction steps<!--Steps to reproduce the problem-->### System- nix-zsh-completions version: <!-- version or git commit -->- ZSH version: <!-- print $ZSH_VERSION -->- NIX_PATH: <!-- print $NIX_PATH --><!--also run `nix-shell -p nix-info --run "nix-info -m"` and paste the result here-->### Completion trace<!--If the issue is elusive and you're unable to reproduce it conistently a completion trace of the failure can be useful.To produce a trace do this:Use the `Ctr-x ?` keybinding instead of tab (at the place tab fails).This will give you a file in `/tmp` with a full trace.Post the file to a gist service and include the link here.-->