_guix 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. #compdef guix
  2. #
  3. # GNU Guix --- Functional package management for GNU
  4. # Copyright © 2016 Eric Le Bihan <eric.le.bihan.dev@free.fr>
  5. #
  6. # This file is part of GNU Guix.
  7. #
  8. # GNU Guix is free software; you can redistribute it and/or modify it
  9. # under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 3 of the License, or (at
  11. # your option) any later version.
  12. #
  13. # GNU Guix is distributed in the hope that it will be useful, but
  14. # WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. _guix_caching_policy()
  21. {
  22. local -a old_policy
  23. old_policy=( "$1"(Nmh+24) )
  24. (( $#old_policy ))
  25. }
  26. _guix_list_actions()
  27. {
  28. _guix_actions=( $(guix system --help | sed -n 's/^ \([a-z-]\+\)\s\+.\+/\1/p') )
  29. }
  30. _guix_list_checkers()
  31. {
  32. _guix_checkers=( $(guix lint -l | sed -n 's/^- \(.\+\): .\+/\1/p') )
  33. }
  34. _guix_list_graph_types()
  35. {
  36. _guix_graph_types=( $(guix graph --list-types | sed -n 's/^ - \(.\+\): .\+/\1/p') )
  37. }
  38. _guix_list_importers()
  39. {
  40. _guix_importers=( $(guix import --help | sed -n 's/^\s\+\([a-z]\+\)$/\1/p') )
  41. }
  42. _guix_list_updaters()
  43. {
  44. _guix_updaters=( $(guix lint -l | sed -n 's/^- \(.\+\): .\+/\1/p') )
  45. }
  46. _guix_list_available_packages()
  47. {
  48. if ( [[ ${+_guix_available_packages} -eq 0 ]] || _cache_invalid GUIX_AVAILABLE_PACKAGES ) \
  49. && ! _retrieve_cache GUIX_AVAILABLE_PACKAGES; then
  50. _guix_available_packages=(${${(f)"$(guix package -A | cut -f1)"}})
  51. _store_cache GUIX_AVAILABLE_PACKAGES _guix_available_packages
  52. fi
  53. }
  54. _guix_list_installed_packages()
  55. {
  56. _guix_installed_packages=( $(guix package -I "^${prefix}" | cut -f1) )
  57. }
  58. (( $+functions[_guix_build] )) || _guix_build()
  59. {
  60. _arguments \
  61. '--expression=[build the package matching EXPR]:EXPR' \
  62. '--file=[build the package matching code evaluated from FILE]:FILE:_files' \
  63. '--source[build the packages source derivations]' \
  64. '--sources=[build source derivations]:TYPE:(all package transitive)' \
  65. '--system=[attempt to build for SYSTEM (e.g. "i686-linux")]:SYSTEM' \
  66. '--target=[cross-build for TRIPLET (e.g. "armel-linux-gnu")]:TRIPLET' \
  67. '--derivations[return the derivation paths of the given packages]' \
  68. '--check[rebuild items to check for non-determinism issues]' \
  69. '--root=[symlink result to FILE and register it as GC root]:FILE:_files' \
  70. '--quiet[do not show the build log]' \
  71. '--log-file[return the log file names for the given derivations]' \
  72. '--load-path=[prepend DIR to the package module search path]:DIR:_dirs' \
  73. '--keep-failed[keep build tree of failed builds]' \
  74. '--keep-going[keep going when some of the derivations fail]' \
  75. '--dry-run[do not build the derivations]' \
  76. '--fallback[fall back to building when the substituter fails]' \
  77. '--no-substitutes[build instead of resorting to pre-built substitutes]' \
  78. '--substitute-urls=[fetch substitute from URLS if they are authorized]:URLS:_urls' \
  79. '--no-grafts[do not graft packages]' \
  80. '--no-offload[do not attempt to offload builds]' \
  81. '--max-silent-time=[mark the build as failed after SECONDS of silence]:SECONDS' \
  82. '--timeout=[mark the build as failed after SECONDS of activity]:SECONDS' \
  83. '--verbosity=[use the given verbosity LEVEL]:LEVEL' \
  84. '--rounds=[build N times in a row to detect non-determinism]:N' \
  85. '--cores=[allow the use of up to N CPU cores for the build]:N' \
  86. '--max-jobs=[allow at most N build jobs]:N' \
  87. '--with-source=[use SOURCE when building the corresponding package]:SOURCE' \
  88. '--with-input=[replace dependency PACKAGE by REPLACEMENT]:PACKAGE=REPLACEMENT' \
  89. '*:package:->packages'
  90. if [[ "$state" = packages ]]; then
  91. _guix_list_available_packages
  92. compadd -a -- _guix_available_packages
  93. fi
  94. }
  95. (( $+functions[_guix_challenge] )) || _guix_challenge()
  96. {
  97. _arguments \
  98. '--substitute-urls=[fetch substitute from URLS if they are authorized]:URL:_urls' \
  99. '*:package:->packages'
  100. if [[ "$state" = packages ]]; then
  101. _guix_list_available_packages
  102. compadd -a -- _guix_available_packages
  103. fi
  104. }
  105. (( $+functions[_guix_container] )) || _guix_container()
  106. {
  107. _arguments \
  108. ':action:(exec)' \
  109. '*:args'
  110. }
  111. (( $+functions[_guix_download] )) || _guix_download()
  112. {
  113. _arguments \
  114. '--format=[write the hash in the given format]:FMT:(nix-base32 base16 base32 hex)' \
  115. '1:URL:_urls'
  116. }
  117. (( $+functions[_guix_edit] )) || _guix_edit()
  118. {
  119. _guix_list_available_packages
  120. compadd -a -- _guix_available_packages
  121. }
  122. (( $+functions[_guix_environment] )) || _guix_environment()
  123. {
  124. _arguments \
  125. '--expression=[create environment for the package evaluated from EXPR]:EXPR' \
  126. '--load=[create environment for the package evaluated from FILE]:FILE:_files' \
  127. '--ad-hoc[include all specified packages, not only their inputs]' \
  128. '--pure[unset existing environment variables]' \
  129. '--search-paths[display needed environment variable definitions]' \
  130. '--system=[attempt to build for SYSTEM (e.g. "i686-linux")]:SYSTEM' \
  131. '--container[run command within an isolated container]' \
  132. '--network[allow containers to access the network]' \
  133. '--share=[share writable host file system according to SPEC]:SPEC' \
  134. '--expose=[expose read-only host file system according to SPEC]:SPEC' \
  135. '--bootstrap[use bootstrap binaries to build the environment]' \
  136. '--load-path=[prepend DIR to the package module search path]:DIR:_dirs' \
  137. '--keep-failed[keep build tree of failed builds]' \
  138. '--keep-going[keep going when some of the derivations fail]' \
  139. '--dry-run[do not build the derivations]' \
  140. '--fallback[fall back to building when the substituter fails]' \
  141. '--no-substitutes[build instead of resorting to pre-built substitutes]' \
  142. '--substitute-urls=[fetch substitute from URLS if they are authorized]:URLS:_urls' \
  143. '--no-grafts[do not graft packages]' \
  144. '--no-offload[do not attempt to offload builds]' \
  145. '--max-silent-time=[mark the build as failed after SECONDS of silence]:SECONDS' \
  146. '--timeout=[mark the build as failed after SECONDS of activity]:SECONDS' \
  147. '--verbosity=[use the given verbosity LEVEL]:LEVEL' \
  148. '--rounds=[build N times in a row to detect non-determinism]:N' \
  149. '--cores=[allow the use of up to N CPU cores for the build]:N' \
  150. '--max-jobs=[allow at most N build jobs]:N' \
  151. '*:package:->packages'
  152. if [[ "$state" = packages ]]; then
  153. _guix_list_available_packages
  154. compadd -a -- _guix_available_packages
  155. fi
  156. }
  157. (( $+functions[_guix_gc] )) || _guix_gc()
  158. {
  159. _arguments \
  160. '--collect-garbage=[collect at least MIN bytes of garbage]:MIN' \
  161. '--free-space=[attempt to reach FREE available space in the store]:FREE' \
  162. '--delete[attempt to delete PATHS]' \
  163. '--optimize[optimize the store by deduplicating identical files]' \
  164. '--list-dead[list dead paths]' \
  165. '--list-live[list live paths]' \
  166. '--references[list the references of PATHS]' \
  167. '--requisites[list the requisites of PATHS]' \
  168. '--referrers[list the referrers of PATHS]' \
  169. '--verify=[verify the integrity of the store]:OPTS:(contents repair)' \
  170. '--list-failures[list cached build failures]' \
  171. '--clear-failures[remove PATHS from the set of cached failures]' \
  172. '1:PATH:_dirs'
  173. }
  174. (( $+functions[_guix_graph] )) || _guix_graph()
  175. {
  176. _arguments \
  177. '--type=[represent nodes of the given TYPE]:TYPE:->types' \
  178. '--list-types[list the available graph types]' \
  179. '--expression=[consider the package EXPR evaluates to]:EXPR' \
  180. '1:PACKAGE:->packages'
  181. case "$state" in
  182. types)
  183. _guix_list_graph_types
  184. compadd -a -- _guix_graph_types
  185. ;;
  186. packages)
  187. _guix_list_available_packages
  188. compadd -a -- _guix_available_packages
  189. ;;
  190. esac
  191. }
  192. (( $+functions[_guix_hash] )) || _guix_hash()
  193. {
  194. _arguments \
  195. '--format=[write the hash in the given format]:FMT:(nix-base32 base16 base32 hex)' \
  196. '--recursive[compute the hash on FILE recursively]'\
  197. '1:FILE:_files'
  198. }
  199. (( $+functions[_guix_import] )) || _guix_import()
  200. {
  201. _arguments \
  202. '1:IMPORTER:->importer' \
  203. '*:args:'
  204. if [[ "$state" = importer ]]; then
  205. _guix_list_importers
  206. compadd -a -- _guix_importers
  207. fi
  208. }
  209. (( $+functions[_guix_lint] )) || _guix_lint()
  210. {
  211. _arguments \
  212. '--checkers=[only run the specified checkers]:CHECKERS:->checkers' \
  213. '--list-checkers[display the list of available lint checkers]' \
  214. '1:PACKAGE:->packages'
  215. case "$state" in
  216. checkers)
  217. _guix_list_checkers
  218. compadd -a -- _guix_checkers
  219. ;;
  220. packages)
  221. _guix_list_available_packages
  222. compadd -a -- _guix_available_packages
  223. ;;
  224. esac
  225. }
  226. (( $+functions[_guix_package] )) || _guix_package()
  227. {
  228. _arguments \
  229. '--install[install one or more packages]: :->install' \
  230. '--install-from-expression=[install the package EXP evaluates to]:EXP' \
  231. '--install-from-file=[install the package evaluated from FILE]:FILE:_files' \
  232. '--remove[remove one or more packages]: :->remove' \
  233. '--upgrade=[upgrade all the installed packages matching REGEXP]:REGEXP' \
  234. '--manifest=[create a new profile generation from FILE]:FILE:_files' \
  235. '--do-not-upgrade=[do not upgrade any packages matching REGEXP]:REGEXP' \
  236. '--roll-back[roll back to the previous generation]' \
  237. '--search-paths=[display needed environment variable definitions]:KINDS' \
  238. '--list-generations=[list generations matching PATTERN]:PATTERN' \
  239. '--delete-generations=[delete generations matching PATTERN]:PATTERN' \
  240. '--switch-generation=[switch to a generation matching PATTERN]:PATTERN' \
  241. '--profile=[use PROFILE instead of the default profile]:PROFILE' \
  242. '--bootstrap[use the bootstrap Guile to build the profile]' \
  243. '--verbose[produce verbose output]' \
  244. '--search=[search in synopsis and description using REGEXP]:REGEXP' \
  245. '--list-installed=[list installed packages matching REGEXP]:REGEXP' \
  246. '--list-available=[list available packages matching REGEXP]:REGEXP' \
  247. '--show=[show details about a package]: :->show' \
  248. '--load-path=[prepend DIR to the package module search path]:DIR:_dirs' \
  249. '--keep-failed[keep build tree of failed builds]' \
  250. '--keep-going[keep going when some of the derivations fail]' \
  251. '--dry-run[do not build the derivations]' \
  252. '--fallback[fall back to building when the substituter fails]' \
  253. '--no-substitutes[build instead of resorting to pre-built substitutes]' \
  254. '--substitute-urls=[fetch substitute from URLS if they are authorized]:URLS:_urls' \
  255. '--no-grafts[do not graft packages]' \
  256. '--no-offload[do not attempt to offload builds]' \
  257. '--max-silent-time=[mark the build as failed after SECONDS of silence]:SECONDS' \
  258. '--timeout=[mark the build as failed after SECONDS of activity]:SECONDS' \
  259. '--verbosity=[use the given verbosity LEVEL]:LEVEL' \
  260. '--rounds=[build N times in a row to detect non-determinism]:N' \
  261. '--cores=[allow the use of up to N CPU cores for the build]:N' \
  262. '--max-jobs=[allow at most N build jobs]:N' \
  263. '--with-source=[use SOURCE when building the corresponding package]:SOURCE' \
  264. '--with-input=[replace dependency PACKAGE by REPLACEMENT]:PACKAGE=REPLACEMENT'
  265. case "$state" in
  266. install|show)
  267. _guix_list_available_packages
  268. compadd -a -- _guix_available_packages
  269. ;;
  270. remove)
  271. _guix_list_installed_packages
  272. compadd -a -- _guix_installed_packages
  273. ;;
  274. esac
  275. }
  276. (( $+functions[_guix_publish] )) || _guix_publish()
  277. {
  278. _arguments \
  279. '--port=[listen on PORT]:PORT:' \
  280. '--listen=[listen on the network interface for HOST]:HOST:_hosts' \
  281. '--user=[change privileges to USER as soon as possible]:USER:_users' \
  282. '--compression=[compress archives at LEVEL]:LEVEL' \
  283. '--ttl=[announce narinfos can be cached for TTL seconds]:TTL' \
  284. '--repl=[spawn REPL server on PORT]:PORT'
  285. }
  286. (( $+functions[_guix_pull] )) || _guix_pull()
  287. {
  288. _arguments \
  289. '--verbose[produce verbose output]' \
  290. '--url=[download the Guix tarball from URL]:URL:_urls' \
  291. '--bootstrap[use the bootstrap Guile to build the new Guix]'
  292. }
  293. (( $+functions[_guix_refresh] )) || _guix_refresh()
  294. {
  295. _arguments \
  296. '--expression=[consider the package EXPR evaluates to]:EXPR' \
  297. '--update[update source files in place]' \
  298. '--select=[select all the packages in SUBSET]:SUBSET:(core non-core)' \
  299. '--type=[restrict to updates from the specified updaters]:UPDATER:->updaters' \
  300. '--list-updaters[list available updaters and exit]' \
  301. '--list-dependent[list top-level dependent packages]' \
  302. '--key-server=[use HOST as the OpenPGP key server]:HOST:_hosts' \
  303. '--gpg=[use COMMAND as the GnuPG 2.x command]:COMMAND' \
  304. '--key-download=[policy to handle missing OpenPGP keys]:POLICY:(always interactive never)' \
  305. '*:package:->packages'
  306. case "$state" in
  307. updaters)
  308. _guix_list_updaters
  309. compadd -a -- _guix_updaters
  310. ;;
  311. packages)
  312. _guix_list_available_packages
  313. compadd -a -- _guix_available_packages
  314. ;;
  315. esac
  316. }
  317. (( $+functions[_guix_size] )) || _guix_size()
  318. {
  319. _arguments \
  320. '--substitute-urls=[fetch substitute from URLS if they are authorized]:URL:_urls' \
  321. '-system=[consider packages for SYSTEM--e.g., "i686-linux"]:SYSTEM' \
  322. '--map-file=[write to FILE a graphical map of disk usage]:FILE:_files' \
  323. '*:package:->packages'
  324. if [[ "$state" = packages ]]; then
  325. _guix_list_available_packages
  326. compadd -a -- _guix_available_packages
  327. fi
  328. }
  329. (( $+functions[_guix_system] )) || _guix_system()
  330. {
  331. _arguments \
  332. '--load-path=[prepend DIR to the package module search path]:DIR:_dirs' \
  333. '--keep-failed[keep build tree of failed builds]' \
  334. '--keep-going[keep going when some of the derivations fail]' \
  335. '--dry-run[do not build the derivations]' \
  336. '--fallback[fall back to building when the substituter fails]' \
  337. '--no-substitutes[build instead of resorting to pre-built substitutes]' \
  338. '--substitute-urls=[fetch substitute from URLS if they are authorized]:URL:_urls' \
  339. '--no-grafts[do not graft packages]' \
  340. '--no-offload[do not attempt to offload builds]' \
  341. '--max-silent-time=[mark the build as failed after SECONDS of silence]:SECONDS' \
  342. '--timeout=[mark the build as failed after SECONDS of activity]:SECONDS' \
  343. '--verbosity=[use the given verbosity LEVEL]:LEVEL' \
  344. '--rounds=[build N times in a row to detect non-determinism]:N' \
  345. '--cores=[allow the use of up to N CPU cores for the build]:N' \
  346. '--max-jobs=[allow at most N build jobs]:N' \
  347. '--derivation[return the derivation of the given system]' \
  348. '--on-error=[apply STRATEGY when an error occurs while reading FILE]:STRATEGY' \
  349. '--image-size=[for "vm-image", produce an image of SIZE]:SIZE' \
  350. '--no-grub[for "init", do not install GRUB]' \
  351. '--share=[for "vm", share host file system according to SPEC]:SPEC' \
  352. '--expose=[for "vm", expose host file system according to SPEC]:SPEC' \
  353. '--full-boot[for "vm", make a full boot sequence]' \
  354. '1:action:->actions' \
  355. '*:file:_files'
  356. if [[ "$state" = actions ]]; then
  357. _guix_list_actions
  358. compadd -a -- _guix_actions
  359. fi
  360. }
  361. (( $+functions[_guix_command] )) || _guix_command()
  362. {
  363. local -a _guix_cmds
  364. _guix_cmds=(
  365. "archive:Export/import one or more packages from/to the store"
  366. "build:Build a given package"
  367. "challenge:Challenge the substitutes for a package"
  368. "container:Build and manipulate Linux containers"
  369. "download:Download the file at given URL and add it to the store"
  370. "edit:Edit the definitions of a package"
  371. "environment:Build an environment with a package and its dependencies"
  372. "gc:Invoke the garbage collector"
  373. "graph:Emit a DOT representation of the dependencies of a package"
  374. "hash:Return the cryptographic hash of a file"
  375. "import:Run an importer"
  376. "lint:Run a set of checkers on a package"
  377. "package:Install, remove, or upgrade packages"
  378. "publish:Publish /gnu/store over HTTP."
  379. "pull:Download and deploy the latest version of Guix"
  380. "refresh:Update package definitions to match the latest version"
  381. "size:Report the size of a package and its dependencies"
  382. "system:Build the operating system"
  383. )
  384. if (( CURRENT == 1 )); then
  385. _describe -t commands 'guix command' _guix_cmds || compadd "$@"
  386. else
  387. local curcontext="$curcontext"
  388. cmd="${${_guix_cmds[(r)$words[1]:*]%%:*}}"
  389. if (( $#cmd )); then
  390. local cache_policy
  391. zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
  392. if [[ -z "$cache_policy" ]]; then
  393. zstyle ":completion:${curcontext}:" cache-policy _guix_caching_policy
  394. fi
  395. curcontext="${curcontext%:*:*}:guix-${cmd}:"
  396. _call_function ret _guix_${cmd} || _message 'no more arguments'
  397. else
  398. _message "unknown guix command: $words[1]"
  399. fi
  400. return ret
  401. fi
  402. }
  403. _arguments \
  404. '(--version)--version[Display version information and exit]' \
  405. '*::guix command:_guix_command'
  406. # vim: ts=4 sts=4 sw=4 et ai
  407. # Local variables:
  408. # mode: sh
  409. # End: