ui.scm 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012-2023 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2013, 2018 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
  5. ;;; Copyright © 2014 Cyril Roelandt <tipecaml@gmail.com>
  6. ;;; Copyright © 2014 Cyrill Schenkel <cyrill.schenkel@gmail.com>
  7. ;;; Copyright © 2014, 2015, 2017 Alex Kost <alezost@gmail.com>
  8. ;;; Copyright © 2015 David Thompson <davet@gnu.org>
  9. ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
  10. ;;; Copyright © 2016 Roel Janssen <roel@gnu.org>
  11. ;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
  12. ;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com>
  13. ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
  14. ;;; Copyright © 2019 Chris Marusich <cmmarusich@gmail.com>
  15. ;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
  16. ;;; Copyright © 2019, 2021 Simon Tournier <zimon.toutoune@gmail.com>
  17. ;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net>
  18. ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  19. ;;; Copyright © 2018 Steve Sprang <scs@stevesprang.com>
  20. ;;; Copyright © 2022 Taiju HIGASHI <higashi@taiju.info>
  21. ;;; Copyright © 2022 Liliana Marie Prikler <liliana.prikler@gmail.com>
  22. ;;; Copyright © 2023 Sarthak Shah <shahsarthakw@gmail.com>
  23. ;;;
  24. ;;; This file is part of GNU Guix.
  25. ;;;
  26. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  27. ;;; under the terms of the GNU General Public License as published by
  28. ;;; the Free Software Foundation; either version 3 of the License, or (at
  29. ;;; your option) any later version.
  30. ;;;
  31. ;;; GNU Guix is distributed in the hope that it will be useful, but
  32. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  33. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. ;;; GNU General Public License for more details.
  35. ;;;
  36. ;;; You should have received a copy of the GNU General Public License
  37. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  38. (define-module (guix ui)
  39. #:use-module (guix i18n)
  40. #:use-module (guix colors)
  41. #:use-module (guix diagnostics)
  42. #:use-module (guix gexp)
  43. #:use-module (guix sets)
  44. #:use-module (guix utils)
  45. #:use-module (guix store)
  46. #:use-module (guix config)
  47. #:use-module (guix packages)
  48. #:use-module (guix profiles)
  49. #:use-module (guix derivations)
  50. #:use-module (guix build-system)
  51. #:use-module (guix serialization)
  52. #:use-module ((guix licenses)
  53. #:select (license? license-name license-uri))
  54. #:use-module ((guix build syscalls)
  55. #:select (free-disk-space terminal-columns terminal-rows
  56. with-file-lock/no-wait))
  57. #:use-module ((guix build utils)
  58. ;; XXX: All we need are the bindings related to
  59. ;; '&invoke-error'. However, to work around the bug described
  60. ;; in 5d669883ecc104403c5d3ba7d172e9c02234577c, #:hide
  61. ;; unwanted bindings instead of #:select'ing the needed
  62. ;; bindings.
  63. #:hide (package-name->name+version
  64. ;; Avoid "overrides core binding" warning.
  65. delete))
  66. #:use-module (srfi srfi-1)
  67. #:use-module (srfi srfi-9 gnu)
  68. #:use-module (srfi srfi-11)
  69. #:use-module (srfi srfi-19)
  70. #:use-module (srfi srfi-26)
  71. #:use-module (srfi srfi-31)
  72. #:use-module (srfi srfi-34)
  73. #:use-module (srfi srfi-35)
  74. #:autoload (ice-9 ftw) (scandir)
  75. #:use-module (ice-9 match)
  76. #:use-module (ice-9 format)
  77. #:use-module (ice-9 regex)
  78. #:autoload (ice-9 popen) (open-pipe* close-pipe)
  79. #:autoload (guix parameters) (all-spec-parameters-with-types package-parameter-spec)
  80. #:autoload (system repl repl) (start-repl)
  81. #:autoload (system repl debug) (make-debug stack->vector)
  82. #:use-module (texinfo)
  83. #:use-module (texinfo plain-text)
  84. #:use-module (texinfo string-utils)
  85. ;; Re-exports for backward compatibility.
  86. #:re-export (G_ N_ P_ ;now in (guix i18n)
  87. warning info report-error leave ;now in (guix diagnostics)
  88. location->string
  89. guix-warning-port program-name)
  90. #:export (display-hint
  91. make-user-module
  92. load*
  93. warn-about-load-error
  94. show-version-and-exit
  95. show-bug-report-information
  96. make-regexp*
  97. string->number*
  98. size->number
  99. show-derivation-outputs
  100. build-notifier
  101. show-what-to-build
  102. show-what-to-build*
  103. show-manifest-transaction
  104. guard*
  105. call-with-error-handling
  106. with-error-handling
  107. with-unbound-variable-handling
  108. leave-on-EPIPE
  109. read/eval
  110. read/eval-package-expression
  111. check-available-space
  112. indented-string
  113. fill-paragraph
  114. %text-width
  115. texi->plain-text
  116. package-description-string
  117. package-synopsis-string
  118. string->recutils
  119. package->recutils
  120. package-specification->name+version+output
  121. pager-wrapped-port
  122. with-paginated-output-port
  123. relevance
  124. package-relevance
  125. display-search-results
  126. with-profile-lock
  127. string->generations
  128. string->duration
  129. matching-generations
  130. display-generation
  131. display-profile-content
  132. display-profile-content-diff
  133. roll-back*
  134. switch-to-generation*
  135. delete-generation*
  136. %default-message-language
  137. current-message-language
  138. run-guix-command
  139. run-guix
  140. guix-main))
  141. ;;; Commentary:
  142. ;;;
  143. ;;; User interface facilities for command-line tools.
  144. ;;;
  145. ;;; Code:
  146. (define (print-unbound-variable-error port key args default-printer)
  147. ;; Print unbound variable errors more nicely, and in the right language.
  148. (match args
  149. ((proc message (variable) _ ...)
  150. ;; We can always omit PROC because when it's useful (i.e., different from
  151. ;; "module-lookup"), it gets displayed before.
  152. (format port (G_ "error: ~a: unbound variable") variable))
  153. (_
  154. (default-printer))))
  155. (set-exception-printer! 'unbound-variable print-unbound-variable-error)
  156. (define (make-user-module modules)
  157. "Return a new user module with the additional MODULES loaded."
  158. ;; Module in which the machine description file is loaded.
  159. (let ((module (make-fresh-user-module)))
  160. (for-each (lambda (iface)
  161. (module-use! module (resolve-interface iface)))
  162. modules)
  163. module))
  164. (define (last-frame-with-source stack)
  165. "Walk stack upwards and return the last frame that has source location
  166. information, or #f if it could not be found."
  167. (define (frame-with-source frame)
  168. ;; Walk from FRAME upwards until source location information is found.
  169. (let loop ((frame frame)
  170. (previous frame))
  171. (if (not frame)
  172. previous
  173. ;; On Guile 3, the latest frame with source may be that of
  174. ;; 'raise-exception' in boot-9.scm. Skip it.
  175. (if (and (frame-source frame)
  176. (not (eq? 'raise-exception (frame-procedure-name frame))))
  177. frame
  178. (loop (frame-previous frame) frame)))))
  179. (let* ((depth (stack-length stack))
  180. (last (and (> depth 0) (stack-ref stack 0))))
  181. (frame-with-source (if (> depth 1)
  182. (stack-ref stack 1) ;skip the 'throw' frame
  183. last))))
  184. (define-syntax-rule (without-compiler-optimizations exp)
  185. ;; Compile with the baseline compiler (-O1), which is much less expensive
  186. ;; than -O2.
  187. (parameterize (((@ (system base compile) default-optimization-level) 1))
  188. exp))
  189. (define (try-canonicalize-path file)
  190. "Like 'canonicalize-path', but return FILE as-is if 'canonicalize-path'
  191. throws.
  192. This is necessary for corner cases where 'canonicalize-path' fails. One
  193. example is on Linux when a /dev/fd/N file denotes a pipe, represented as a
  194. symlink to a non-existent file like 'pipe:[1234]', as in this example:
  195. sh -c 'stat $(readlink -f /dev/fd/1)' | cat"
  196. (catch 'system-error
  197. (lambda ()
  198. (canonicalize-path file))
  199. (const file)))
  200. (define* (load* file user-module
  201. #:key (on-error 'nothing-special))
  202. "Load the user provided Scheme source code FILE."
  203. (define (error-string frame args)
  204. (call-with-output-string
  205. (lambda (port)
  206. (apply display-error frame port (cdr args)))))
  207. (define tag
  208. (make-prompt-tag "user-code"))
  209. (catch #t
  210. (lambda ()
  211. ;; XXX: Force a recompilation to avoid ABI issues.
  212. (set! %fresh-auto-compile #t)
  213. (set! %load-should-auto-compile #t)
  214. (save-module-excursion
  215. (lambda ()
  216. (set-current-module user-module)
  217. ;; Hide the "auto-compiling" messages.
  218. (parameterize ((current-warning-port (%make-void-port "w")))
  219. (call-with-prompt tag
  220. (lambda ()
  221. ;; Give 'load' an absolute file name so that it doesn't try to
  222. ;; search for FILE in %LOAD-PATH. Note: use 'load', not
  223. ;; 'primitive-load', so that FILE is compiled, which then allows
  224. ;; us to provide better error reporting with source line numbers.
  225. (without-compiler-optimizations
  226. (load (try-canonicalize-path file))))
  227. (const #f))))))
  228. (lambda _
  229. ;; XXX: Errors are reported from the pre-unwind handler below, but
  230. ;; calling 'exit' from there has no effect, so we call it here.
  231. (exit 1))
  232. (rec (handle-error . args)
  233. ;; Capture the stack up to this procedure call, excluded, and pass
  234. ;; the faulty stack frame to 'report-load-error'.
  235. (let* ((stack (make-stack #t handle-error tag))
  236. (frame (last-frame-with-source stack)))
  237. (report-load-error file args frame)
  238. (case on-error
  239. ((debug)
  240. (newline)
  241. (display (G_ "entering debugger; type ',bt' for a backtrace\n"))
  242. (start-repl #:debug (make-debug (stack->vector stack) 0
  243. (error-string frame args)
  244. #f)))
  245. ((backtrace)
  246. (newline (current-error-port))
  247. (display-backtrace stack (current-error-port)))
  248. (else
  249. #t))))))
  250. (define (known-variable-definition variable)
  251. "Search among the currently loaded modules one that defines a variable named
  252. VARIABLE and return it, or #f if none was found."
  253. (define (module<? m1 m2)
  254. (match (module-name m2)
  255. (('gnu _ ...) #t)
  256. (('guix _ ...)
  257. (match (module-name m1)
  258. (('gnu _ ...) #f)
  259. (_ #t)))
  260. (_ #f)))
  261. (let loop ((modules (list (resolve-module '() #f #f #:ensure #f)))
  262. (suggestions '())
  263. (visited (setq)))
  264. (match modules
  265. (()
  266. ;; Pick the "best" suggestion.
  267. (match (sort suggestions module<?)
  268. (() #f)
  269. ((first _ ...) first)))
  270. ((head tail ...)
  271. (if (set-contains? visited head)
  272. (loop tail suggestions visited)
  273. (let ((visited (set-insert head visited))
  274. (next (append tail
  275. (hash-map->list (lambda (name module)
  276. module)
  277. (module-submodules head)))))
  278. (match (and=> (module-public-interface head)
  279. (cut module-local-variable <> variable))
  280. (#f (loop next suggestions visited))
  281. (_
  282. (match (module-name head)
  283. (('gnu _ ...) head) ;must be that one
  284. (_ (loop next (cons head suggestions) visited)))))))))))
  285. (define %hint-color (color BOLD CYAN))
  286. (define (texinfo-quote str)
  287. "Quote at signs and braces in STR to obtain its Texinfo represention."
  288. (list->string
  289. (string-fold-right (lambda (chr result)
  290. (if (memq chr '(#\@ #\{ #\}))
  291. (cons* #\@ chr result)
  292. (cons chr result)))
  293. '()
  294. str)))
  295. (define* (display-hint message
  296. #:key (port (current-error-port))
  297. #:rest arguments)
  298. "Display MESSAGE, a l10n message possibly containing Texinfo markup and
  299. 'format' escape, to PORT. ARGUMENTS is a (possibly empty) list of strings or
  300. other objects that must match the 'format' escapes in MESSAGE."
  301. (define colorize
  302. (if (color-output? port)
  303. (lambda (str)
  304. (colorize-string str %hint-color))
  305. identity))
  306. (display (colorize (G_ "hint: ")) port)
  307. (display
  308. ;; XXX: We should arrange so that the initial indent is wider.
  309. (parameterize ((%text-width (max 15 (- (terminal-columns) 5))))
  310. (texi->plain-text (match arguments
  311. (() (format #f message))
  312. (_ (apply format #f message
  313. (map (match-lambda
  314. ((? string? str)
  315. (texinfo-quote str))
  316. (obj
  317. (texinfo-quote
  318. (object->string obj))))
  319. arguments))))))
  320. port))
  321. (define* (report-unbound-variable-error args #:key frame)
  322. "Return the given unbound-variable error, where ARGS is the list of 'throw'
  323. arguments."
  324. (match args
  325. ((key . args)
  326. (print-exception (current-error-port) frame key args)))
  327. (match args
  328. (('unbound-variable proc message (variable) _ ...)
  329. (match (known-variable-definition variable)
  330. (#f
  331. (display-hint (G_ "Did you forget a @code{use-modules} form?")))
  332. ((? module? module)
  333. (display-hint (G_ "Did you forget @code{(use-modules ~a)}?")
  334. (module-name module)))))))
  335. (define (check-module-matches-file module file)
  336. "Check whether FILE starts with 'define-module MODULE' and print a hint if
  337. it doesn't."
  338. ;; This is a common mistake when people start writing their own package
  339. ;; definitions and try loading them with 'guix build -L …', so help them
  340. ;; diagnose the problem.
  341. (define (hint)
  342. (display-hint (G_ "File @file{~a} should probably start with:
  343. @example\n(define-module ~a)\n@end example")
  344. file module))
  345. (catch 'system-error
  346. (lambda ()
  347. (let* ((sexp (call-with-input-file file read))
  348. (loc (and (pair? sexp)
  349. (source-properties->location (source-properties sexp)))))
  350. (match sexp
  351. (('define-module (names ...) _ ...)
  352. (unless (equal? module names)
  353. (warning loc
  354. (G_ "module name ~a does not match file name '~a'~%")
  355. names (module->source-file-name module))
  356. (hint)))
  357. ((? eof-object?)
  358. (warning (G_ "~a: file is empty~%") file))
  359. (else
  360. (hint)))))
  361. (const #f)))
  362. (define* (report-load-error file args #:optional frame)
  363. "Report the failure to load FILE, a user-provided Scheme file.
  364. ARGS is the list of arguments received by the 'throw' handler."
  365. (match args
  366. (('system-error . rest)
  367. (let ((err (system-error-errno args)))
  368. (report-error (G_ "failed to load '~a': ~a~%") file (strerror err))))
  369. (('read-error _ message args ...)
  370. ;; Guile's missing-paren messages are obscure so we make them more
  371. ;; intelligible here.
  372. (if (or (string-suffix? "end of file" message) ;Guile < 3.0.6
  373. (and (string-contains message "unexpected end of input")
  374. (member '(#\)) args)))
  375. (let ((location (string-take message
  376. (+ 2 (string-contains message ": ")))))
  377. (format (current-error-port) (G_ "~amissing closing parenthesis~%")
  378. location))
  379. (report-error (G_ "read error while loading '~a': ~a~%")
  380. file (apply format #f message args))))
  381. (('syntax-error proc message properties form subform . rest)
  382. (let ((loc (source-properties->location properties)))
  383. (report-error loc (G_ "~s: ~a~%")
  384. (or subform form) message)))
  385. (('unbound-variable _ ...)
  386. (report-unbound-variable-error args #:frame frame))
  387. (((or 'srfi-34 '%exception) obj)
  388. (cond ((message-condition? obj)
  389. (report-error (and (error-location? obj)
  390. (error-location obj))
  391. (G_ "~a~%")
  392. (gettext (condition-message obj) %gettext-domain)))
  393. ((formatted-message? obj)
  394. (apply report-error
  395. (and (error-location? obj) (error-location obj))
  396. (gettext (formatted-message-string obj) %gettext-domain)
  397. (formatted-message-arguments obj)))
  398. (else
  399. (report-error (G_ "exception thrown: ~s~%") obj)))
  400. (when (fix-hint? obj)
  401. (display-hint (condition-fix-hint obj))))
  402. ((key args ...)
  403. (report-error (G_ "failed to load '~a':~%") file)
  404. (match args
  405. (((? symbol? proc) (? string? message) (args ...) . rest)
  406. (display-error frame (current-error-port) proc message
  407. args rest))
  408. (_
  409. ;; Some exceptions like 'git-error' do not follow Guile's convention
  410. ;; above and need to be printed with 'print-exception'.
  411. (print-exception (current-error-port) frame key args))))))
  412. (define (warn-about-load-error file module args) ;FIXME: factorize with ↑
  413. "Report the failure to load FILE, a user-provided Scheme file, without
  414. exiting. ARGS is the list of arguments received by the 'throw' handler."
  415. (match args
  416. (('system-error . rest)
  417. (let ((err (system-error-errno args)))
  418. (warning (G_ "failed to load '~a': ~a~%") module (strerror err))))
  419. (('syntax-error proc message properties form . rest)
  420. (let ((loc (source-properties->location properties)))
  421. (warning loc (G_ "~a~%") message)))
  422. (('unbound-variable _ ...)
  423. (report-unbound-variable-error args))
  424. (((or 'srfi-34 '%exception) obj)
  425. (cond ((message-condition? obj)
  426. (warning (G_ "failed to load '~a': ~a~%")
  427. file
  428. (gettext (condition-message obj) %gettext-domain)))
  429. ((formatted-message? obj)
  430. (warning (G_ "failed to load '~a': ~a~%")
  431. file
  432. (apply format #f
  433. (gettext (formatted-message-string obj)
  434. %gettext-domain)
  435. (formatted-message-arguments obj))))
  436. (else
  437. (warning (G_ "failed to load '~a': exception thrown: ~s~%")
  438. file obj))))
  439. ((error args ...)
  440. (warning (G_ "failed to load '~a':~%") module)
  441. (apply display-error #f (current-error-port) args)
  442. (check-module-matches-file module file))))
  443. (define (call-with-unbound-variable-handling thunk)
  444. (define tag
  445. (make-prompt-tag "user-code"))
  446. (catch 'unbound-variable
  447. (lambda ()
  448. (call-with-prompt tag
  449. thunk
  450. (const #f)))
  451. (const #t)
  452. (rec (handle-error . args)
  453. (let* ((stack (make-stack #t handle-error tag))
  454. (frame (and stack (last-frame-with-source stack))))
  455. (report-unbound-variable-error args #:frame frame)
  456. (exit 1)))))
  457. (define-syntax-rule (with-unbound-variable-handling exp ...)
  458. "Capture 'unbound-variable' exceptions in the dynamic extent of EXP... and
  459. report them in a user-friendly way."
  460. (call-with-unbound-variable-handling (lambda () exp ...)))
  461. (define %default-message-language
  462. ;; Default language to use for messages.
  463. (make-parameter "en"))
  464. (define (current-message-language)
  465. "Return the language used for messages according to the current locale.
  466. Return %DEFAULT-MESSAGE-LANGUAGE if that information could not be obtained. The
  467. result is an ISO-639-2 language code such as \"ar\", without the territory
  468. part."
  469. (let ((locale (setlocale LC_MESSAGES)))
  470. (match (string-index locale #\_)
  471. (#f locale)
  472. (index (string-take locale index)))))
  473. (define (install-locale)
  474. "Install the current locale settings."
  475. (catch 'system-error
  476. (lambda _
  477. (setlocale LC_ALL ""))
  478. (lambda args
  479. (display-hint (G_ "Consider installing the @code{glibc-locales} package
  480. and defining @code{GUIX_LOCPATH}, along these lines:
  481. @example
  482. guix install glibc-locales
  483. export GUIX_LOCPATH=\"$HOME/.guix-profile/lib/locale\"
  484. @end example
  485. See the \"Application Setup\" section in the manual, for more info.\n"))
  486. ;; We're now running in the "C" locale. Try to install a UTF-8 locale
  487. ;; instead. This one is guaranteed to be available in 'guix' from 'guix
  488. ;; pull'.
  489. (false-if-exception (setlocale LC_ALL "en_US.utf8")))))
  490. (define (initialize-guix)
  491. "Perform the usual initialization for stand-alone Guix commands."
  492. ;; By default don't annoy users with deprecation warnings. In practice,
  493. ;; 'define-deprecated' in (ice-9 deprecated) arranges so that those warnings
  494. ;; are emitted at expansion-time only, but there are cases where they could
  495. ;; slip through, for instance when interpreting code.
  496. (unless (getenv "GUILE_WARN_DEPRECATED")
  497. (debug-disable 'warn-deprecated))
  498. (install-locale)
  499. (textdomain %gettext-domain)
  500. ;; Ignore SIGPIPE. If the daemon closes the connection, we prefer to be
  501. ;; notified via an EPIPE later.
  502. (sigaction SIGPIPE SIG_IGN)
  503. (setvbuf (current-output-port) 'line)
  504. (setvbuf (current-error-port) 'line))
  505. (define* (show-version-and-exit #:optional (command (car (command-line))))
  506. "Display version information for COMMAND and `(exit 0)'."
  507. (simple-format #t "~a (~a) ~a~%"
  508. command %guix-package-name %guix-version)
  509. (format #t "Copyright ~a 2023 ~a"
  510. ;; TRANSLATORS: Translate "(C)" to the copyright symbol
  511. ;; (C-in-a-circle), if this symbol is available in the user's
  512. ;; locale. Otherwise, do not translate "(C)"; leave it as-is. */
  513. (G_ "(C)")
  514. (G_ "the Guix authors\n"))
  515. (display (G_"\
  516. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  517. This is free software: you are free to change and redistribute it.
  518. There is NO WARRANTY, to the extent permitted by law.
  519. "))
  520. (exit 0))
  521. (define (show-bug-report-information)
  522. ;; TRANSLATORS: The placeholder indicates the bug-reporting address for this
  523. ;; package. Please add another line saying "Report translation bugs to
  524. ;; ...\n" with the address for translation bugs (typically your translation
  525. ;; team's web or email address).
  526. (format #t (G_ "
  527. Report bugs to: ~a.") %guix-bug-report-address)
  528. (format #t (G_ "
  529. ~a home page: <~a>") %guix-package-name %guix-home-page-url)
  530. (format #t (G_ "
  531. General help using Guix and GNU software: <~a>")
  532. ;; TRANSLATORS: Change the "/en" bit of this URL appropriately if
  533. ;; the web site is translated in your language.
  534. (G_ "https://guix.gnu.org/en/help/"))
  535. (newline))
  536. (define (augmented-system-error-handler file)
  537. "Return a 'system-error' handler that mentions FILE in its message."
  538. (lambda (key proc fmt args errno)
  539. ;; Augment the FMT and ARGS with information about TARGET (this
  540. ;; information is missing as of Guile 2.0.11, making the exception
  541. ;; uninformative.)
  542. (apply throw key proc "~A: ~S"
  543. (list (strerror (car errno)) file)
  544. (list errno))))
  545. (define-syntax apply-formals
  546. (syntax-rules ()
  547. ((_ proc (args ...)) (proc args ...))
  548. ((_ proc (arg1 args ... . rest)) (apply proc arg1 args ... rest))))
  549. (define-syntax-rule (error-reporting-wrapper proc formals file)
  550. "Wrap PROC such that its 'system-error' exceptions are augmented to mention
  551. FILE."
  552. (let ((real-proc (@ (guile) proc)))
  553. (lambda formals
  554. (catch 'system-error
  555. (lambda ()
  556. (apply-formals real-proc formals))
  557. (augmented-system-error-handler file)))))
  558. (set! symlink
  559. ;; We 'set!' the global binding because (gnu build ...) modules and similar
  560. ;; typically don't use (guix ui).
  561. (error-reporting-wrapper symlink (source target) target))
  562. (set! copy-file
  563. ;; Note: here we use 'set!', not #:replace, because UIs typically use
  564. ;; 'copy-recursively', which doesn't use (guix ui).
  565. (error-reporting-wrapper copy-file (source target) target))
  566. (set! canonicalize-path
  567. (error-reporting-wrapper canonicalize-path (file) file))
  568. (set! delete-file
  569. (error-reporting-wrapper delete-file (file) file))
  570. (set! execlp
  571. (error-reporting-wrapper execlp (filename . args) filename))
  572. (set! mkdir
  573. (error-reporting-wrapper mkdir (directory . args) directory))
  574. (define (make-regexp* regexp . flags)
  575. "Like 'make-regexp' but error out if REGEXP is invalid, reporting the error
  576. nicely."
  577. (catch 'regular-expression-syntax
  578. (lambda ()
  579. (apply make-regexp regexp flags))
  580. (lambda (key proc message . rest)
  581. (leave (G_ "'~a' is not a valid regular expression: ~a~%")
  582. regexp message))))
  583. (define (string->number* str)
  584. "Like `string->number', but error out with an error message on failure."
  585. (or (string->number str)
  586. (leave (G_ "~a: invalid number~%") str)))
  587. (define (size->number str)
  588. "Convert STR, a storage measurement representation such as \"1024\" or
  589. \"1MiB\", to a number of bytes. Raise an error if STR could not be
  590. interpreted."
  591. (define unit-pos
  592. (string-rindex str
  593. (char-set-union (char-set #\.) char-set:digit)))
  594. (define unit
  595. (and unit-pos (substring str (+ 1 unit-pos))))
  596. (let* ((numstr (if unit-pos
  597. (substring str 0 (+ 1 unit-pos))
  598. str))
  599. (num (string->number numstr)))
  600. (unless num
  601. (leave (G_ "invalid number: ~a~%") numstr))
  602. ((compose inexact->exact round)
  603. (* num
  604. (match unit
  605. ((or "KiB" "K" "k") (expt 2 10))
  606. ((or "MiB" "M") (expt 2 20))
  607. ((or "GiB" "G") (expt 2 30))
  608. ((or "TiB" "T") (expt 2 40))
  609. ((or "PiB" "P") (expt 2 50))
  610. ((or "EiB" "E") (expt 2 60))
  611. ((or "ZiB" "Z") (expt 2 70))
  612. ((or "YiB" "Y") (expt 2 80))
  613. ("kB" (expt 10 3))
  614. ("MB" (expt 10 6))
  615. ("GB" (expt 10 9))
  616. ("TB" (expt 10 12))
  617. ("PB" (expt 10 15))
  618. ("EB" (expt 10 18))
  619. ("ZB" (expt 10 21))
  620. ("YB" (expt 10 24))
  621. ("" 1)
  622. (x
  623. (leave (G_ "unknown unit: ~a~%") unit)))))))
  624. (define (display-collision-resolution-hint collision)
  625. "Display hints on how to resolve COLLISION, a &profile-collistion-error."
  626. (define (top-most-entry entry)
  627. (let loop ((entry entry))
  628. (match (force (manifest-entry-parent entry))
  629. (#f entry)
  630. (parent (loop parent)))))
  631. (let* ((first (profile-collision-error-entry collision))
  632. (second (profile-collision-error-conflict collision))
  633. (name1 (manifest-entry-name (top-most-entry first)))
  634. (name2 (manifest-entry-name (top-most-entry second))))
  635. (if (string=? name1 name2)
  636. (display-hint (G_ "You cannot have two different versions
  637. or variants of @code{~a} in the same profile.")
  638. name1)
  639. (display-hint (G_ "Try upgrading both @code{~a} and @code{~a},
  640. or remove one of them from the profile.")
  641. name1 name2))))
  642. ;; On Guile 3.0, in 'call-with-error-handling' we need to re-raise. To
  643. ;; preserve useful backtraces in case of unhandled errors, we want that to
  644. ;; happen before the stack has been unwound, hence 'guard*'.
  645. (define-syntax-rule (guard* (var clauses ...) exp ...)
  646. "This variant of SRFI-34 'guard' does not unwind the stack before
  647. evaluating the tests and bodies of CLAUSES."
  648. (with-exception-handler
  649. (lambda (var)
  650. (cond clauses ... (else (raise var))))
  651. (lambda () exp ...)
  652. #:unwind? #f))
  653. (define (call-with-error-handling thunk)
  654. "Call THUNK within a user-friendly error handler."
  655. (define (port-filename* port)
  656. ;; 'port-filename' returns #f for non-file ports, but it raises an
  657. ;; exception for file ports that are closed. Work around that.
  658. (and (not (port-closed? port))
  659. (port-filename port)))
  660. (guard* (c ((package-input-error? c)
  661. (let* ((package (package-error-package c))
  662. (input (package-error-invalid-input c))
  663. (location (package-location package))
  664. (file (location-file location))
  665. (line (location-line location))
  666. (column (location-column location)))
  667. (leave (G_ "~a:~a:~a: package `~a' has an invalid input: ~s~%")
  668. file line column
  669. (package-full-name package) input)))
  670. ((package-cyclic-dependency-error? c)
  671. (let ((package (package-error-package c)))
  672. (leave (package-location package)
  673. (G_ "~a: dependency cycle detected:
  674. ~a~{ -> ~a~}~%")
  675. (package-full-name package)
  676. (package-full-name package)
  677. (map package-full-name
  678. (package-error-dependency-cycle c)))))
  679. ((package-cross-build-system-error? c)
  680. (let* ((package (package-error-package c))
  681. (loc (package-location package))
  682. (system (package-build-system package)))
  683. (leave (G_ "~a: ~a: build system `~a' does not support cross builds~%")
  684. (location->string loc)
  685. (package-full-name package)
  686. (build-system-name system))))
  687. ((gexp-input-error? c)
  688. (let ((input (gexp-error-invalid-input c)))
  689. (leave (G_ "~s: invalid G-expression input~%")
  690. (gexp-error-invalid-input c))))
  691. ((profile-not-found-error? c)
  692. (leave (G_ "profile '~a' does not exist~%")
  693. (profile-error-profile c)))
  694. ((missing-generation-error? c)
  695. (leave (G_ "generation ~a of profile '~a' does not exist~%")
  696. (missing-generation-error-generation c)
  697. (profile-error-profile c)))
  698. ((unmatched-pattern-error? c)
  699. (let ((pattern (unmatched-pattern-error-pattern c)))
  700. (leave (G_ "package '~a~@[@~a~]~@[:~a~]' not found in profile~%")
  701. (manifest-pattern-name pattern)
  702. (manifest-pattern-version pattern)
  703. (match (manifest-pattern-output pattern)
  704. ("out" #f)
  705. (output output)))))
  706. ((profile-collision-error? c)
  707. (let ((entry (profile-collision-error-entry c))
  708. (conflict (profile-collision-error-conflict c)))
  709. (define (report-parent-entries entry)
  710. (let ((parent (force (manifest-entry-parent entry))))
  711. (when (manifest-entry? parent)
  712. (report-error (G_ " ... propagated from ~a@~a~%")
  713. (manifest-entry-name parent)
  714. (manifest-entry-version parent))
  715. (report-parent-entries parent))))
  716. (define (manifest-entry-output* entry)
  717. (match (manifest-entry-output entry)
  718. ("out" "")
  719. (output (string-append ":" output))))
  720. (report-error (G_ "profile contains conflicting entries for ~a~a~%")
  721. (manifest-entry-name entry)
  722. (manifest-entry-output* entry))
  723. (report-error (G_ " first entry: ~a@~a~a ~a~%")
  724. (manifest-entry-name entry)
  725. (manifest-entry-version entry)
  726. (manifest-entry-output* entry)
  727. (manifest-entry-item entry))
  728. (report-parent-entries entry)
  729. (report-error (G_ " second entry: ~a@~a~a ~a~%")
  730. (manifest-entry-name conflict)
  731. (manifest-entry-version conflict)
  732. (manifest-entry-output* conflict)
  733. (manifest-entry-item conflict))
  734. (report-parent-entries conflict)
  735. (display-collision-resolution-hint c)
  736. (exit 1)))
  737. ((nar-error? c)
  738. (let ((file (nar-error-file c))
  739. (port (nar-error-port c)))
  740. (if file
  741. (leave (G_ "corrupt input while restoring '~a' from ~s~%")
  742. file (or (port-filename* port) port))
  743. (leave (G_ "corrupt input while restoring archive from ~s~%")
  744. (or (port-filename* port) port)))))
  745. ((store-connection-error? c)
  746. (leave (G_ "failed to connect to `~a': ~a~%")
  747. (store-connection-error-file c)
  748. (strerror (store-connection-error-code c))))
  749. ((store-protocol-error? c)
  750. ;; FIXME: Server-provided error messages aren't i18n'd.
  751. (leave (G_ "~a~%")
  752. (store-protocol-error-message c)))
  753. ((derivation-missing-output-error? c)
  754. (leave (G_ "reference to invalid output '~a' of derivation '~a'~%")
  755. (derivation-missing-output c)
  756. (derivation-file-name (derivation-error-derivation c))))
  757. ((file-search-error? c)
  758. (leave (G_ "file '~a' could not be found in these \
  759. directories:~{ ~a~}~%")
  760. (file-search-error-file-name c)
  761. (file-search-error-search-path c)))
  762. ((invoke-error? c)
  763. (leave (G_ "program exited\
  764. ~@[ with non-zero exit status ~a~]\
  765. ~@[ terminated by signal ~a~]\
  766. ~@[ stopped by signal ~a~]: ~s~%")
  767. (invoke-error-exit-status c)
  768. (invoke-error-term-signal c)
  769. (invoke-error-stop-signal c)
  770. (cons (invoke-error-program c)
  771. (invoke-error-arguments c))))
  772. ((formatted-message? c)
  773. (apply report-error
  774. (and (error-location? c) (error-location c))
  775. (gettext (formatted-message-string c) %gettext-domain)
  776. (formatted-message-arguments c))
  777. (when (fix-hint? c)
  778. (display-hint (condition-fix-hint c)))
  779. (exit 1))
  780. ;; On Guile 3.0.0, exceptions such as 'unbound-variable' are
  781. ;; compound and include a '&message'. However, that message only
  782. ;; contains the format string. Thus, special-case it here to
  783. ;; avoid displaying a bare format string.
  784. ;;
  785. ;; Furthermore, use of 'guard*' ensures that the stack has not
  786. ;; been unwound when we re-raise, since that would otherwise show
  787. ;; useless backtraces.
  788. (((exception-predicate &exception-with-kind-and-args) c)
  789. (if (eq? 'system-error (exception-kind c)) ;EPIPE & co.
  790. (match (exception-args c)
  791. ((proc format-string format-args . _)
  792. (leave (G_ "~a: ~a~%") proc
  793. (apply format #f format-string format-args))))
  794. (raise c)))
  795. ((message-condition? c)
  796. ;; Normally '&message' error conditions have an i18n'd message.
  797. (report-error (and (error-location? c) (error-location c))
  798. (G_ "~a~%")
  799. (gettext (condition-message c) %gettext-domain))
  800. (when (fix-hint? c)
  801. (display-hint (condition-fix-hint c)))
  802. (exit 1)))
  803. (thunk)))
  804. (define-syntax-rule (leave-on-EPIPE exp ...)
  805. "Run EXP... in a context where EPIPE errors are caught and lead to 'exit'
  806. with successful exit code. This is useful when writing to the standard output
  807. may lead to EPIPE, because the standard output is piped through 'head' or
  808. similar."
  809. (catch 'system-error
  810. (lambda ()
  811. exp ...)
  812. (lambda args
  813. ;; We really have to exit this brutally, otherwise Guile eventually
  814. ;; attempts to flush all the ports, leading to an uncaught EPIPE down
  815. ;; the path.
  816. (if (= EPIPE (system-error-errno args))
  817. (primitive-_exit 0)
  818. (apply throw args)))))
  819. (define %guix-user-module
  820. ;; Module in which user expressions are evaluated.
  821. ;; Compute lazily to avoid circularity with (guix gexp).
  822. (delay
  823. (let ((module (make-module)))
  824. (beautify-user-module! module)
  825. ;; Use (guix gexp) so that one can use #~ & co.
  826. (module-use! module (resolve-interface '(guix gexp)))
  827. module)))
  828. (define (read/eval str)
  829. "Read and evaluate STR, raising an error if something goes wrong."
  830. (let ((exp (catch #t
  831. (lambda ()
  832. (call-with-input-string str read))
  833. (lambda args
  834. (leave (G_ "failed to read expression ~s: ~s~%")
  835. str args)))))
  836. (catch #t
  837. (lambda ()
  838. (eval exp (force %guix-user-module)))
  839. (lambda args
  840. (report-error (G_ "failed to evaluate expression '~a':~%") exp)
  841. (match args
  842. (('syntax-error proc message properties form . rest)
  843. (report-error (G_ "syntax error: ~a~%") message))
  844. (((or 'srfi-34 '%exception) obj)
  845. (cond ((message-condition? obj)
  846. (report-error (G_ "~a~%")
  847. (gettext (condition-message obj)
  848. %gettext-domain)))
  849. ((formatted-message? obj)
  850. (apply report-error #f
  851. (gettext (formatted-message-string obj)
  852. %gettext-domain)
  853. (formatted-message-arguments obj)))
  854. (else
  855. (report-error (G_ "exception thrown: ~s~%") obj))))
  856. ((error args ...)
  857. (apply display-error #f (current-error-port) args))
  858. (what? #f))
  859. (exit 1)))))
  860. (define (read/eval-package-expression str)
  861. "Read and evaluate STR and return the package it refers to, or exit an
  862. error."
  863. (match (read/eval str)
  864. ((? package? p) p)
  865. (x
  866. (leave (G_ "expression ~s does not evaluate to a package~%")
  867. str))))
  868. (define (show-derivation-outputs derivation)
  869. "Show the output file names of DERIVATION, which can be a derivation or a
  870. derivation input."
  871. (define (show-outputs derivation outputs)
  872. (format #t "~{~a~%~}"
  873. (map (cut derivation->output-path derivation <>)
  874. outputs)))
  875. (match derivation
  876. ((? derivation?)
  877. (show-outputs derivation (derivation-output-names derivation)))
  878. ((? derivation-input? input)
  879. (show-outputs (derivation-input-derivation input)
  880. (derivation-input-sub-derivations input)))))
  881. (define* (check-available-space need
  882. #:optional (directory (%store-prefix)))
  883. "Make sure at least NEED bytes are available in DIRECTORY. Otherwise emit a
  884. warning."
  885. (let ((free (catch 'system-error
  886. (lambda ()
  887. (free-disk-space directory))
  888. (const #f))))
  889. (when (and free (>= need free))
  890. (warning (G_ "at least ~,1h MB needed but only ~,1h MB available in ~a~%")
  891. (/ need 1e6) (/ free 1e6) directory))))
  892. (define (graft-derivation? drv)
  893. "Return true if DRV is definitely a graft derivation, false otherwise."
  894. (match (assq-ref (derivation-properties drv) 'type)
  895. ('graft #t)
  896. (_ #f)))
  897. (define (profile-hook-derivation? drv)
  898. "Return true if DRV is definitely a profile hook derivation, false otherwise."
  899. (match (assq-ref (derivation-properties drv) 'type)
  900. ('profile-hook #t)
  901. (_ #f)))
  902. (define (colorize-store-file-name file)
  903. "Colorize FILE, a store file name, such that the hash part is less prominent
  904. than the rest."
  905. (let ((len (string-length file))
  906. (prefix (+ (string-length (%store-prefix)) 32 2)))
  907. (if (< len prefix)
  908. file
  909. (string-append (colorize-string (string-take file prefix)
  910. (color DARK))
  911. (string-drop file prefix)))))
  912. (define %default-verbosity
  913. ;; Default verbosity level for 'show-what-to-build'.
  914. 2)
  915. (define* (show-what-to-build store drv
  916. #:key dry-run? (use-substitutes? #t)
  917. (verbosity %default-verbosity)
  918. (mode (build-mode normal)))
  919. "Show what will or would (depending on DRY-RUN?) be built in realizing the
  920. derivations listed in DRV using MODE, a 'build-mode' value. The elements of
  921. DRV can be either derivations or derivation inputs.
  922. Return two values: a Boolean indicating whether there's something to build,
  923. and a Boolean indicating whether there's something to download.
  924. When USE-SUBSTITUTES?, check and report what is prerequisites are available
  925. for download. VERBOSITY is an integer indicating the level of details to be
  926. shown: level 2 and higher provide all the details, level 1 shows a high-level
  927. summary, and level 0 shows nothing."
  928. (define inputs
  929. (map (match-lambda
  930. ((? derivation? drv) (derivation-input drv))
  931. ((? derivation-input? input) input))
  932. drv))
  933. (define substitutable-info
  934. ;; Call 'substitution-oracle' upfront so we don't end up launching the
  935. ;; substituter many times. This makes a big difference, especially when
  936. ;; DRV is a long list as is the case with 'guix environment'.
  937. (if use-substitutes?
  938. (substitution-oracle store inputs #:mode mode)
  939. (const #f)))
  940. (define colorized-store-item
  941. (if (color-output? (current-error-port))
  942. colorize-store-file-name
  943. identity))
  944. (let*-values (((build/full download)
  945. (derivation-build-plan store inputs
  946. #:mode mode
  947. #:substitutable-info
  948. substitutable-info))
  949. ((graft hook build)
  950. (match (fold (lambda (drv acc)
  951. (let ((file (derivation-file-name drv)))
  952. (match acc
  953. ((#:graft graft #:hook hook #:build build)
  954. (cond
  955. ((graft-derivation? drv)
  956. `(#:graft ,(cons file graft)
  957. #:hook ,hook
  958. #:build ,build))
  959. ((profile-hook-derivation? drv)
  960. `(#:graft ,graft
  961. #:hook ,(cons file hook)
  962. #:build ,build))
  963. (else
  964. `(#:graft ,graft
  965. #:hook ,hook
  966. #:build ,(cons file build))))))))
  967. '(#:graft () #:hook () #:build ())
  968. build/full)
  969. ((#:graft graft #:hook hook #:build build)
  970. (values graft hook build)))))
  971. (define installed-size
  972. (reduce + 0 (map substitutable-nar-size download)))
  973. (define download-size
  974. (/ (reduce + 0 (map substitutable-download-size download))
  975. 1e6))
  976. (define display-download-size?
  977. ;; Sometimes narinfos lack information about the download size. Only
  978. ;; display when we have information for all of DOWNLOAD.
  979. (not (any (compose zero? substitutable-download-size) download)))
  980. ;; Combinatorial explosion ahead along two axes: DRY-RUN? and VERBOSITY.
  981. ;; Unfortunately, this is hardly avoidable for proper i18n.
  982. (if dry-run?
  983. (begin
  984. (unless (or (zero? verbosity) (null? build))
  985. (format (current-error-port)
  986. (highlight/warn
  987. (N_ "The following derivation would be built:~%"
  988. "The following derivations would be built:~%"
  989. (length build))))
  990. (format (current-error-port) "~{ ~a~%~}"
  991. (map colorized-store-item build)))
  992. (cond ((>= verbosity 2)
  993. (if display-download-size?
  994. (begin
  995. (format (current-error-port)
  996. (highlight
  997. ;; TRANSLATORS: "MB" is for "megabyte"; it
  998. ;; should be translated to the corresponding
  999. ;; abbreviation.
  1000. (G_ "~:[~,1h MB would be downloaded:~%~;~]"))
  1001. (null? download)
  1002. download-size)
  1003. (format (current-error-port) "~{ ~a~%~}"
  1004. (map (compose colorized-store-item substitutable-path)
  1005. download)))
  1006. (begin
  1007. (format (current-error-port)
  1008. (highlight
  1009. (N_ "~:[The following file would be downloaded:~%~;~]"
  1010. "~:[The following files would be downloaded:~%~;~]"
  1011. (length download)))
  1012. (null? download))
  1013. (format (current-error-port) "~{ ~a~%~}"
  1014. (map (compose colorized-store-item substitutable-path)
  1015. download))))
  1016. (format (current-error-port)
  1017. (N_ "~:[The following graft would be made:~%~{ ~a~%~}~;~]"
  1018. "~:[The following grafts would be made:~%~{ ~a~%~}~;~]"
  1019. (length graft))
  1020. (null? graft) (map colorized-store-item graft))
  1021. (format (current-error-port)
  1022. (N_ "~:[The following profile hook would be built:~%~{ ~a~%~}~;~]"
  1023. "~:[The following profile hooks would be built:~%~{ ~a~%~}~;~]"
  1024. (length hook))
  1025. (null? hook) (map colorized-store-item hook)))
  1026. ((= verbosity 1)
  1027. ;; Display the bare minimum; don't mention grafts and hooks.
  1028. (unless (null? build)
  1029. (newline (current-error-port)))
  1030. (if display-download-size?
  1031. (format (current-error-port)
  1032. ;; TRANSLATORS: "MB" is for "megabyte"; it should be
  1033. ;; translated to the corresponding abbreviation.
  1034. (highlight (G_ "~:[~,1h MB would be downloaded~%~;~]"))
  1035. (null? download) download-size)
  1036. (format (current-error-port)
  1037. (highlight
  1038. (N_ "~:[~h item would be downloaded~%~;~]"
  1039. "~:[~h items would be downloaded~%~;~]"
  1040. (length download)))
  1041. (null? download) (length download))))))
  1042. (begin
  1043. (unless (or (zero? verbosity) (null? build))
  1044. (format (current-error-port)
  1045. (highlight/warn
  1046. (N_ "The following derivation will be built:~%"
  1047. "The following derivations will be built:~%"
  1048. (length build))))
  1049. (format (current-error-port) "~{ ~a~%~}"
  1050. (map colorized-store-item build)))
  1051. (cond ((>= verbosity 2)
  1052. (if display-download-size?
  1053. (begin
  1054. (format (current-error-port)
  1055. (highlight
  1056. ;; TRANSLATORS: "MB" is for "megabyte"; it
  1057. ;; should be translated to the corresponding
  1058. ;; abbreviation.
  1059. (G_ "~:[~,1h MB will be downloaded:~%~;~]"))
  1060. (null? download)
  1061. download-size)
  1062. (format (current-error-port) "~{ ~a~%~}"
  1063. (map (compose colorized-store-item substitutable-path)
  1064. download)))
  1065. (begin
  1066. (format (current-error-port)
  1067. (highlight
  1068. (N_ "~:[The following file will be downloaded:~%~;~]"
  1069. "~:[The following files will be downloaded:~%~;~]"
  1070. (length download)))
  1071. (null? download))
  1072. (format (current-error-port) "~{ ~a~%~}"
  1073. (map (compose colorized-store-item substitutable-path)
  1074. download))))
  1075. (format (current-error-port)
  1076. (N_ "~:[The following graft will be made:~%~{ ~a~%~}~;~]"
  1077. "~:[The following grafts will be made:~%~{ ~a~%~}~;~]"
  1078. (length graft))
  1079. (null? graft) (map colorized-store-item graft))
  1080. (format (current-error-port)
  1081. (N_ "~:[The following profile hook will be built:~%~{ ~a~%~}~;~]"
  1082. "~:[The following profile hooks will be built:~%~{ ~a~%~}~;~]"
  1083. (length hook))
  1084. (null? hook) (map colorized-store-item hook)))
  1085. ((= verbosity 1)
  1086. ;; Display the bare minimum; don't mention grafts and hooks.
  1087. (unless (null? build)
  1088. (newline (current-error-port)))
  1089. (if display-download-size?
  1090. (format (current-error-port)
  1091. ;; TRANSLATORS: "MB" is for "megabyte"; it should be
  1092. ;; translated to the corresponding abbreviation.
  1093. (highlight (G_ "~:[~,1h MB will be downloaded~%~;~]"))
  1094. (null? download) download-size)
  1095. (format (current-error-port)
  1096. (highlight
  1097. (N_ "~:[~h item will be downloaded~%~;~]"
  1098. "~:[~h items will be downloaded~%~;~]"
  1099. (length download)))
  1100. (null? download) (length download)))))))
  1101. (check-available-space installed-size)
  1102. (values (pair? build/full) (pair? download))))
  1103. (define show-what-to-build*
  1104. (store-lift show-what-to-build))
  1105. (define* (build-notifier #:key (dry-run? #f) (use-substitutes? #t)
  1106. (verbosity %default-verbosity))
  1107. "Return a procedure suitable for 'with-build-handler' that, when
  1108. 'build-things' is called, invokes 'show-what-to-build' to display the build
  1109. plan. When DRY-RUN? is true, the 'with-build-handler' form returns without
  1110. any build happening."
  1111. (define not-comma
  1112. (char-set-complement (char-set #\,)))
  1113. (define (read-derivation-from-file* item)
  1114. (catch 'system-error
  1115. (lambda ()
  1116. (read-derivation-from-file item))
  1117. (const #f)))
  1118. (lambda (continue store things mode)
  1119. (define inputs
  1120. ;; List of derivation inputs to build. Filter out non-existent '.drv'
  1121. ;; files because the daemon transparently tries to substitute them.
  1122. (filter-map (match-lambda
  1123. (((? derivation-path? drv) . output)
  1124. (let ((drv (read-derivation-from-file* drv))
  1125. (outputs (string-tokenize output not-comma)))
  1126. (and drv (derivation-input drv outputs))))
  1127. ((? derivation-path? drv)
  1128. (and=> (read-derivation-from-file* drv)
  1129. derivation-input))
  1130. (_
  1131. #f))
  1132. things))
  1133. (let-values (((build? download?)
  1134. (show-what-to-build store inputs
  1135. #:dry-run? dry-run?
  1136. #:use-substitutes? use-substitutes?
  1137. #:verbosity verbosity
  1138. #:mode mode)))
  1139. (unless (and (or build? download?)
  1140. dry-run?)
  1141. (continue #t)))))
  1142. (define (right-arrow port)
  1143. "Return either a string containing the 'RIGHT ARROW' character, or an ASCII
  1144. replacement if PORT is not Unicode-capable."
  1145. (let ((encoding (port-encoding port))
  1146. (arrow "→"))
  1147. (catch 'encoding-error
  1148. (lambda ()
  1149. (call-with-output-string
  1150. (lambda (port)
  1151. (set-port-encoding! port encoding)
  1152. (set-port-conversion-strategy! port 'error)
  1153. (display arrow port))))
  1154. (lambda (key . args)
  1155. "->"))))
  1156. (define* (tabulate rows #:key (initial-indent 0) (max-width 25)
  1157. (inter-column " "))
  1158. "Return a list of strings where each string is a tabulated representation of
  1159. an element of ROWS. All the ROWS must be lists of the same number of cells.
  1160. Add INITIAL-INDENT white space at the beginning of each row. Ensure that
  1161. columns are at most MAX-WIDTH characters wide. Use INTER-COLUMN as a
  1162. separator between subsequent columns."
  1163. (define column-widths
  1164. ;; List of column widths.
  1165. (let loop ((rows rows)
  1166. (widths '()))
  1167. (match rows
  1168. (((? null?) ...)
  1169. (reverse widths))
  1170. (((column rest ...) ...)
  1171. (loop rest
  1172. (cons (min (apply max (map string-length column))
  1173. max-width)
  1174. widths))))))
  1175. (define indent
  1176. (make-string initial-indent #\space))
  1177. (define (string-pad-right* str len)
  1178. (if (> (string-length str) len)
  1179. str
  1180. (string-pad-right str len)))
  1181. (map (lambda (row)
  1182. (string-trim-right
  1183. (string-append indent
  1184. (string-join
  1185. (map string-pad-right* row column-widths)
  1186. inter-column))))
  1187. rows))
  1188. (define* (show-manifest-transaction store manifest transaction
  1189. #:key dry-run?)
  1190. "Display what will/would be installed/removed from MANIFEST by TRANSACTION."
  1191. (define* (package-strings names versions outputs #:key old-versions)
  1192. (tabulate (stable-sort
  1193. (zip (map (lambda (name output)
  1194. (if (string=? output "out")
  1195. name
  1196. (string-append name ":" output)))
  1197. names outputs)
  1198. (if old-versions
  1199. (map (lambda (old new)
  1200. (if (string=? old new)
  1201. (G_ "(dependencies or package changed)")
  1202. (string-append old " " → " " new)))
  1203. old-versions versions)
  1204. versions))
  1205. (lambda (x y)
  1206. (string<? (first x) (first y))))
  1207. #:initial-indent 3))
  1208. (define → ;an arrow that can be represented on stderr
  1209. (right-arrow (current-error-port)))
  1210. (let-values (((remove install upgrade downgrade)
  1211. (manifest-transaction-effects manifest transaction)))
  1212. (match remove
  1213. ((($ <manifest-entry> name version output item) ..1)
  1214. (let ((len (length name))
  1215. (remove (package-strings name version output)))
  1216. (if dry-run?
  1217. (format (current-error-port)
  1218. (N_ "The following package would be removed:~%~{~a~%~}~%"
  1219. "The following packages would be removed:~%~{~a~%~}~%"
  1220. len)
  1221. remove)
  1222. (format (current-error-port)
  1223. (N_ "The following package will be removed:~%~{~a~%~}~%"
  1224. "The following packages will be removed:~%~{~a~%~}~%"
  1225. len)
  1226. remove))))
  1227. (x #f))
  1228. (match downgrade
  1229. (((($ <manifest-entry> name old-version)
  1230. . ($ <manifest-entry> _ new-version output item)) ..1)
  1231. (let ((len (length name))
  1232. (downgrade (package-strings name new-version output
  1233. #:old-versions old-version)))
  1234. (if dry-run?
  1235. (format (current-error-port)
  1236. (N_ "The following package would be downgraded:~%~{~a~%~}~%"
  1237. "The following packages would be downgraded:~%~{~a~%~}~%"
  1238. len)
  1239. downgrade)
  1240. (format (current-error-port)
  1241. (N_ "The following package will be downgraded:~%~{~a~%~}~%"
  1242. "The following packages will be downgraded:~%~{~a~%~}~%"
  1243. len)
  1244. downgrade))))
  1245. (x #f))
  1246. (match upgrade
  1247. (((($ <manifest-entry> name old-version)
  1248. . ($ <manifest-entry> _ new-version output item)) ..1)
  1249. (let ((len (length name))
  1250. (upgrade (package-strings name new-version output
  1251. #:old-versions old-version)))
  1252. (if dry-run?
  1253. (format (current-error-port)
  1254. (N_ "The following package would be upgraded:~%~{~a~%~}~%"
  1255. "The following packages would be upgraded:~%~{~a~%~}~%"
  1256. len)
  1257. upgrade)
  1258. (format (current-error-port)
  1259. (N_ "The following package will be upgraded:~%~{~a~%~}~%"
  1260. "The following packages will be upgraded:~%~{~a~%~}~%"
  1261. len)
  1262. upgrade))))
  1263. (x #f))
  1264. (match install
  1265. ((($ <manifest-entry> name version output item _) ..1)
  1266. (let ((len (length name))
  1267. (install (package-strings name version output)))
  1268. (if dry-run?
  1269. (format (current-error-port)
  1270. (N_ "The following package would be installed:~%~{~a~%~}~%"
  1271. "The following packages would be installed:~%~{~a~%~}~%"
  1272. len)
  1273. install)
  1274. (format (current-error-port)
  1275. (N_ "The following package will be installed:~%~{~a~%~}~%"
  1276. "The following packages will be installed:~%~{~a~%~}~%"
  1277. len)
  1278. install))))
  1279. (x #f))))
  1280. (define-syntax with-error-handling
  1281. (syntax-rules ()
  1282. "Run BODY within a user-friendly error condition handler."
  1283. ((_ body ...)
  1284. (call-with-error-handling
  1285. (lambda ()
  1286. body ...)))))
  1287. (define* (indented-string str indent
  1288. #:key (initial-indent? #t))
  1289. "Return STR with each newline preceded by INDENT spaces. When
  1290. INITIAL-INDENT? is true, the first line is also indented."
  1291. (define indent-string
  1292. (make-list indent #\space))
  1293. (list->string
  1294. (string-fold-right (lambda (chr result)
  1295. (if (eqv? chr #\newline)
  1296. (cons chr (append indent-string result))
  1297. (cons chr result)))
  1298. '()
  1299. (if initial-indent?
  1300. (string-append (list->string indent-string) str)
  1301. str))))
  1302. (define* (fill-paragraph str width #:optional (column 0))
  1303. "Fill STR such that each line contains at most WIDTH characters, assuming
  1304. that the first character is at COLUMN.
  1305. When STR contains a single line break surrounded by other characters, it is
  1306. converted to a space; sequences of more than one line break are preserved."
  1307. (define (maybe-break chr result)
  1308. (match result
  1309. ((column newlines chars)
  1310. (case chr
  1311. ((#\newline)
  1312. `(,column ,(+ 1 newlines) ,chars))
  1313. (else
  1314. (let* ((spaces (if (and (pair? chars) (eqv? (car chars) #\.)) 2 1))
  1315. (chars (case newlines
  1316. ((0) chars)
  1317. ((1)
  1318. (append (make-list spaces #\space) chars))
  1319. (else
  1320. (append (make-list newlines #\newline) chars))))
  1321. (column (case newlines
  1322. ((0) column)
  1323. ((1) (+ spaces column))
  1324. (else 0))))
  1325. (let ((chars (cons chr chars))
  1326. (column (+ 1 column)))
  1327. (if (> column width)
  1328. (let*-values (((before after)
  1329. (break (cut eqv? #\space <>) chars))
  1330. ((len)
  1331. (length before)))
  1332. (if (<= len width)
  1333. `(,len
  1334. 0
  1335. ,(if (null? after)
  1336. before
  1337. (append before
  1338. (cons #\newline
  1339. (drop-while (cut eqv? #\space <>)
  1340. after)))))
  1341. `(,column 0 ,chars))) ; unbreakable
  1342. `(,column 0 ,chars)))))))))
  1343. (match (string-fold maybe-break
  1344. `(,column 0 ())
  1345. str)
  1346. ((column newlines chars)
  1347. (list->string (reverse chars)))))
  1348. ;;;
  1349. ;;; Packages.
  1350. ;;;
  1351. (define %text-width
  1352. ;; '*line-width*' was introduced in Guile 2.2.7/3.0.1. On older versions of
  1353. ;; Guile, monkey-patch 'wrap*' below.
  1354. (if (defined? '*line-width*)
  1355. (let ((parameter (fluid->parameter *line-width*)))
  1356. (parameter (terminal-columns))
  1357. parameter)
  1358. (make-parameter (terminal-columns))))
  1359. (unless (defined? '*line-width*) ;Guile < 2.2.7
  1360. (set! (@@ (texinfo plain-text) wrap*)
  1361. ;; XXX: Monkey patch this private procedure to let 'package->recutils'
  1362. ;; parameterize the fill of description field correctly.
  1363. (lambda strings
  1364. (let ((indent (fluid-ref (@@ (texinfo plain-text) *indent*))))
  1365. (fill-string (string-concatenate strings)
  1366. #:line-width (%text-width) #:initial-indent indent
  1367. #:subsequent-indent indent)))))
  1368. (define (texi->plain-text str)
  1369. "Return a plain-text representation of texinfo fragment STR."
  1370. ;; 'texi-fragment->stexi' uses a string port so make sure it's a
  1371. ;; Unicode-capable one (see <http://bugs.gnu.org/11197>.)
  1372. (with-fluids ((%default-port-encoding "UTF-8"))
  1373. (stexi->plain-text (texi-fragment->stexi str))))
  1374. (define (texi->plain-text* package str)
  1375. "Same as 'texi->plain-text', but gracefully handle Texinfo errors."
  1376. (catch 'parser-error
  1377. (lambda ()
  1378. (texi->plain-text str))
  1379. (lambda args
  1380. (warning (package-location package)
  1381. (G_ "~a: invalid Texinfo markup~%")
  1382. (package-full-name package))
  1383. str)))
  1384. (define (package-field-string package field-accessor)
  1385. "Return a plain-text representation of PACKAGE field."
  1386. (and=> (field-accessor package)
  1387. (lambda (str)
  1388. (texi->plain-text* package (P_ str)))))
  1389. (define (package-description-string package)
  1390. "Return a plain-text representation of PACKAGE description field."
  1391. (package-field-string package package-description))
  1392. (define (package-synopsis-string package)
  1393. "Return a plain-text representation of PACKAGE synopsis field."
  1394. (package-field-string package package-synopsis))
  1395. (define (string->recutils str)
  1396. "Return a version of STR where newlines have been replaced by newlines
  1397. followed by \"+ \", which makes for a valid multi-line field value in the
  1398. `recutils' syntax."
  1399. (list->string
  1400. (string-fold-right (lambda (chr result)
  1401. (if (eqv? chr #\newline)
  1402. (cons* chr #\+ #\space result)
  1403. (cons chr result)))
  1404. '()
  1405. str)))
  1406. (define* (package->recutils p port #:optional (width (%text-width))
  1407. #:key
  1408. (hyperlinks? (supports-hyperlinks? port))
  1409. (extra-fields '())
  1410. (highlighting identity))
  1411. "Write to PORT a `recutils' record of package P, arranging to fit within
  1412. WIDTH columns. EXTRA-FIELDS is a list of symbol/value pairs to emit. When
  1413. HYPERLINKS? is true, emit hyperlink escape sequences when appropriate. Pass
  1414. the synopsis and description through HIGHLIGHTING, a one-argument procedure
  1415. that may return a colorized version of its argument."
  1416. (define port*
  1417. (or (pager-wrapped-port port) port))
  1418. (define width*
  1419. ;; The available number of columns once we've taken into account space for
  1420. ;; the initial "+ " prefix.
  1421. (if (> width 2) (- width 2) width))
  1422. (define (split-lines str indent)
  1423. (string->recutils
  1424. (fill-paragraph str width* indent)))
  1425. (define (dependencies->recutils packages)
  1426. (let ((list (string-join (delete-duplicates
  1427. (map package-full-name
  1428. (sort packages package<?))) " ")))
  1429. (split-lines list (string-length "dependencies: "))))
  1430. (define %default-output-synopses
  1431. `(("bin" . ,(G_ "executable programs and scripts"))
  1432. ("debug" . ,(G_ "debug information"))
  1433. ("doc" . ,(G_ "documentation"))
  1434. ("lib" . ,(G_ "shared libraries"))
  1435. ("static" . ,(G_ "static libraries"))
  1436. ("out" . ,(G_ "everything else"))))
  1437. (define* (output->recutils package output #:optional
  1438. (default-synopses %default-output-synopses))
  1439. (string-append
  1440. "+ " output ": "
  1441. (or
  1442. (any
  1443. (match-lambda
  1444. (('output-synopsis key synopsis)
  1445. (and (string=? key output) (P_ synopsis)))
  1446. (_ #f))
  1447. (package-properties package))
  1448. (assoc-ref default-synopses output)
  1449. (G_ "[description missing]"))))
  1450. (define (package-outputs/out-last package)
  1451. ((compose append partition)
  1452. (negate (cut string=? "out" <>))
  1453. (package-outputs package)))
  1454. (define (package<? p1 p2)
  1455. (string<? (package-full-name p1) (package-full-name p2)))
  1456. (define highlighting*
  1457. (if (color-output? port*)
  1458. highlighting
  1459. identity))
  1460. ;; Note: Don't i18n field names so that people can post-process it.
  1461. (format port "name: ~a~%" (highlight (package-name p) port*))
  1462. (format port "version: ~a~%" (highlight (package-version p) port*))
  1463. (match (package-outputs/out-last p)
  1464. (("out") ; one output has everything
  1465. (format port "outputs:~%~a~%"
  1466. (output->recutils p "out"
  1467. (alist-cons "out" (G_ "everything")
  1468. %default-output-synopses))))
  1469. (outputs ; multiple outputs
  1470. (format port "outputs:~%~{~a~%~}"
  1471. (map (cut output->recutils p <>) (package-outputs/out-last p)))))
  1472. (match (all-spec-parameters-with-types
  1473. (package-parameter-spec p))
  1474. (() #t)
  1475. (lst (format port "parameters:~{ ~a~}~%"
  1476. lst)))
  1477. (format port "systems: ~a~%"
  1478. (split-lines (string-join (package-transitive-supported-systems p))
  1479. (string-length "systems: ")))
  1480. (format port "dependencies: ~a~%"
  1481. (match (package-direct-inputs p)
  1482. (((labels inputs . _) ...)
  1483. (dependencies->recutils (filter package? inputs)))))
  1484. (format port "location: ~a~%"
  1485. (or (and=> (package-location p)
  1486. (if hyperlinks? location->hyperlink location->string))
  1487. (G_ "unknown")))
  1488. ;; Note: Starting from version 1.6 or recutils, hyphens are not allowed in
  1489. ;; field identifiers.
  1490. (format port "homepage: ~a~%" (package-home-page p))
  1491. (format port "license: ~a~%"
  1492. (match (package-license p)
  1493. (((? license? licenses) ...)
  1494. (string-join (map license-name licenses)
  1495. ", "))
  1496. ((? license? license)
  1497. (let ((text (license-name license))
  1498. (uri (license-uri license)))
  1499. (if (and hyperlinks? uri (string-prefix? "http" uri))
  1500. (hyperlink uri text)
  1501. text)))
  1502. (x
  1503. (G_ "unknown"))))
  1504. (format port "synopsis: ~a~%"
  1505. (highlighting*
  1506. (string-map (match-lambda
  1507. (#\newline #\space)
  1508. (chr chr))
  1509. (or (package-synopsis-string p) ""))))
  1510. (format port "~a~%"
  1511. (highlighting*
  1512. (string->recutils
  1513. (string-trim-right
  1514. (parameterize ((%text-width width*))
  1515. ;; Call 'texi->plain-text' on the concatenated string to account
  1516. ;; for the width of "description:" in paragraph filling.
  1517. (texi->plain-text*
  1518. p
  1519. (string-append "description: "
  1520. (or (and=> (package-description p) P_)
  1521. ""))))
  1522. #\newline))))
  1523. (for-each (match-lambda
  1524. ((field . value)
  1525. (let ((field (symbol->string field)))
  1526. (format port "~a: ~a~%"
  1527. field
  1528. (fill-paragraph (object->string value) width*
  1529. (string-length field))))))
  1530. extra-fields)
  1531. (newline port))
  1532. ;;;
  1533. ;;; Searching.
  1534. ;;;
  1535. (define (relevance obj regexps metrics)
  1536. "Compute a \"relevance score\" for OBJ as a function of its number of
  1537. matches of REGEXPS and accordingly to METRICS. METRICS is list of
  1538. field/weight pairs, where FIELD is a procedure that returns a string or list
  1539. of strings describing OBJ, and WEIGHT is a positive integer denoting the
  1540. weight of this field in the final score.
  1541. A score of zero means that OBJ does not match any of REGEXPS. The higher the
  1542. score, the more relevant OBJ is to REGEXPS."
  1543. (define (score regexp str)
  1544. (fold-matches regexp str 0
  1545. (lambda (m score)
  1546. (+ score
  1547. (if (string=? (match:substring m) str)
  1548. 5 ;exact match
  1549. 1)))))
  1550. (define (regexp->score regexp)
  1551. (let ((score-regexp (lambda (str) (score regexp str))))
  1552. (fold (lambda (metric relevance)
  1553. (match metric
  1554. ((field . weight)
  1555. (match (field obj)
  1556. (#f relevance)
  1557. ((? string? str)
  1558. (+ relevance (* (score-regexp str) weight)))
  1559. ((lst ...)
  1560. (+ relevance (* weight (apply + (map score-regexp lst)))))))))
  1561. 0 metrics)))
  1562. (let loop ((regexps regexps)
  1563. (total-score 0))
  1564. (match regexps
  1565. ((head . tail)
  1566. (let ((score (regexp->score head)))
  1567. ;; Return zero if one of PATTERNS doesn't match.
  1568. (if (zero? score)
  1569. 0
  1570. (loop tail (+ total-score score)))))
  1571. (() total-score))))
  1572. (define %package-metrics
  1573. ;; Metrics used to compute the "relevance score" of a package against a set
  1574. ;; of regexps.
  1575. `((,package-name . 4)
  1576. (,package-upstream-name* . 2)
  1577. ;; Match against uncommon outputs.
  1578. (,(lambda (package)
  1579. (filter (lambda (output)
  1580. (not (member output
  1581. ;; Some common outputs shared by many packages.
  1582. '("out" "doc" "debug" "lib" "include" "bin"))))
  1583. (package-outputs package)))
  1584. . 1)
  1585. ;; Match regexps on the raw Texinfo since formatting it is quite expensive
  1586. ;; and doesn't have much of an effect on search results.
  1587. (,(lambda (package)
  1588. (and=> (package-synopsis package) P_)) . 3)
  1589. (,(lambda (package)
  1590. (and=> (package-description package) P_)) . 2)
  1591. (,(lambda (type)
  1592. (match (and=> (package-location type) location-file)
  1593. ((? string? file) (basename file ".scm"))
  1594. (#f "")))
  1595. . 1)))
  1596. (define (package-relevance package regexps)
  1597. "Return a score denoting the relevance of PACKAGE for REGEXPS. A score of
  1598. zero means that PACKAGE does not match any of REGEXPS."
  1599. (relevance package regexps %package-metrics))
  1600. (define pager-port-mapping
  1601. ;; If a pager is being used, via 'with-paginated-output-port', this maps the
  1602. ;; pager port (pipe) to the underlying output port.
  1603. (make-parameter #f))
  1604. (define* (pager-wrapped-port #:optional (port (current-output-port)))
  1605. "If PORT is a pipe to a pager created by 'with-paginated-output-port',
  1606. return the underlying port. Otherwise return #f."
  1607. (match (pager-port-mapping)
  1608. ((pager . wrapped)
  1609. (and (eq? pager port) wrapped))
  1610. (_
  1611. #f)))
  1612. (define (find-available-pager)
  1613. "Return the program name of an available pager or the empty string if none is
  1614. available."
  1615. (or (getenv "GUIX_PAGER")
  1616. (getenv "PAGER")
  1617. (which "less")
  1618. (which "more")
  1619. ""))
  1620. (define* (call-with-paginated-output-port proc
  1621. #:key (less-options "FrX"))
  1622. (let ((pager-command-line (find-available-pager)))
  1623. ;; Setting PAGER to the empty string conventionally disables paging.
  1624. (if (and (not (string-null? pager-command-line))
  1625. (isatty?* (current-output-port)))
  1626. ;; Set 'LESS' so that 'less' exits if everything fits on the screen
  1627. ;; (F), lets ANSI escapes through (r), does not send the termcap
  1628. ;; initialization string (X). Set it unconditionally because some
  1629. ;; distros set it to something that doesn't work here.
  1630. ;;
  1631. ;; For things that produce long lines, such as 'guix processes', use
  1632. ;; 'R' instead of 'r': this strips hyperlinks but allows 'less' to
  1633. ;; make a good estimate of the line length.
  1634. (let* ((pager (with-environment-variables `(("LESS" ,less-options))
  1635. (apply open-pipe* OPEN_WRITE
  1636. ;; Split into arguments. Treat runs of multiple
  1637. ;; whitespace characters as one. libpipeline-
  1638. ;; style "cmd one\ arg" escaping is unsupported.
  1639. (remove (lambda (s) (string-null? s))
  1640. (string-split pager-command-line
  1641. char-set:whitespace))))))
  1642. (dynamic-wind
  1643. (const #t)
  1644. (lambda ()
  1645. (parameterize ((pager-port-mapping
  1646. (cons pager (current-output-port))))
  1647. (proc pager)))
  1648. (lambda () (close-pipe pager))))
  1649. (proc (current-output-port)))))
  1650. (define-syntax with-paginated-output-port
  1651. (syntax-rules ()
  1652. "Evaluate EXP... with PORT bound to a port that talks to the pager if
  1653. standard output is a tty, or with PORT set to the current output port."
  1654. ((_ port exp ... #:less-options opts)
  1655. (call-with-paginated-output-port (lambda (port) exp ...)
  1656. #:less-options opts))
  1657. ((_ port exp ...)
  1658. (call-with-paginated-output-port (lambda (port) exp ...)))))
  1659. (define* (display-search-results matches port
  1660. #:key
  1661. (regexps '())
  1662. (command "guix search")
  1663. (print package->recutils))
  1664. "Display MATCHES, a list of object/score pairs, by calling PRINT on each of
  1665. them. If PORT is a terminal, print at most a full screen of results. REGEXPS
  1666. is a list of regexps to highlight in search results."
  1667. (define first-line
  1668. (port-line port))
  1669. (define max-rows
  1670. (and first-line (isatty? port)
  1671. (terminal-rows port)))
  1672. (define (line-count str)
  1673. (string-count str #\newline))
  1674. (define highlighting
  1675. (let ((match-color (color ON-RED BOLD)))
  1676. (colorize-full-matches (map (lambda (regexp)
  1677. (cons regexp match-color))
  1678. regexps))))
  1679. (with-paginated-output-port paginated
  1680. (let loop ((matches matches))
  1681. (match matches
  1682. (((package . score) rest ...)
  1683. (let* ((links? (supports-hyperlinks? port)))
  1684. (print package paginated
  1685. #:hyperlinks? links?
  1686. #:extra-fields `((relevance . ,score))
  1687. #:highlighting highlighting)
  1688. (loop rest)))
  1689. (()
  1690. #t)))))
  1691. (define (string->generations str)
  1692. "Return the list of generations matching a pattern in STR. This function
  1693. accepts the following patterns: \"1\", \"1,2,3\", \"1..9\", \"1..\", \"..9\"."
  1694. (define (maybe-integer)
  1695. (let ((x (string->number str)))
  1696. (and (integer? x)
  1697. x)))
  1698. (define (maybe-comma-separated-integers)
  1699. (let ((lst (delete-duplicates
  1700. (map string->number
  1701. (string-split str #\,)))))
  1702. (and (every integer? lst)
  1703. lst)))
  1704. (cond ((maybe-integer)
  1705. =>
  1706. list)
  1707. ((maybe-comma-separated-integers)
  1708. =>
  1709. identity)
  1710. ((string-match "^([0-9]+)\\.\\.([0-9]+)$" str)
  1711. =>
  1712. (lambda (match)
  1713. (let ((s (string->number (match:substring match 1)))
  1714. (e (string->number (match:substring match 2))))
  1715. (and (every integer? (list s e))
  1716. (<= s e)
  1717. (iota (1+ (- e s)) s)))))
  1718. ((string-match "^([0-9]+)\\.\\.$" str)
  1719. =>
  1720. (lambda (match)
  1721. (let ((s (string->number (match:substring match 1))))
  1722. (and (integer? s)
  1723. `(>= ,s)))))
  1724. ((string-match "^\\.\\.([0-9]+)$" str)
  1725. =>
  1726. (lambda (match)
  1727. (let ((e (string->number (match:substring match 1))))
  1728. (and (integer? e)
  1729. `(<= ,e)))))
  1730. (else #f)))
  1731. (define (string->duration str)
  1732. "Return the duration matching a pattern in STR. This function accepts the
  1733. following patterns: \"1d\", \"1w\", \"1m\"."
  1734. (define (hours->duration hours match)
  1735. (make-time time-duration 0
  1736. (* 3600 hours (string->number (match:substring match 1)))))
  1737. (cond ((string-match "^([0-9]+)s$" str)
  1738. =>
  1739. (lambda (match)
  1740. (make-time time-duration 0
  1741. (string->number (match:substring match 1)))))
  1742. ((string-match "^([0-9]+)h$" str)
  1743. =>
  1744. (lambda (match)
  1745. (hours->duration 1 match)))
  1746. ((string-match "^([0-9]+)d$" str)
  1747. =>
  1748. (lambda (match)
  1749. (hours->duration 24 match)))
  1750. ((string-match "^([0-9]+)w$" str)
  1751. =>
  1752. (lambda (match)
  1753. (hours->duration (* 24 7) match)))
  1754. ((string-match "^([0-9]+)m$" str)
  1755. =>
  1756. (lambda (match)
  1757. (hours->duration (* 24 30) match)))
  1758. (else #f)))
  1759. (define* (matching-generations str profile
  1760. #:key (duration-relation <=))
  1761. "Return the list of available generations matching a pattern in STR. See
  1762. 'string->generations' and 'string->duration' for the list of valid patterns.
  1763. When STR is a duration pattern, return all the generations whose ctime has
  1764. DURATION-RELATION with the current time."
  1765. (define (valid-generations lst)
  1766. (define (valid-generation? n)
  1767. (any (cut = n <>) (generation-numbers profile)))
  1768. (fold-right (lambda (x acc)
  1769. (if (valid-generation? x)
  1770. (cons x acc)
  1771. acc))
  1772. '()
  1773. lst))
  1774. (define (filter-generations generations)
  1775. (match generations
  1776. (() '())
  1777. (('>= n)
  1778. (drop-while (cut > n <>)
  1779. (generation-numbers profile)))
  1780. (('<= n)
  1781. (valid-generations (iota n 1)))
  1782. ((lst ..1)
  1783. (valid-generations lst))
  1784. (x #f)))
  1785. (define (filter-by-duration duration)
  1786. (define (time-at-midnight time)
  1787. ;; Return TIME at midnight by setting nanoseconds, seconds, minutes, and
  1788. ;; hours to zeros.
  1789. (let ((d (time-utc->date time)))
  1790. (date->time-utc
  1791. (make-date 0 0 0 0
  1792. (date-day d) (date-month d)
  1793. (date-year d) (date-zone-offset d)))))
  1794. (define generation-ctime-alist
  1795. (map (lambda (number)
  1796. (cons number
  1797. (time-second
  1798. (time-at-midnight
  1799. (generation-time profile number)))))
  1800. (generation-numbers profile)))
  1801. (match duration
  1802. (#f #f)
  1803. (res
  1804. (let ((s (time-second
  1805. (subtract-duration (time-at-midnight (current-time))
  1806. duration))))
  1807. (delete #f (map (lambda (x)
  1808. (and (duration-relation s (cdr x))
  1809. (first x)))
  1810. generation-ctime-alist))))))
  1811. (cond ((string->generations str)
  1812. =>
  1813. filter-generations)
  1814. ((string->duration str)
  1815. =>
  1816. filter-by-duration)
  1817. (else
  1818. (raise
  1819. (formatted-message (G_ "invalid syntax: ~a~%") str)))))
  1820. (define (display-generation profile number)
  1821. "Display a one-line summary of generation NUMBER of PROFILE."
  1822. (unless (zero? number)
  1823. (let* ((file (generation-file-name profile number))
  1824. (link (if (supports-hyperlinks?)
  1825. (cut file-hyperlink file <>)
  1826. identity))
  1827. (header (format #f (link (highlight (G_ "Generation ~a\t~a")
  1828. (or (pager-wrapped-port)
  1829. (current-output-port))))
  1830. number
  1831. (date->string
  1832. (time-utc->date
  1833. (generation-time profile number))
  1834. ;; TRANSLATORS: This is a format-string for date->string.
  1835. ;; Please choose a format that corresponds to the
  1836. ;; usual way of presenting dates in your locale.
  1837. ;; See https://www.gnu.org/software/guile/manual/html_node/SRFI_002d19-Date-to-string.html
  1838. ;; for details.
  1839. (G_ "~b ~d ~Y ~T"))))
  1840. (current (generation-number profile)))
  1841. (if (= number current)
  1842. ;; TRANSLATORS: The word "current" here is an adjective for
  1843. ;; "Generation", as in "current generation". Use the appropriate
  1844. ;; gender where applicable.
  1845. (format #t (G_ "~a\t(current)~%") header)
  1846. (format #t "~a~%" header)))))
  1847. (define (display-profile-content-diff profile gen1 gen2)
  1848. "Display the changed packages in PROFILE GEN2 compared to generation GEN1."
  1849. (define (equal-entry? first second)
  1850. (string= (manifest-entry-item first) (manifest-entry-item second)))
  1851. (define (make-row entry prefix)
  1852. (match entry
  1853. (($ <manifest-entry> name version output location _)
  1854. (list (format #f " ~a ~a" prefix name) version output location))))
  1855. (define (list-entries number)
  1856. (manifest-entries (profile-manifest (generation-file-name profile number))))
  1857. (define (display-diff profile old new)
  1858. (display-generation profile new)
  1859. (let ((added (lset-difference
  1860. equal-entry? (list-entries new) (list-entries old)))
  1861. (removed (lset-difference
  1862. equal-entry? (list-entries old) (list-entries new))))
  1863. (pretty-print-table (append (map (cut make-row <> "+") added)
  1864. (map (cut make-row <> "-") removed)))
  1865. (newline)))
  1866. (display-diff profile gen1 gen2))
  1867. (define (profile-lock-handler profile errno . _)
  1868. "Handle failure to acquire PROFILE's lock."
  1869. ;; NFS mounts can return ENOLCK. When that happens, there's not much that
  1870. ;; can be done, so warn the user and keep going.
  1871. (if (= errno ENOLCK)
  1872. (warning (G_ "cannot lock profile ~a: ~a~%")
  1873. profile (strerror errno))
  1874. (leave (G_ "profile ~a is locked by another process~%")
  1875. profile)))
  1876. (define profile-lock-file
  1877. (cut string-append <> ".lock"))
  1878. (define-syntax-rule (with-profile-lock profile exp ...)
  1879. "Grab PROFILE's lock and evaluate EXP... Call 'leave' if the lock is
  1880. already taken."
  1881. (with-file-lock/no-wait (profile-lock-file profile)
  1882. (cut profile-lock-handler profile <...>)
  1883. exp ...))
  1884. (define (display-profile-content profile number)
  1885. "Display the packages in PROFILE, generation NUMBER, in a human-readable
  1886. way."
  1887. (define entry->row
  1888. (match-lambda
  1889. (($ <manifest-entry> name version output location _)
  1890. (list (string-append " " name) version output location))))
  1891. (let* ((manifest (profile-manifest (generation-file-name profile number)))
  1892. (entries (manifest-entries manifest))
  1893. (rows (map entry->row entries)))
  1894. ;; Show most recently installed packages last.
  1895. (pretty-print-table (reverse rows))))
  1896. (define (display-generation-change previous current)
  1897. (format #t (G_ "switched from generation ~a to ~a~%") previous current))
  1898. (define (roll-back* store profile)
  1899. "Like 'roll-back', but display what is happening."
  1900. (call-with-values
  1901. (lambda ()
  1902. (roll-back store profile))
  1903. display-generation-change))
  1904. (define (switch-to-generation* profile number)
  1905. "Like 'switch-to-generation', but display what is happening."
  1906. (let ((previous (switch-to-generation profile number)))
  1907. (display-generation-change previous number)))
  1908. (define (delete-generation* store profile generation)
  1909. "Like 'delete-generation', but display what is going on."
  1910. (format #t (G_ "deleting ~a~%")
  1911. (generation-file-name profile generation))
  1912. (delete-generation store profile generation))
  1913. (define* (package-specification->name+version+output spec
  1914. #:optional (output "out"))
  1915. "Parse package specification SPEC and return three value: the specified
  1916. package name, version number (or #f), and output name (or OUTPUT). SPEC may
  1917. optionally contain a version number and an output name, as in these examples:
  1918. guile
  1919. guile@2.0.9
  1920. guile:debug
  1921. guile@2.0.9:debug
  1922. "
  1923. (let*-values (((name sub-drv)
  1924. (match (string-rindex spec #\:)
  1925. (#f (values spec output))
  1926. (colon (values (substring spec 0 colon)
  1927. (substring spec (+ 1 colon))))))
  1928. ((name version)
  1929. (package-name->name+version name)))
  1930. (values name version sub-drv)))
  1931. ;;;
  1932. ;;; Command-line option processing.
  1933. ;;;
  1934. (define (show-guix-usage)
  1935. (format (current-error-port)
  1936. (G_ "Try `guix --help' for more information.~%"))
  1937. (exit 1))
  1938. ;; Representation of a 'guix' command.
  1939. (define-immutable-record-type <command>
  1940. (command name synopsis category)
  1941. command?
  1942. (name command-name)
  1943. (synopsis command-synopsis)
  1944. (category command-category))
  1945. (define (source-file-command file)
  1946. "Read FILE, a Scheme source file, and return either a <command> object based
  1947. on the 'define-command' top-level form found therein, or #f if FILE does not
  1948. contain a 'define-command' form."
  1949. (define command-name
  1950. (match (filter (negate string-null?)
  1951. (string-split file #\/))
  1952. ((_ ... "guix" (or "scripts" "extensions") name)
  1953. (list (file-sans-extension name)))
  1954. ((_ ... "guix" (or "scripts" "extensions") first second)
  1955. (list first (file-sans-extension second)))))
  1956. ;; The strategy here is to parse FILE. This is much cheaper than a
  1957. ;; technique based on run-time introspection where we'd load FILE and all
  1958. ;; the modules it depends on.
  1959. (call-with-input-file file
  1960. (lambda (port)
  1961. (let loop ()
  1962. (match (read port)
  1963. (('define-command _ ('synopsis synopsis)
  1964. _ ...)
  1965. (command command-name synopsis 'main))
  1966. (('define-command _
  1967. ('category category) ('synopsis synopsis)
  1968. _ ...)
  1969. (command command-name synopsis category))
  1970. ((? eof-object?)
  1971. #f)
  1972. (_
  1973. (loop)))))))
  1974. (define* (command-files #:optional directory)
  1975. "Return the list of source files that define Guix sub-commands."
  1976. (define directory*
  1977. (or directory
  1978. (and=> (search-path %load-path "guix.scm")
  1979. (compose (cut string-append <> "/guix/scripts")
  1980. dirname))))
  1981. (define dot-scm?
  1982. (cut string-suffix? ".scm" <>))
  1983. (if directory*
  1984. (map (cut string-append directory* "/" <>)
  1985. (scandir directory* dot-scm?))
  1986. '()))
  1987. (define (extension-directories)
  1988. "Return the list of directories containing Guix extensions."
  1989. (filter file-exists?
  1990. (parse-path
  1991. (getenv "GUIX_EXTENSIONS_PATH"))))
  1992. (define (commands)
  1993. "Return the list of commands, alphabetically sorted."
  1994. (filter-map source-file-command
  1995. (append (command-files)
  1996. (append-map command-files
  1997. (extension-directories)))))
  1998. (define (show-guix-help)
  1999. (define (internal? command)
  2000. (member command '("substitute" "authenticate" "offload"
  2001. "perform-download")))
  2002. (define (display-commands commands)
  2003. (let* ((names (map (lambda (command)
  2004. (string-join (command-name command)))
  2005. commands))
  2006. (max-width (reduce max 0 (map string-length names))))
  2007. (for-each (lambda (name command)
  2008. (format #t " ~a ~a~%"
  2009. (string-pad-right name max-width)
  2010. (G_ (command-synopsis command))))
  2011. names
  2012. commands)))
  2013. (define (category-predicate category)
  2014. (lambda (command)
  2015. (eq? category (command-category command))))
  2016. (display (G_ "Usage: guix OPTION | COMMAND ARGS...
  2017. Run COMMAND with ARGS, if given.\n"))
  2018. (display (G_ "
  2019. -h, --help display this helpful text again and exit"))
  2020. (display (G_ "
  2021. -V, --version display version and copyright information and exit"))
  2022. (newline)
  2023. (newline)
  2024. (display (G_ "COMMAND must be one of the sub-commands listed below:\n"))
  2025. (let ((commands (commands))
  2026. (categories (module-ref (resolve-interface '(guix scripts))
  2027. '%command-categories)))
  2028. (for-each (match-lambda
  2029. (('internal . _)
  2030. #t) ;hide internal commands
  2031. ((category . synopsis)
  2032. (let ((relevant-commands (filter (category-predicate category)
  2033. commands)))
  2034. ;; Only print categories that contain commands.
  2035. (match relevant-commands
  2036. ((one . more)
  2037. (format #t "~% ~a~%" (G_ synopsis))
  2038. (display-commands relevant-commands))
  2039. (_ #f)))))
  2040. categories))
  2041. (show-bug-report-information))
  2042. (define (run-guix-command command . args)
  2043. "Run COMMAND with the given ARGS. Report an error when COMMAND is not
  2044. found."
  2045. (define (command-hint guess commands)
  2046. (define command-names
  2047. (map (lambda (command)
  2048. (match (command-name command)
  2049. ((head tail ...) head)))
  2050. commands))
  2051. (string-closest (symbol->string guess) command-names #:threshold 3))
  2052. (define module
  2053. ;; Check if there is a matching extension.
  2054. (match (search-path (extension-directories)
  2055. (format #f "~a.scm" command))
  2056. (#f
  2057. (catch 'misc-error
  2058. (lambda ()
  2059. (resolve-interface `(guix scripts ,command)))
  2060. (lambda _
  2061. (let ((hint (command-hint command (commands))))
  2062. (format (current-error-port)
  2063. (G_ "guix: ~a: command not found~%") command)
  2064. (when hint
  2065. (display-hint (G_ "Did you mean @code{~a}?") hint))
  2066. (show-guix-usage)))))
  2067. (file
  2068. (load file)
  2069. (resolve-interface `(guix extensions ,command)))))
  2070. (let ((command-main (module-ref module
  2071. (symbol-append 'guix- command))))
  2072. (parameterize ((program-name command))
  2073. (dynamic-wind
  2074. (const #f)
  2075. (lambda ()
  2076. (apply command-main args))
  2077. (lambda ()
  2078. ;; Abuse 'exit-hook' (which is normally meant to be used by the
  2079. ;; REPL) to run things like profiling hooks upon completion.
  2080. (run-hook exit-hook))))))
  2081. (define (run-guix . args)
  2082. "Run the 'guix' command defined by command line ARGS.
  2083. Unlike 'guix-main', this procedure assumes that locale, i18n support,
  2084. and signal handling have already been set up."
  2085. (define option? (cut string-prefix? "-" <>))
  2086. ;; The default %LOAD-EXTENSIONS includes the empty string, which doubles the
  2087. ;; number of 'stat' calls per entry in %LOAD-PATH. Shamelessly remove it.
  2088. (set! %load-extensions '(".scm"))
  2089. ;; Disable canonicalization so we don't don't stat unreasonably.
  2090. (with-fluids ((%file-port-name-canonicalization #f))
  2091. (match args
  2092. (()
  2093. (format (current-error-port)
  2094. (G_ "guix: missing command name~%"))
  2095. (show-guix-usage))
  2096. ((or ("-h") ("--help"))
  2097. (leave-on-EPIPE (show-guix-help)))
  2098. ((or ("-V") ("--version"))
  2099. (show-version-and-exit "guix"))
  2100. (((? option? o) args ...)
  2101. (format (current-error-port)
  2102. (G_ "guix: unrecognized option '~a'~%") o)
  2103. (show-guix-usage))
  2104. (("help" command)
  2105. (apply run-guix-command (string->symbol command)
  2106. '("--help")))
  2107. (("help" args ...)
  2108. (leave-on-EPIPE (show-guix-help)))
  2109. ((command args ...)
  2110. (apply run-guix-command
  2111. (string->symbol command)
  2112. args)))))
  2113. (define (guix-main arg0 . args)
  2114. (initialize-guix)
  2115. (apply run-guix args))
  2116. ;;; Local Variables:
  2117. ;;; eval: (put 'guard* 'scheme-indent-function 2)
  2118. ;;; End:
  2119. ;;; ui.scm ends here