profiles.scm 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013-2023 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
  4. ;;; Copyright © 2014, 2016 Alex Kost <alezost@gmail.com>
  5. ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
  6. ;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
  7. ;;; Copyright © 2016, 2017, 2018, 2019, 2021, 2022 Ricardo Wurmus <rekado@elephly.net>
  8. ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
  9. ;;; Copyright © 2017 Huang Ying <huang.ying.caritas@gmail.com>
  10. ;;; Copyright © 2017, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  11. ;;; Copyright © 2019 Kyle Meyer <kyle@kyleam.com>
  12. ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
  13. ;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
  14. ;;; Copyright © 2014 David Thompson <davet@gnu.org>
  15. ;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net>
  16. ;;;
  17. ;;; This file is part of GNU Guix.
  18. ;;;
  19. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  20. ;;; under the terms of the GNU General Public License as published by
  21. ;;; the Free Software Foundation; either version 3 of the License, or (at
  22. ;;; your option) any later version.
  23. ;;;
  24. ;;; GNU Guix is distributed in the hope that it will be useful, but
  25. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  26. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. ;;; GNU General Public License for more details.
  28. ;;;
  29. ;;; You should have received a copy of the GNU General Public License
  30. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  31. (define-module (guix profiles)
  32. #:use-module ((guix config) #:select (%state-directory))
  33. #:use-module ((guix utils) #:hide (package-name->name+version))
  34. #:use-module ((guix build utils)
  35. #:select (package-name->name+version mkdir-p switch-symlinks))
  36. #:use-module ((guix diagnostics) #:select (&fix-hint formatted-message))
  37. #:use-module (guix i18n)
  38. #:use-module (guix records)
  39. #:use-module (guix packages)
  40. #:use-module (guix derivations)
  41. #:use-module (guix search-paths)
  42. #:use-module (guix gexp)
  43. #:use-module (guix modules)
  44. #:use-module (guix monads)
  45. #:use-module (guix store)
  46. #:use-module (ice-9 vlist)
  47. #:use-module (ice-9 match)
  48. #:use-module (ice-9 regex)
  49. #:use-module (ice-9 ftw)
  50. #:use-module (ice-9 format)
  51. #:use-module (srfi srfi-1)
  52. #:use-module (srfi srfi-9)
  53. #:use-module (srfi srfi-11)
  54. #:use-module (srfi srfi-19)
  55. #:use-module (srfi srfi-26)
  56. #:use-module (srfi srfi-34)
  57. #:use-module (srfi srfi-35)
  58. #:autoload (srfi srfi-98) (get-environment-variables)
  59. #:export (&profile-error
  60. profile-error?
  61. profile-error-profile
  62. &profile-not-found-error
  63. profile-not-found-error?
  64. &profile-collision-error
  65. profile-collision-error?
  66. profile-collision-error-entry
  67. profile-collision-error-conflict
  68. &missing-generation-error
  69. missing-generation-error?
  70. missing-generation-error-generation
  71. &unmatched-pattern-error
  72. unmatched-pattern-error?
  73. unmatched-pattern-error-pattern
  74. unmatched-pattern-error-manifest
  75. manifest make-manifest
  76. manifest?
  77. manifest-entries
  78. manifest-transitive-entries
  79. <manifest-entry> ; FIXME: eventually make it internal
  80. manifest-entry
  81. manifest-entry?
  82. manifest-entry-name
  83. manifest-entry-version
  84. manifest-entry-output
  85. manifest-entry-item
  86. manifest-entry-dependencies
  87. manifest-entry-search-paths
  88. manifest-entry-parent
  89. manifest-entry-properties
  90. lower-manifest-entry
  91. manifest-entry=?
  92. manifest-pattern
  93. manifest-pattern?
  94. manifest-pattern-name
  95. manifest-pattern-version
  96. manifest-pattern-output
  97. concatenate-manifests
  98. map-manifest-entries
  99. manifest-remove
  100. manifest-add
  101. manifest-lookup
  102. manifest-installed?
  103. manifest-matching-entries
  104. manifest-search-paths
  105. check-for-collisions
  106. manifest->code
  107. manifest-transaction
  108. manifest-transaction?
  109. manifest-transaction-install
  110. manifest-transaction-remove
  111. manifest-transaction-install-entry
  112. manifest-transaction-remove-pattern
  113. manifest-transaction-null?
  114. manifest-transaction-removal-candidate?
  115. manifest-perform-transaction
  116. manifest-transaction-effects
  117. profile-manifest
  118. package->manifest-entry
  119. package->development-manifest
  120. packages->manifest
  121. ca-certificate-bundle
  122. %default-profile-hooks
  123. %manifest-format-version
  124. profile-derivation
  125. profile-search-paths
  126. load-profile
  127. profile
  128. profile?
  129. profile-name
  130. profile-content
  131. profile-hooks
  132. profile-locales?
  133. profile-allow-collisions?
  134. profile-relative-symlinks?
  135. generation-number
  136. generation-profile
  137. generation-numbers
  138. profile-generations
  139. relative-generation-spec->number
  140. relative-generation
  141. previous-generation-number
  142. generation-time
  143. generation-file-name
  144. switch-to-generation
  145. roll-back
  146. delete-generation
  147. %user-profile-directory
  148. %profile-directory
  149. %current-profile
  150. ensure-profile-directory
  151. canonicalize-profile
  152. user-friendly-profile
  153. linux-module-database))
  154. ;;; Commentary:
  155. ;;;
  156. ;;; Tools to create and manipulate profiles---i.e., the representation of a
  157. ;;; set of installed packages.
  158. ;;;
  159. ;;; Code:
  160. ;;;
  161. ;;; Condition types.
  162. ;;;
  163. (define-condition-type &profile-error &error
  164. profile-error?
  165. (profile profile-error-profile))
  166. (define-condition-type &profile-not-found-error &profile-error
  167. profile-not-found-error?)
  168. (define-condition-type &profile-collision-error &error
  169. profile-collision-error?
  170. (entry profile-collision-error-entry) ;<manifest-entry>
  171. (conflict profile-collision-error-conflict)) ;<manifest-entry>
  172. (define-condition-type &unmatched-pattern-error &error
  173. unmatched-pattern-error?
  174. (pattern unmatched-pattern-error-pattern) ;<manifest-pattern>
  175. (manifest unmatched-pattern-error-manifest)) ;<manifest>
  176. (define-condition-type &missing-generation-error &profile-error
  177. missing-generation-error?
  178. (generation missing-generation-error-generation))
  179. ;;;
  180. ;;; Manifests.
  181. ;;;
  182. (define-record-type <manifest>
  183. (manifest entries)
  184. manifest?
  185. (entries manifest-entries)) ; list of <manifest-entry>
  186. ;; Convenient alias, to avoid name clashes.
  187. (define make-manifest manifest)
  188. (define-record-type* <manifest-entry> manifest-entry
  189. make-manifest-entry
  190. manifest-entry?
  191. (name manifest-entry-name) ; string
  192. (version manifest-entry-version) ; string
  193. (output manifest-entry-output ; string
  194. (default "out"))
  195. (item manifest-entry-item) ; package | file-like | store path
  196. (dependencies manifest-entry-dependencies ; <manifest-entry>*
  197. (default '()))
  198. (search-paths manifest-entry-search-paths ; search-path-specification*
  199. (default '()))
  200. (parent manifest-entry-parent ; promise (#f | <manifest-entry>)
  201. (default (delay #f)))
  202. (properties manifest-entry-properties ; list of symbol/value pairs
  203. (default '())))
  204. (define-record-type* <manifest-pattern> manifest-pattern
  205. make-manifest-pattern
  206. manifest-pattern?
  207. (name manifest-pattern-name) ; string
  208. (version manifest-pattern-version ; string | #f
  209. (default #f))
  210. (output manifest-pattern-output ; string | #f
  211. (default "out")))
  212. (define (list=? = lst1 lst2)
  213. "Return true if LST1 and LST2 have the same length and their elements are
  214. pairwise equal per =."
  215. (match lst1
  216. (()
  217. (null? lst2))
  218. ((head1 . tail1)
  219. (match lst2
  220. ((head2 . tail2)
  221. (and (= head1 head2) (list=? = tail1 tail2)))
  222. (()
  223. #f)))))
  224. (define (manifest-entry=? entry1 entry2)
  225. "Return true if ENTRY1 is equivalent to ENTRY2, ignoring their 'properties'
  226. field."
  227. (match entry1
  228. (($ <manifest-entry> name1 version1 output1 item1 dependencies1 paths1)
  229. (match entry2
  230. (($ <manifest-entry> name2 version2 output2 item2 dependencies2 paths2)
  231. (and (string=? name1 name2)
  232. (string=? version1 version2)
  233. (string=? output1 output2)
  234. (equal? item1 item2) ;XXX: could be <package> vs. store item
  235. (equal? paths1 paths2)
  236. (list=? manifest-entry=? dependencies1 dependencies2)))))))
  237. (define (manifest-transitive-entries manifest)
  238. "Return the entries of MANIFEST along with their propagated inputs,
  239. recursively."
  240. (let loop ((entries (manifest-entries manifest))
  241. (result '())
  242. (visited vlist-null)) ;compare with 'manifest-entry=?'
  243. (match entries
  244. (()
  245. (reverse result))
  246. ((head . tail)
  247. (if (vhash-assoc head visited manifest-entry=?)
  248. (loop tail result visited)
  249. (loop (append (manifest-entry-dependencies head)
  250. tail)
  251. (cons head result)
  252. (vhash-cons head #t visited)))))))
  253. (define (profile-manifest profile)
  254. "Return the PROFILE's manifest."
  255. (let ((file (string-append profile "/manifest")))
  256. (if (file-exists? file)
  257. (call-with-input-file file read-manifest)
  258. (manifest '()))))
  259. (define (manifest-entry-lookup manifest)
  260. "Return a lookup procedure for the entries of MANIFEST. The lookup
  261. procedure takes two arguments: the entry name and output."
  262. (define mapping
  263. (let loop ((entries (manifest-entries manifest))
  264. (mapping vlist-null))
  265. (fold (lambda (entry result)
  266. (vhash-cons (cons (manifest-entry-name entry)
  267. (manifest-entry-output entry))
  268. entry
  269. (loop (manifest-entry-dependencies entry)
  270. result)))
  271. mapping
  272. entries)))
  273. (lambda (name output)
  274. (match (vhash-assoc (cons name output) mapping)
  275. ((_ . entry) entry)
  276. (#f #f))))
  277. (define* (lower-manifest-entry entry system #:key target)
  278. "Lower ENTRY for SYSTEM and TARGET such that its 'item' field is a store
  279. file name."
  280. (define (recurse entry)
  281. (mapm/accumulate-builds (lambda (entry)
  282. (lower-manifest-entry entry system
  283. #:target target))
  284. (manifest-entry-dependencies entry)))
  285. (let ((item (manifest-entry-item entry)))
  286. (if (string? item)
  287. (with-monad %store-monad
  288. (return entry))
  289. (mlet %store-monad ((drv (lower-object item system
  290. #:target target))
  291. (dependencies (recurse entry))
  292. (output -> (manifest-entry-output entry)))
  293. (return (manifest-entry
  294. (inherit entry)
  295. (item (derivation->output-path drv output))
  296. (dependencies dependencies)))))))
  297. (define* (check-for-collisions manifest system #:key target)
  298. "Check whether the entries of MANIFEST conflict with one another; raise a
  299. '&profile-collision-error' when a conflict is encountered."
  300. (define lookup
  301. (manifest-entry-lookup manifest))
  302. (define candidates
  303. (filter-map (lambda (entry)
  304. (let ((other (lookup (manifest-entry-name entry)
  305. (manifest-entry-output entry))))
  306. (and other
  307. (not (eq? (manifest-entry-item entry)
  308. (manifest-entry-item other)))
  309. (list entry other))))
  310. (manifest-transitive-entries manifest)))
  311. (define lower-pair
  312. (match-lambda
  313. ((first second)
  314. (mlet %store-monad ((first (lower-manifest-entry first system
  315. #:target target))
  316. (second (lower-manifest-entry second system
  317. #:target target)))
  318. (return (list first second))))))
  319. ;; Start by lowering CANDIDATES "in parallel".
  320. (mlet %store-monad ((lst (mapm/accumulate-builds lower-pair candidates)))
  321. (foldm %store-monad
  322. (lambda (entries result)
  323. (match entries
  324. ((first second)
  325. (if (string=? (manifest-entry-item first)
  326. (manifest-entry-item second))
  327. (return result)
  328. (raise (condition
  329. (&profile-collision-error
  330. (entry first)
  331. (conflict second))))))))
  332. #t
  333. lst)))
  334. (define (default-properties package)
  335. "Return the default properties of a manifest entry for PACKAGE."
  336. ;; Preserve transformation options by default.
  337. (match (assq-ref (package-properties package) 'transformations)
  338. (#f '())
  339. (transformations `((transformations . ,transformations)))))
  340. (define* (package->manifest-entry package #:optional (output "out")
  341. #:key (parent (delay #f))
  342. (properties (default-properties package)))
  343. "Return a manifest entry for the OUTPUT of package PACKAGE."
  344. ;; For each dependency, keep a promise pointing to its "parent" entry.
  345. (letrec* ((deps (map (match-lambda
  346. ((label package)
  347. (package->manifest-entry package
  348. #:parent (delay entry)))
  349. ((label package output)
  350. (package->manifest-entry package output
  351. #:parent (delay entry))))
  352. (package-propagated-inputs package)))
  353. (entry (manifest-entry
  354. (name (package-name package))
  355. (version (package-version package))
  356. (output output)
  357. (item package)
  358. (dependencies (delete-duplicates deps))
  359. (search-paths
  360. (package-transitive-native-search-paths package))
  361. (parent parent)
  362. (properties properties))))
  363. entry))
  364. (define* (package->development-manifest package
  365. #:optional
  366. (system (%current-system))
  367. #:key target)
  368. "Return a manifest for the \"development inputs\" of PACKAGE for SYSTEM,
  369. optionally when cross-compiling to TARGET. Development inputs include both
  370. explicit and implicit inputs of PACKAGE."
  371. (manifest
  372. (filter-map (match-lambda
  373. ((label (? package? package))
  374. (package->manifest-entry package))
  375. ((label (? package? package) output)
  376. (package->manifest-entry package output))
  377. ;; TODO: Support <inferior-package>.
  378. (_
  379. #f))
  380. (package-development-inputs package system #:target target))))
  381. (define (packages->manifest packages)
  382. "Return a list of manifest entries, one for each item listed in PACKAGES.
  383. Elements of PACKAGES can be either package objects or package/string tuples
  384. denoting a specific output of a package."
  385. (define inferiors-loaded?
  386. ;; This hack allows us to provide seamless integration for inferior
  387. ;; packages while not having a hard dependency on (guix inferior).
  388. (resolve-module '(guix inferior) #f #f #:ensure #f))
  389. (define (inferior->entry)
  390. (module-ref (resolve-interface '(guix inferior))
  391. 'inferior-package->manifest-entry))
  392. (manifest
  393. (delete-duplicates
  394. (map (match-lambda
  395. (((? package? package) output)
  396. (package->manifest-entry package output))
  397. ((? package? package)
  398. (package->manifest-entry package))
  399. ((thing output)
  400. (if inferiors-loaded?
  401. ((inferior->entry) thing output)
  402. (throw 'wrong-type-arg 'packages->manifest
  403. "Wrong package object: ~S" (list thing) (list thing))))
  404. (thing
  405. (if inferiors-loaded?
  406. ((inferior->entry) thing)
  407. (throw 'wrong-type-arg 'packages->manifest
  408. "Wrong package object: ~S" (list thing) (list thing)))))
  409. packages)
  410. manifest-entry=?)))
  411. (define %manifest-format-version
  412. ;; The current manifest format version.
  413. 4)
  414. (define* (manifest->gexp manifest #:optional
  415. (format-version %manifest-format-version))
  416. "Return a representation in FORMAT-VERSION of MANIFEST as a gexp."
  417. (define (optional name value)
  418. (match format-version
  419. (4
  420. (if (null? value)
  421. #~()
  422. #~((#$name #$value))))
  423. (3
  424. (match name
  425. ('properties #~((#$name #$@value)))
  426. (_ #~((#$name #$value)))))))
  427. (define (entry->gexp entry)
  428. ;; Maintain in state monad a vhash of visited entries, indexed by their
  429. ;; item, usually package objects (we cannot use the entry itself as an
  430. ;; index since identical entries are usually not 'eq?'). Use that vhash
  431. ;; to avoid repeating duplicate entries. This is particularly useful in
  432. ;; the presence of propagated inputs, where we could otherwise end up
  433. ;; repeating large trees.
  434. (mlet %state-monad ((visited (current-state)))
  435. (if (and (= format-version 4)
  436. (match (vhash-assq (manifest-entry-item entry) visited)
  437. ((_ . previous-entry)
  438. (manifest-entry=? previous-entry entry))
  439. (#f #f)))
  440. (return #~(repeated #$(manifest-entry-name entry)
  441. #$(manifest-entry-version entry)
  442. (ungexp (manifest-entry-item entry)
  443. (manifest-entry-output entry))))
  444. (mbegin %state-monad
  445. (set-current-state (vhash-consq (manifest-entry-item entry)
  446. entry visited))
  447. (mlet %state-monad ((deps (mapm %state-monad entry->gexp
  448. (manifest-entry-dependencies entry))))
  449. (return
  450. (match entry
  451. (($ <manifest-entry> name version output (? string? path)
  452. (_ ...) (search-paths ...) _ (properties ...))
  453. #~(#$name #$version #$output #$path
  454. #$@(optional 'propagated-inputs deps)
  455. #$@(optional 'search-paths
  456. (map search-path-specification->sexp
  457. search-paths))
  458. #$@(optional 'properties properties)))
  459. (($ <manifest-entry> name version output package
  460. (_deps ...) (search-paths ...) _ (properties ...))
  461. #~(#$name #$version #$output
  462. (ungexp package (or output "out"))
  463. #$@(optional 'propagated-inputs deps)
  464. #$@(optional 'search-paths
  465. (map search-path-specification->sexp
  466. search-paths))
  467. #$@(optional 'properties properties))))))))))
  468. (unless (memq format-version '(3 4))
  469. (raise (formatted-message
  470. (G_ "cannot emit manifests formatted as version ~a")
  471. format-version)))
  472. (match manifest
  473. (($ <manifest> (entries ...))
  474. #~(manifest (version #$format-version)
  475. (packages #$(run-with-state
  476. (mapm %state-monad entry->gexp entries)
  477. vlist-null))))))
  478. (define (sexp->manifest sexp)
  479. "Parse SEXP as a manifest."
  480. (define (infer-dependency item parent)
  481. ;; Return a <manifest-entry> for ITEM.
  482. (let-values (((name version)
  483. (package-name->name+version
  484. (store-path-package-name item))))
  485. (manifest-entry
  486. (name name)
  487. (version version)
  488. (item item)
  489. (parent parent))))
  490. (define* (sexp->manifest-entry/v3 sexp #:optional (parent (delay #f)))
  491. ;; Read SEXP as a version 3 manifest entry.
  492. (match sexp
  493. ((name version output path
  494. ('propagated-inputs deps)
  495. ('search-paths search-paths)
  496. extra-stuff ...)
  497. ;; For each of DEPS, keep a promise pointing to ENTRY.
  498. (letrec* ((deps* (map (cut sexp->manifest-entry/v3 <> (delay entry))
  499. deps))
  500. (entry (manifest-entry
  501. (name name)
  502. (version version)
  503. (output output)
  504. (item path)
  505. (dependencies deps*)
  506. (search-paths (map sexp->search-path-specification
  507. search-paths))
  508. (parent parent)
  509. (properties (or (assoc-ref extra-stuff 'properties)
  510. '())))))
  511. entry))))
  512. (define-syntax let-fields
  513. (syntax-rules ()
  514. ;; Bind the fields NAME of LST to same-named variables in the lexical
  515. ;; scope of BODY.
  516. ((_ lst (name rest ...) body ...)
  517. (let ((name (match (assq 'name lst)
  518. ((_ value) value)
  519. (#f '()))))
  520. (let-fields lst (rest ...) body ...)))
  521. ((_ lst () body ...)
  522. (begin body ...))))
  523. (define* (sexp->manifest-entry sexp #:optional (parent (delay #f)))
  524. (match sexp
  525. (('repeated name version path)
  526. ;; This entry is the same as another one encountered earlier; look it
  527. ;; up and return it.
  528. (mlet %state-monad ((visited (current-state))
  529. (key -> (list name version path)))
  530. (match (vhash-assoc key visited)
  531. (#f
  532. (raise (formatted-message
  533. (G_ "invalid repeated entry in profile: ~s")
  534. sexp)))
  535. ((_ . entry)
  536. (return entry)))))
  537. ((name version output path fields ...)
  538. (let-fields fields (propagated-inputs search-paths properties)
  539. (mlet* %state-monad
  540. ((entry -> #f)
  541. (deps (mapm %state-monad
  542. (cut sexp->manifest-entry <> (delay entry))
  543. propagated-inputs))
  544. (visited (current-state))
  545. (key -> (list name version path)))
  546. (set! entry ;XXX: emulate 'letrec*'
  547. (manifest-entry
  548. (name name)
  549. (version version)
  550. (output output)
  551. (item path)
  552. (dependencies deps)
  553. (search-paths (map sexp->search-path-specification
  554. search-paths))
  555. (parent parent)
  556. (properties properties)))
  557. (mbegin %state-monad
  558. (set-current-state (vhash-cons key entry visited))
  559. (return entry)))))))
  560. (match sexp
  561. ;; Versions 0 and 1 are no longer produced since 2015.
  562. ;; Version 2 adds search paths and is slightly more verbose.
  563. (('manifest ('version 2 minor-version ...)
  564. ('packages ((name version output path
  565. ('propagated-inputs deps)
  566. ('search-paths search-paths)
  567. extra-stuff ...)
  568. ...)))
  569. (manifest
  570. (map (lambda (name version output path deps search-paths)
  571. (letrec* ((deps* (map (cute infer-dependency <> (delay entry))
  572. deps))
  573. (entry (manifest-entry
  574. (name name)
  575. (version version)
  576. (output output)
  577. (item path)
  578. (dependencies deps*)
  579. (search-paths
  580. (map sexp->search-path-specification
  581. search-paths)))))
  582. entry))
  583. name version output path deps search-paths)))
  584. ;; Version 3 represents DEPS as full-blown manifest entries.
  585. (('manifest ('version 3 minor-version ...)
  586. ('packages (entries ...)))
  587. (manifest (map sexp->manifest-entry/v3 entries)))
  588. ;; Version 4 deduplicates repeated entries and makes manifest entry fields
  589. ;; such as 'propagated-inputs' and 'search-paths' optional.
  590. (('manifest ('version 4 minor-version ...)
  591. ('packages (entries ...)))
  592. (manifest (run-with-state
  593. (mapm %state-monad sexp->manifest-entry entries)
  594. vlist-null)))
  595. (_
  596. (raise (condition
  597. (&message (message "unsupported manifest format")))))))
  598. (define (read-manifest port)
  599. "Return the packages listed in MANIFEST."
  600. (sexp->manifest (read port)))
  601. (define (concatenate-manifests lst)
  602. "Concatenate the manifests listed in LST and return the resulting manifest."
  603. (manifest (append-map manifest-entries lst)))
  604. (define (map-manifest-entries proc manifest)
  605. "Apply PROC to all the entries of MANIFEST and return a new manifest."
  606. (make-manifest
  607. (map proc (manifest-entries manifest))))
  608. (define (entry-predicate pattern)
  609. "Return a procedure that returns #t when passed a manifest entry that
  610. matches NAME/OUTPUT/VERSION. OUTPUT and VERSION may be #f, in which case they
  611. are ignored."
  612. (match pattern
  613. (($ <manifest-pattern> name version output)
  614. (match-lambda
  615. (($ <manifest-entry> entry-name entry-version entry-output)
  616. (and (string=? entry-name name)
  617. (or (not entry-output) (not output)
  618. (string=? entry-output output))
  619. (or (not version)
  620. (string=? entry-version version))))))))
  621. (define (manifest-remove manifest patterns)
  622. "Remove entries for each of PATTERNS from MANIFEST. Each item in PATTERNS
  623. must be a manifest-pattern."
  624. (define (remove-entry pattern lst)
  625. (remove (entry-predicate pattern) lst))
  626. (make-manifest (fold remove-entry
  627. (manifest-entries manifest)
  628. patterns)))
  629. (define (manifest-add manifest entries)
  630. "Add a list of manifest ENTRIES to MANIFEST and return new manifest.
  631. Remove MANIFEST entries that have the same name and output as ENTRIES."
  632. (define (same-entry? entry name output)
  633. (match entry
  634. (($ <manifest-entry> entry-name _ entry-output _)
  635. (and (equal? name entry-name)
  636. (equal? output entry-output)))))
  637. (make-manifest
  638. (fold (lambda (entry result) ;XXX: quadratic
  639. (match entry
  640. (($ <manifest-entry> name _ out _)
  641. (cons entry
  642. (remove (cut same-entry? <> name out)
  643. result)))))
  644. (manifest-entries manifest)
  645. entries)))
  646. (define (manifest-lookup manifest pattern)
  647. "Return the first item of MANIFEST that matches PATTERN, or #f if there is
  648. no match.."
  649. (find (entry-predicate pattern)
  650. (manifest-entries manifest)))
  651. (define (manifest-installed? manifest pattern)
  652. "Return #t if MANIFEST has an entry matching PATTERN (a manifest-pattern),
  653. #f otherwise."
  654. (->bool (manifest-lookup manifest pattern)))
  655. (define (manifest-matching-entries manifest patterns)
  656. "Return all the entries of MANIFEST that match one of the PATTERNS. Raise
  657. an '&unmatched-pattern-error' if none of the entries of MANIFEST matches one
  658. of PATTERNS."
  659. (fold-right (lambda (pattern matches)
  660. (match (filter (entry-predicate pattern)
  661. (manifest-entries manifest))
  662. (()
  663. (raise (condition
  664. (&unmatched-pattern-error
  665. (pattern pattern)
  666. (manifest manifest)))))
  667. (lst
  668. (append lst matches))))
  669. '()
  670. patterns))
  671. (define (manifest-search-paths manifest)
  672. "Return the list of search path specifications that apply to MANIFEST,
  673. including the search path specification for $PATH."
  674. (delete-duplicates
  675. (cons $PATH
  676. (append-map manifest-entry-search-paths
  677. (manifest-entries manifest)))))
  678. (define* (manifest->code manifest
  679. #:key (entry-package-version (const "")))
  680. "Return an sexp representing code to build an approximate version of
  681. MANIFEST; the code is wrapped in a top-level 'begin' form. Call
  682. ENTRY-PACKAGE-VERSION to determine the version number to use in the spec for a
  683. given entry; it can be set to 'manifest-entry-version' for fully-specified
  684. version numbers, or to some other procedure to disambiguate versions for
  685. packages for which several versions are available."
  686. (define (entry-transformations entry)
  687. ;; Return the transformations that apply to ENTRY.
  688. (assoc-ref (manifest-entry-properties entry) 'transformations))
  689. (define transformation-procedures
  690. ;; List of transformation options/procedure name pairs.
  691. (let loop ((entries (manifest-entries manifest))
  692. (counter 1)
  693. (result '()))
  694. (match entries
  695. (() result)
  696. ((entry . tail)
  697. (match (entry-transformations entry)
  698. (#f
  699. (loop tail counter result))
  700. (options
  701. (if (assoc-ref result options)
  702. (loop tail counter result)
  703. (loop tail (+ 1 counter)
  704. (alist-cons options
  705. (string->symbol
  706. (format #f "transform~a" counter))
  707. result)))))))))
  708. (define (qualified-name entry)
  709. ;; Return the name of ENTRY possibly with "@" followed by a version.
  710. (match (entry-package-version entry)
  711. ("" (manifest-entry-name entry))
  712. (version (string-append (manifest-entry-name entry)
  713. "@" version))))
  714. (if (null? transformation-procedures)
  715. `(begin ;simplest case
  716. (specifications->manifest
  717. (list ,@(map (lambda (entry)
  718. (match (manifest-entry-output entry)
  719. ("out" (qualified-name entry))
  720. (output (string-append (qualified-name entry)
  721. ":" output))))
  722. (manifest-entries manifest)))))
  723. (let* ((transform (lambda (options exp)
  724. (if (not options)
  725. exp
  726. (let ((proc (assoc-ref transformation-procedures
  727. options)))
  728. `(,proc ,exp))))))
  729. `(begin ;transformations apply
  730. (use-modules (guix transformations))
  731. ,@(map (match-lambda
  732. ((options . name)
  733. `(define ,name
  734. (options->transformation ',options))))
  735. transformation-procedures)
  736. (packages->manifest
  737. (list ,@(map (lambda (entry)
  738. (define options
  739. (entry-transformations entry))
  740. (define name
  741. (qualified-name entry))
  742. (match (manifest-entry-output entry)
  743. ("out"
  744. (transform options
  745. `(specification->package ,name)))
  746. (output
  747. `(list ,(transform
  748. options
  749. `(specification->package ,name))
  750. ,output))))
  751. (manifest-entries manifest))))))))
  752. ;;;
  753. ;;; Manifest transactions.
  754. ;;;
  755. (define-record-type* <manifest-transaction> manifest-transaction
  756. make-manifest-transaction
  757. manifest-transaction?
  758. (install manifest-transaction-install ; list of <manifest-entry>
  759. (default '()))
  760. (remove manifest-transaction-remove ; list of <manifest-pattern>
  761. (default '())))
  762. (define (manifest-transaction-install-entry entry transaction)
  763. "Augment TRANSACTION's set of installed packages with ENTRY, a
  764. <manifest-entry>."
  765. (manifest-transaction
  766. (inherit transaction)
  767. (install
  768. (cons entry (manifest-transaction-install transaction)))))
  769. (define (manifest-transaction-remove-pattern pattern transaction)
  770. "Add PATTERN to TRANSACTION's list of packages to remove."
  771. (manifest-transaction
  772. (inherit transaction)
  773. (remove
  774. (cons pattern (manifest-transaction-remove transaction)))))
  775. (define (manifest-transaction-null? transaction)
  776. "Return true if TRANSACTION has no effect---i.e., it neither installs nor
  777. remove software."
  778. (match transaction
  779. (($ <manifest-transaction> () ()) #t)
  780. (($ <manifest-transaction> _ _) #f)))
  781. (define (manifest-transaction-removal-candidate? entry transaction)
  782. "Return true if ENTRY is a candidate for removal in TRANSACTION."
  783. (any (lambda (pattern)
  784. ((entry-predicate pattern) entry))
  785. (manifest-transaction-remove transaction)))
  786. (define (manifest-transaction-effects manifest transaction)
  787. "Compute the effect of applying TRANSACTION to MANIFEST. Return 4 values:
  788. the list of packages that would be removed, installed, upgraded, or downgraded
  789. when applying TRANSACTION to MANIFEST. Upgrades are represented as pairs
  790. where the head is the entry being upgraded and the tail is the entry that will
  791. replace it."
  792. (define (manifest-entry->pattern entry)
  793. (manifest-pattern
  794. (name (manifest-entry-name entry))
  795. (output (manifest-entry-output entry))))
  796. (define manifest-entry-pair=?
  797. (match-lambda*
  798. (((m1a . m2a) (m1b . m2b))
  799. (and (manifest-entry=? m1a m1b)
  800. (manifest-entry=? m2a m2b)))
  801. (_ #f)))
  802. (let loop ((input (manifest-transaction-install transaction))
  803. (install '())
  804. (upgrade '())
  805. (downgrade '()))
  806. (match input
  807. (()
  808. (let ((remove (manifest-transaction-remove transaction)))
  809. (values (delete-duplicates
  810. (manifest-matching-entries manifest remove)
  811. manifest-entry=?)
  812. (delete-duplicates (reverse install) manifest-entry=?)
  813. (delete-duplicates
  814. (reverse upgrade)
  815. manifest-entry-pair=?)
  816. (delete-duplicates
  817. (reverse downgrade)
  818. manifest-entry-pair=?))))
  819. ((entry rest ...)
  820. ;; Check whether installing ENTRY corresponds to the installation of a
  821. ;; new package or to an upgrade.
  822. ;; XXX: When the exact same output directory is installed, we're not
  823. ;; really upgrading anything. Add a check for that case.
  824. (let* ((pattern (manifest-entry->pattern entry))
  825. (previous (manifest-lookup manifest pattern))
  826. (newer? (and previous
  827. (version>=? (manifest-entry-version entry)
  828. (manifest-entry-version previous)))))
  829. (loop rest
  830. (if previous install (cons entry install))
  831. (if (and previous newer?)
  832. (alist-cons previous entry upgrade)
  833. upgrade)
  834. (if (and previous (not newer?))
  835. (alist-cons previous entry downgrade)
  836. downgrade)))))))
  837. (define (manifest-perform-transaction manifest transaction)
  838. "Perform TRANSACTION on MANIFEST and return the new manifest."
  839. (let ((install (manifest-transaction-install transaction))
  840. (remove (manifest-transaction-remove transaction)))
  841. (manifest-add (manifest-remove manifest remove)
  842. install)))
  843. ;;;
  844. ;;; Profiles.
  845. ;;;
  846. (define (manifest-inputs manifest)
  847. "Return a list of <gexp-input> objects for MANIFEST."
  848. (define entry->input
  849. (match-lambda
  850. (($ <manifest-entry> name version output thing deps)
  851. ;; THING may be a package or a file name. In the latter case, assume
  852. ;; it's already valid.
  853. (cons (gexp-input thing output)
  854. (append-map entry->input deps)))))
  855. (append-map entry->input (manifest-entries manifest)))
  856. (define* (manifest-lookup-package manifest name #:optional version)
  857. "Return as a monadic value the first package or store path referenced by
  858. MANIFEST that is named NAME and optionally has the given VERSION prefix, or #f
  859. if not found."
  860. ;; Return as a monadic value the package or store path referenced by the
  861. ;; manifest ENTRY, or #f if not referenced.
  862. (define (entry-lookup-package entry)
  863. (define (find-among-inputs inputs)
  864. (find (lambda (input)
  865. (and (package? input)
  866. (equal? name (package-name input))
  867. (if version
  868. (string-prefix? version (package-version input))
  869. #t)))
  870. inputs))
  871. (define (find-among-store-items items)
  872. (find (lambda (item)
  873. (let-values (((name* version*)
  874. (package-name->name+version
  875. (store-path-package-name item))))
  876. (and (string=? name name*)
  877. (if version
  878. (string-prefix? version version*)
  879. #t))))
  880. items))
  881. (with-monad %store-monad
  882. (match (manifest-entry-item entry)
  883. ((? package? package)
  884. (match (cons (list (package-name package) package)
  885. (package-transitive-inputs package))
  886. (((labels inputs . _) ...)
  887. (return (find-among-inputs inputs)))))
  888. ((? string? item)
  889. (mlet %store-monad ((refs (references* item)))
  890. (return (find-among-store-items refs))))
  891. (item
  892. ;; XXX: ITEM might be a 'computed-file' or anything like that, in
  893. ;; which case we don't know what to do. The fix may be to check
  894. ;; references once ITEM is compiled, as proposed at
  895. ;; <https://bugs.gnu.org/29927>.
  896. (return #f)))))
  897. (anym %store-monad
  898. entry-lookup-package (manifest-entries manifest)))
  899. (define (info-dir-file manifest)
  900. "Return a derivation that builds the 'dir' file for all the entries of
  901. MANIFEST."
  902. (define texinfo ;lazy reference
  903. (module-ref (resolve-interface '(gnu packages texinfo)) 'texinfo))
  904. (define gzip ;lazy reference
  905. (module-ref (resolve-interface '(gnu packages compression)) 'gzip))
  906. (define glibc-utf8-locales ;lazy reference
  907. (module-ref (resolve-interface '(gnu packages base)) 'glibc-utf8-locales))
  908. (define build
  909. (with-imported-modules '((guix build utils))
  910. #~(begin
  911. (use-modules (guix build utils)
  912. (srfi srfi-1) (srfi srfi-26)
  913. (ice-9 ftw))
  914. (define (info-file? file)
  915. (or (string-suffix? ".info" file)
  916. (string-suffix? ".info.gz" file)))
  917. (define (info-files top)
  918. (let ((infodir (string-append top "/share/info")))
  919. (map (cut string-append infodir "/" <>)
  920. (or (scandir infodir info-file?) '()))))
  921. (define (info-file-language file)
  922. (let* ((base (if (string-suffix? ".gz" file)
  923. (basename file ".info.gz")
  924. (basename file ".info")))
  925. (dot (string-rindex base #\.)))
  926. (if dot
  927. (string-drop base (+ 1 dot))
  928. "en")))
  929. (define (install-info info)
  930. (let ((language (info-file-language info)))
  931. ;; We need to choose a valid locale for $LANGUAGE to be honored.
  932. (setenv "LC_ALL" "en_US.utf8")
  933. (setenv "LANGUAGE" language)
  934. (zero?
  935. (system* #+(file-append texinfo "/bin/install-info")
  936. info
  937. (apply string-append #$output "/share/info/dir"
  938. (if (string=? "en" language)
  939. '("")
  940. `("." ,language)))))))
  941. (setenv "PATH" (string-append #+gzip "/bin")) ;for info.gz files
  942. (setenv "GUIX_LOCPATH"
  943. #+(file-append glibc-utf8-locales "/lib/locale"))
  944. (mkdir-p (string-append #$output "/share/info"))
  945. (exit (every install-info
  946. (append-map info-files
  947. '#$(manifest-inputs manifest)))))))
  948. (gexp->derivation "info-dir" build
  949. #:local-build? #t
  950. #:substitutable? #f
  951. #:properties
  952. `((type . profile-hook)
  953. (hook . info-dir))))
  954. (define (ghc-package-cache-file manifest)
  955. "Return a derivation that builds the GHC 'package.cache' file for all the
  956. entries of MANIFEST, or #f if MANIFEST does not have any GHC packages."
  957. (define ghc ;lazy reference
  958. (module-ref (resolve-interface '(gnu packages haskell)) 'ghc))
  959. (define build
  960. (with-imported-modules '((guix build utils))
  961. #~(begin
  962. (use-modules (guix build utils)
  963. (srfi srfi-1) (srfi srfi-26)
  964. (ice-9 ftw))
  965. (define ghc-name-version
  966. (let* ((base (basename #+ghc)))
  967. (string-drop base
  968. (+ 1 (string-index base #\-)))))
  969. (define db-subdir
  970. (string-append "lib/" ghc-name-version "/package.conf.d"))
  971. (define db-dir
  972. (string-append #$output "/" db-subdir))
  973. (define (conf-files top)
  974. (let ((db (string-append top "/" db-subdir)))
  975. (if (file-exists? db)
  976. (find-files db "\\.conf$")
  977. '())))
  978. (define (copy-conf-file conf)
  979. (let ((base (basename conf)))
  980. (copy-file conf (string-append db-dir "/" base))))
  981. (system* (string-append #+ghc "/bin/ghc-pkg") "init" db-dir)
  982. (for-each copy-conf-file
  983. (append-map conf-files
  984. (delete-duplicates
  985. '#$(manifest-inputs manifest))))
  986. (let ((success
  987. (zero?
  988. (system* (string-append #+ghc "/bin/ghc-pkg") "recache"
  989. (string-append "--package-db=" db-dir)))))
  990. (for-each delete-file (find-files db-dir "\\.conf$"))
  991. (exit success)))))
  992. (with-monad %store-monad
  993. ;; Don't depend on GHC when there's nothing to do.
  994. (if (any (cut string-prefix? "ghc" <>)
  995. (map manifest-entry-name (manifest-entries manifest)))
  996. (gexp->derivation "ghc-package-cache" build
  997. #:local-build? #t
  998. #:substitutable? #f
  999. #:properties
  1000. `((type . profile-hook)
  1001. (hook . ghc-package-cache)))
  1002. (return #f))))
  1003. (define (ca-certificate-bundle manifest)
  1004. "Return a derivation that builds a single-file bundle containing the CA
  1005. certificates in the /etc/ssl/certs sub-directories of the packages in
  1006. MANIFEST. Single-file bundles are required by programs such as Git and Lynx."
  1007. ;; See <http://lists.gnu.org/archive/html/guix-devel/2015-02/msg00429.html>
  1008. ;; for a discussion.
  1009. (define glibc-utf8-locales ;lazy reference
  1010. (module-ref (resolve-interface '(gnu packages base)) 'glibc-utf8-locales))
  1011. (define build
  1012. (with-imported-modules '((guix build utils))
  1013. #~(begin
  1014. (use-modules (guix build utils)
  1015. (rnrs io ports)
  1016. (srfi srfi-1)
  1017. (srfi srfi-26)
  1018. (ice-9 ftw)
  1019. (ice-9 match))
  1020. (define (pem-file? file)
  1021. (string-suffix? ".pem" file))
  1022. (define (ca-files top)
  1023. (let ((cert-dir (string-append top "/etc/ssl/certs")))
  1024. (map (cut string-append cert-dir "/" <>)
  1025. (or (scandir cert-dir pem-file?) '()))))
  1026. (define (concatenate-files files result)
  1027. "Make RESULT the concatenation of all of FILES."
  1028. (define (dump file port)
  1029. (display (call-with-input-file file get-string-all)
  1030. port)
  1031. (newline port)) ;required, see <https://bugs.debian.org/635570>
  1032. (call-with-output-file result
  1033. (lambda (port)
  1034. (for-each (cut dump <> port) files))))
  1035. ;; Some file names in the NSS certificates are UTF-8 encoded so
  1036. ;; install a UTF-8 locale.
  1037. (setenv "LOCPATH"
  1038. (string-append #+glibc-utf8-locales "/lib/locale/"
  1039. #+(version-major+minor
  1040. (package-version glibc-utf8-locales))))
  1041. (setlocale LC_ALL "en_US.utf8")
  1042. (match (append-map ca-files '#$(manifest-inputs manifest))
  1043. (()
  1044. ;; Since there are no CA files, just create an empty directory. Do
  1045. ;; not create the etc/ssl/certs sub-directory, since that would
  1046. ;; wrongfully lead to a message about 'SSL_CERT_DIR' needing to be
  1047. ;; defined.
  1048. (mkdir #$output)
  1049. #t)
  1050. ((ca-files ...)
  1051. (let ((result (string-append #$output "/etc/ssl/certs")))
  1052. (mkdir-p result)
  1053. (concatenate-files ca-files
  1054. (string-append result
  1055. "/ca-certificates.crt"))
  1056. #t))))))
  1057. (gexp->derivation "ca-certificate-bundle" build
  1058. #:local-build? #t
  1059. #:substitutable? #f
  1060. #:properties
  1061. `((type . profile-hook)
  1062. (hook . ca-certificate-bundle))))
  1063. (define (emacs-subdirs manifest)
  1064. (define build
  1065. (with-imported-modules (source-module-closure
  1066. '((guix build profiles)
  1067. (guix build utils)))
  1068. #~(begin
  1069. (use-modules (guix build utils)
  1070. (guix build profiles)
  1071. (ice-9 ftw) ; scandir
  1072. (srfi srfi-1) ; append-map
  1073. (srfi srfi-26))
  1074. (let ((destdir (string-append #$output "/share/emacs/site-lisp"))
  1075. (subdirs
  1076. (append-map
  1077. (lambda (dir)
  1078. (filter
  1079. file-is-directory?
  1080. (map (cute string-append dir "/" <>)
  1081. (scandir dir (negate (cute member <> '("." "..")))))))
  1082. (filter file-exists?
  1083. (map (cute string-append <> "/share/emacs/site-lisp")
  1084. '#$(manifest-inputs manifest))))))
  1085. (mkdir-p destdir)
  1086. (with-directory-excursion destdir
  1087. (call-with-output-file "subdirs.el"
  1088. (lambda (port)
  1089. (write
  1090. `(normal-top-level-add-to-load-path
  1091. (list ,@(delete-duplicates subdirs)))
  1092. port)
  1093. (newline port)
  1094. #t)))))))
  1095. (gexp->derivation "emacs-subdirs" build
  1096. #:local-build? #t
  1097. #:substitutable? #f
  1098. #:properties
  1099. `((type . profile-hook)
  1100. (hook . emacs-subdirs))))
  1101. (define (gdk-pixbuf-loaders-cache-file manifest)
  1102. "Return a derivation that produces a loaders cache file for every gdk-pixbuf
  1103. loaders discovered in MANIFEST."
  1104. (define gdk-pixbuf ;lazy reference
  1105. (module-ref (resolve-interface '(gnu packages gtk)) 'gdk-pixbuf))
  1106. (mlet* %store-monad
  1107. ((gdk-pixbuf (manifest-lookup-package manifest "gdk-pixbuf"))
  1108. (librsvg (manifest-lookup-package manifest "librsvg"))
  1109. (gdk-pixbuf-bin -> (if (string? gdk-pixbuf)
  1110. (string-append gdk-pixbuf "/bin")
  1111. (file-append gdk-pixbuf "/bin"))))
  1112. (define build
  1113. (with-imported-modules (source-module-closure
  1114. '((guix build glib-or-gtk-build-system)))
  1115. #~(begin
  1116. (use-modules (guix build glib-or-gtk-build-system))
  1117. (setenv "PATH" (string-append #$gdk-pixbuf-bin ":" (getenv "PATH")))
  1118. (generate-gdk-pixbuf-loaders-cache
  1119. ;; XXX: MANIFEST-LOOKUP-PACKAGE transitively searches through
  1120. ;; every input referenced by the manifest, while MANIFEST-INPUTS
  1121. ;; only retrieves the immediate inputs as well as their
  1122. ;; propagated inputs; to avoid causing an empty output derivation
  1123. ;; we must ensure that the inputs contain at least one
  1124. ;; loaders.cache file. This is why we include gdk-pixbuf or
  1125. ;; librsvg when they are transitively found.
  1126. (list #$@(if gdk-pixbuf
  1127. (list gdk-pixbuf)
  1128. '())
  1129. #$@(if librsvg
  1130. (list librsvg)
  1131. '())
  1132. #$@(manifest-inputs manifest))
  1133. (list #$output)))))
  1134. (if gdk-pixbuf
  1135. (gexp->derivation "gdk-pixbuf-loaders-cache-file" build
  1136. #:local-build? #t
  1137. #:substitutable? #f
  1138. #:properties
  1139. '((type . profile-hook)
  1140. (hook . gdk-pixbuf-loaders-cache-file)))
  1141. (return #f))))
  1142. (define (glib-schemas manifest)
  1143. "Return a derivation that unions all schemas from manifest entries and
  1144. creates the Glib 'gschemas.compiled' file."
  1145. (define glib ; lazy reference
  1146. (module-ref (resolve-interface '(gnu packages glib)) 'glib))
  1147. (mlet %store-monad ((%glib (manifest-lookup-package manifest "glib"))
  1148. ;; XXX: Can't use glib-compile-schemas corresponding
  1149. ;; to the glib referenced by 'manifest'. Because
  1150. ;; '%glib' can be either a package or store path, and
  1151. ;; there's no way to get the "bin" output for the later.
  1152. (glib-compile-schemas
  1153. -> #~(string-append #+glib:bin
  1154. "/bin/glib-compile-schemas")))
  1155. (define build
  1156. (with-imported-modules '((guix build utils)
  1157. (guix build union)
  1158. (guix build profiles)
  1159. (guix search-paths)
  1160. (guix records))
  1161. #~(begin
  1162. (use-modules (guix build utils)
  1163. (guix build union)
  1164. (guix build profiles)
  1165. (srfi srfi-26))
  1166. (let* ((destdir (string-append #$output "/share/glib-2.0/schemas"))
  1167. (schemadirs (filter file-exists?
  1168. (map (cut string-append <> "/share/glib-2.0/schemas")
  1169. '#$(manifest-inputs manifest)))))
  1170. ;; Union all the schemas.
  1171. (mkdir-p (string-append #$output "/share/glib-2.0"))
  1172. (union-build destdir schemadirs
  1173. #:log-port (%make-void-port "w"))
  1174. (let ((dir destdir))
  1175. (when (file-is-directory? dir)
  1176. (ensure-writable-directory dir)
  1177. (invoke #+glib-compile-schemas
  1178. (string-append "--targetdir=" dir)
  1179. dir)))))))
  1180. ;; Don't run the hook when there's nothing to do.
  1181. (if %glib
  1182. (gexp->derivation "glib-schemas" build
  1183. #:local-build? #t
  1184. #:substitutable? #f
  1185. #:properties
  1186. `((type . profile-hook)
  1187. (hook . glib-schemas)))
  1188. (return #f))))
  1189. (define (gtk-icon-themes manifest)
  1190. "Return a derivation that unions all icon themes from manifest entries and
  1191. creates the GTK+ 'icon-theme.cache' file for each theme."
  1192. (define gtk+ ; lazy reference
  1193. (module-ref (resolve-interface '(gnu packages gtk)) 'gtk+))
  1194. (mlet %store-monad ((%gtk+ (manifest-lookup-package manifest "gtk+"))
  1195. ;; XXX: Can't use gtk-update-icon-cache corresponding
  1196. ;; to the gtk+ referenced by 'manifest'. Because
  1197. ;; '%gtk+' can be either a package or store path, and
  1198. ;; there's no way to get the "bin" output for the later.
  1199. (gtk-update-icon-cache
  1200. -> #~(string-append #+gtk+:bin
  1201. "/bin/gtk-update-icon-cache")))
  1202. (define build
  1203. (with-imported-modules '((guix build utils)
  1204. (guix build union)
  1205. (guix build profiles)
  1206. (guix search-paths)
  1207. (guix records))
  1208. #~(begin
  1209. (use-modules (guix build utils)
  1210. (guix build union)
  1211. (guix build profiles)
  1212. (srfi srfi-26)
  1213. (ice-9 ftw))
  1214. (let* ((destdir (string-append #$output "/share/icons"))
  1215. (icondirs (filter file-exists?
  1216. (map (cut string-append <> "/share/icons")
  1217. '#$(manifest-inputs manifest)))))
  1218. ;; Union all the icons.
  1219. (mkdir-p (string-append #$output "/share"))
  1220. (union-build destdir icondirs
  1221. #:log-port (%make-void-port "w"))
  1222. ;; Update the 'icon-theme.cache' file for each icon theme.
  1223. (for-each
  1224. (lambda (theme)
  1225. (let ((dir (string-append destdir "/" theme)))
  1226. ;; Occasionally DESTDIR contains plain files, such as
  1227. ;; "abiword_48.png". Ignore these.
  1228. (when (file-is-directory? dir)
  1229. (ensure-writable-directory dir)
  1230. (system* #+gtk-update-icon-cache "-t" dir "--quiet"))))
  1231. (scandir destdir (negate (cut member <> '("." "..")))))))))
  1232. ;; Don't run the hook when there's nothing to do.
  1233. (if %gtk+
  1234. (gexp->derivation "gtk-icon-themes" build
  1235. #:local-build? #t
  1236. #:substitutable? #f
  1237. #:properties
  1238. `((type . profile-hook)
  1239. (hook . gtk-icon-themes)))
  1240. (return #f))))
  1241. (define (gtk-im-modules manifest)
  1242. "Return a derivation that builds the cache files for input method modules
  1243. for both major versions of GTK+."
  1244. (mlet %store-monad ((gtk+ (manifest-lookup-package manifest "gtk+" "3"))
  1245. (gtk+-2 (manifest-lookup-package manifest "gtk+" "2")))
  1246. (define (build gtk gtk-version query)
  1247. (let ((major (string-take gtk-version 1)))
  1248. (with-imported-modules '((guix build utils)
  1249. (guix build union)
  1250. (guix build profiles)
  1251. (guix search-paths)
  1252. (guix records))
  1253. #~(begin
  1254. (use-modules (guix build utils)
  1255. (guix build union)
  1256. (guix build profiles)
  1257. (ice-9 popen)
  1258. (srfi srfi-1)
  1259. (srfi srfi-26))
  1260. (let* ((prefix (string-append "/lib/gtk-" #$major ".0/"
  1261. #$gtk-version))
  1262. (destdir (string-append #$output prefix))
  1263. (moddirs (cons (string-append #$gtk prefix "/immodules")
  1264. (filter file-exists?
  1265. (map (cut string-append <> prefix "/immodules")
  1266. '#$(manifest-inputs manifest)))))
  1267. (modules (append-map (cut find-files <> "\\.so$")
  1268. moddirs)))
  1269. ;; Generate a new immodules cache file.
  1270. (mkdir-p (string-append #$output prefix))
  1271. (let ((pipe (apply open-pipe* OPEN_READ #$query modules))
  1272. (outfile (string-append #$output prefix
  1273. "/immodules-gtk" #$major ".cache")))
  1274. (dynamic-wind
  1275. (const #t)
  1276. (lambda ()
  1277. (call-with-output-file outfile
  1278. (lambda (out)
  1279. (while (not (eof-object? (peek-char pipe)))
  1280. (write-char (read-char pipe) out))))
  1281. #t)
  1282. (lambda ()
  1283. (close-pipe pipe)))))))))
  1284. ;; Don't run the hook when there's nothing to do.
  1285. (let* ((pkg-gtk+ (module-ref ; lazy reference
  1286. (resolve-interface '(gnu packages gtk)) 'gtk+))
  1287. (pkg-gtk+2 (module-ref ; lazy reference
  1288. (resolve-interface '(gnu packages gtk)) 'gtk+-2))
  1289. (gexp #~(begin
  1290. #$(if gtk+
  1291. (build
  1292. gtk+ "3.0.0"
  1293. ;; Use 'gtk-query-immodules-3.0' from the 'bin'
  1294. ;; output of latest gtk+ package.
  1295. #~(string-append
  1296. #$pkg-gtk+:bin "/bin/gtk-query-immodules-3.0"))
  1297. #t)
  1298. #$(if gtk+-2
  1299. (build
  1300. gtk+-2 "2.10.0"
  1301. #~(string-append
  1302. #$pkg-gtk+2:bin "/bin/gtk-query-immodules-2.0"))
  1303. #t))))
  1304. (if (or gtk+ gtk+-2)
  1305. (gexp->derivation "gtk-im-modules" gexp
  1306. #:local-build? #t
  1307. #:substitutable? #f
  1308. #:properties
  1309. `((type . profile-hook)
  1310. (hook . gtk-im-modules)))
  1311. (return #f)))))
  1312. (define (linux-module-database manifest)
  1313. "Return a derivation that unites all the kernel modules of the manifest
  1314. and creates the dependency graph of all these kernel modules.
  1315. This is meant to be used as a profile hook."
  1316. (define kmod ; lazy reference
  1317. (module-ref (resolve-interface '(gnu packages linux)) 'kmod))
  1318. (define guile-zlib
  1319. (module-ref (resolve-interface '(gnu packages guile)) 'guile-zlib))
  1320. (define build
  1321. (with-imported-modules (source-module-closure
  1322. '((guix build utils)
  1323. (gnu build linux-modules)))
  1324. (with-extensions (list guile-zlib)
  1325. #~(begin
  1326. (use-modules (ice-9 ftw)
  1327. (ice-9 match)
  1328. (srfi srfi-1) ; append-map
  1329. (gnu build linux-modules))
  1330. (let* ((inputs '#$(manifest-inputs manifest))
  1331. (module-directories
  1332. (map (lambda (directory)
  1333. (string-append directory "/lib/modules"))
  1334. inputs))
  1335. (directory-entries
  1336. (lambda (directory)
  1337. (or (scandir directory
  1338. (lambda (basename)
  1339. (not (string-prefix? "." basename))))
  1340. '())))
  1341. ;; Note: Should usually result in one entry.
  1342. (versions (delete-duplicates
  1343. (append-map directory-entries
  1344. module-directories))))
  1345. (match versions
  1346. ((version)
  1347. (let ((old-path (getenv "PATH")))
  1348. (setenv "PATH" #+(file-append kmod "/bin"))
  1349. (make-linux-module-directory inputs version #$output)
  1350. (setenv "PATH" old-path)))
  1351. (()
  1352. ;; Nothing here, maybe because this is a kernel with
  1353. ;; CONFIG_MODULES=n.
  1354. (mkdir #$output))
  1355. (_ (error "Specified Linux kernel and Linux kernel modules
  1356. are not all of the same version"))))))))
  1357. (gexp->derivation "linux-module-database" build
  1358. #:local-build? #t
  1359. #:substitutable? #f
  1360. #:properties
  1361. `((type . profile-hook)
  1362. (hook . linux-module-database))))
  1363. (define (xdg-desktop-database manifest)
  1364. "Return a derivation that builds the @file{mimeinfo.cache} database from
  1365. desktop files. It's used to query what applications can handle a given
  1366. MIME type."
  1367. (define desktop-file-utils ; lazy reference
  1368. (module-ref (resolve-interface '(gnu packages freedesktop))
  1369. 'desktop-file-utils))
  1370. (mlet %store-monad ((glib
  1371. (manifest-lookup-package
  1372. manifest "glib")))
  1373. (define build
  1374. (with-imported-modules '((guix build utils)
  1375. (guix build union))
  1376. #~(begin
  1377. (use-modules (srfi srfi-26)
  1378. (guix build utils)
  1379. (guix build union))
  1380. (let* ((destdir (string-append #$output "/share/applications"))
  1381. (appdirs (filter file-exists?
  1382. (map (cut string-append <>
  1383. "/share/applications")
  1384. '#$(manifest-inputs manifest))))
  1385. (update-desktop-database (string-append
  1386. #+desktop-file-utils
  1387. "/bin/update-desktop-database")))
  1388. (mkdir-p (string-append #$output "/share"))
  1389. (union-build destdir appdirs
  1390. #:log-port (%make-void-port "w"))
  1391. (exit (zero? (system* update-desktop-database destdir)))))))
  1392. ;; Don't run the hook when 'glib' is not referenced.
  1393. (if glib
  1394. (gexp->derivation "xdg-desktop-database" build
  1395. #:local-build? #t
  1396. #:substitutable? #f
  1397. #:properties
  1398. `((type . profile-hook)
  1399. (hook . xdg-desktop-database)))
  1400. (return #f))))
  1401. (define (xdg-mime-database manifest)
  1402. "Return a derivation that builds the @file{mime.cache} database from manifest
  1403. entries. It's used to query the MIME type of a given file."
  1404. (define shared-mime-info ; lazy reference
  1405. (module-ref (resolve-interface '(gnu packages gnome)) 'shared-mime-info))
  1406. (mlet %store-monad ((glib (manifest-lookup-package manifest "glib")))
  1407. (define build
  1408. (with-imported-modules '((guix build utils)
  1409. (guix build union))
  1410. #~(begin
  1411. (use-modules (guix build utils)
  1412. (guix build union)
  1413. (srfi srfi-26)
  1414. (ice-9 match))
  1415. (let* ((datadir (string-append #$output "/share"))
  1416. (destdir (string-append datadir "/mime"))
  1417. (pkgdirs (filter file-exists?
  1418. (map (cut string-append <>
  1419. "/share/mime/packages")
  1420. (cons #+shared-mime-info
  1421. '#$(manifest-inputs manifest))))))
  1422. (match pkgdirs
  1423. ((shared-mime-info)
  1424. ;; PKGDIRS contains nothing but 'shared-mime-info', which
  1425. ;; already contains its database, so nothing to do.
  1426. (mkdir-p datadir)
  1427. (symlink #$(file-append shared-mime-info "/share/mime")
  1428. destdir))
  1429. (_
  1430. ;; PKGDIRS contains additional packages providing
  1431. ;; 'share/mime/packages' (very few packages do so) so rebuild
  1432. ;; the database. TODO: Find a way to avoid reprocessing
  1433. ;; 'shared-mime-info', which is the most expensive one.
  1434. (mkdir-p destdir)
  1435. (union-build (string-append destdir "/packages") pkgdirs
  1436. #:log-port (%make-void-port "w"))
  1437. (setenv "XDG_DATA_HOME" datadir)
  1438. (invoke #+(file-append shared-mime-info
  1439. "/bin/update-mime-database")
  1440. destdir)))))))
  1441. ;; Don't run the hook when there are no GLib based applications.
  1442. (if glib
  1443. (gexp->derivation "xdg-mime-database" build
  1444. #:local-build? #t
  1445. #:substitutable? #f
  1446. #:properties
  1447. `((type . profile-hook)
  1448. (hook . xdg-mime-database)))
  1449. (return #f))))
  1450. ;; Several font packages may install font files into same directory, so
  1451. ;; fonts.dir and fonts.scale file should be generated here, instead of in
  1452. ;; packages.
  1453. (define (fonts-dir-file manifest)
  1454. "Return a derivation that builds the @file{fonts.dir} and @file{fonts.scale}
  1455. files for the fonts of the @var{manifest} entries."
  1456. (define mkfontscale
  1457. (module-ref (resolve-interface '(gnu packages xorg)) 'mkfontscale))
  1458. (define mkfontdir
  1459. (module-ref (resolve-interface '(gnu packages xorg)) 'mkfontdir))
  1460. (define build
  1461. #~(begin
  1462. (use-modules (srfi srfi-26)
  1463. (guix build utils)
  1464. (guix build union))
  1465. (let ((fonts-dirs (filter file-exists?
  1466. (map (cut string-append <>
  1467. "/share/fonts")
  1468. '#$(manifest-inputs manifest)))))
  1469. (mkdir #$output)
  1470. (if (null? fonts-dirs)
  1471. (exit #t)
  1472. (let* ((share-dir (string-append #$output "/share"))
  1473. (fonts-dir (string-append share-dir "/fonts"))
  1474. (mkfontscale (string-append #+mkfontscale
  1475. "/bin/mkfontscale"))
  1476. (mkfontdir (string-append #+mkfontdir
  1477. "/bin/mkfontdir"))
  1478. (empty-file? (lambda (filename)
  1479. (call-with-ascii-input-file filename
  1480. (lambda (p)
  1481. (eqv? #\0 (read-char p))))))
  1482. (fonts-dir-file "fonts.dir")
  1483. (fonts-scale-file "fonts.scale"))
  1484. (mkdir-p share-dir)
  1485. ;; Create all sub-directories, because we may create fonts.dir
  1486. ;; and fonts.scale files in the sub-directories.
  1487. (union-build fonts-dir fonts-dirs
  1488. #:log-port (%make-void-port "w")
  1489. #:create-all-directories? #t)
  1490. (let ((directories (find-files fonts-dir
  1491. (lambda (file stat)
  1492. (eq? 'directory (stat:type stat)))
  1493. #:directories? #t)))
  1494. (for-each (lambda (dir)
  1495. (with-directory-excursion dir
  1496. (when (file-exists? fonts-scale-file)
  1497. (delete-file fonts-scale-file))
  1498. (when (file-exists? fonts-dir-file)
  1499. (delete-file fonts-dir-file))
  1500. (unless (and (zero? (system* mkfontscale))
  1501. (zero? (system* mkfontdir)))
  1502. (exit #f))
  1503. (when (and (file-exists? fonts-scale-file)
  1504. (empty-file? fonts-scale-file))
  1505. (delete-file fonts-scale-file))
  1506. (when (and (file-exists? fonts-dir-file)
  1507. (empty-file? fonts-dir-file))
  1508. (delete-file fonts-dir-file))))
  1509. directories)))))))
  1510. (gexp->derivation "fonts-dir" build
  1511. #:modules '((guix build utils)
  1512. (guix build union)
  1513. (srfi srfi-26))
  1514. #:local-build? #t
  1515. #:substitutable? #f
  1516. #:properties
  1517. `((type . profile-hook)
  1518. (hook . fonts-dir))))
  1519. (define (manual-database manifest)
  1520. "Return a derivation that builds the manual page database (\"mandb\") for
  1521. the entries in MANIFEST."
  1522. (define gdbm-ffi
  1523. (module-ref (resolve-interface '(gnu packages guile))
  1524. 'guile-gdbm-ffi))
  1525. (define guile-zlib
  1526. (module-ref (resolve-interface '(gnu packages guile)) 'guile-zlib))
  1527. (define modules
  1528. (delete '(guix config)
  1529. (source-module-closure `((guix build utils)
  1530. (guix man-db)))))
  1531. (define build
  1532. (with-imported-modules modules
  1533. (with-extensions (list gdbm-ffi ;for (guix man-db)
  1534. guile-zlib)
  1535. #~(begin
  1536. (use-modules (guix man-db)
  1537. (guix build utils)
  1538. (ice-9 threads)
  1539. (srfi srfi-1)
  1540. (srfi srfi-19))
  1541. (define (print-string msg)
  1542. (display msg)
  1543. (force-output))
  1544. (define-syntax-rule (print fmt args ...)
  1545. ;; Build up the string and display it at once.
  1546. (print-string (format #f fmt args ...)))
  1547. (define (compute-entry directory count total)
  1548. (print "\r[~3d/~3d] building list of man-db entries..."
  1549. count total)
  1550. (let ((man (string-append directory "/share/man")))
  1551. (if (directory-exists? man)
  1552. (mandb-entries man)
  1553. '())))
  1554. (define (compute-entries)
  1555. ;; This is the most expensive part (I/O and CPU, due to
  1556. ;; decompression), so report progress as we traverse INPUTS.
  1557. ;; Cap at 4 threads because we don't see any speedup beyond that
  1558. ;; on an SSD laptop.
  1559. (let* ((inputs '#$(manifest-inputs manifest))
  1560. (total (length inputs))
  1561. (threads (min (parallel-job-count) 4)))
  1562. (concatenate
  1563. (n-par-map threads compute-entry inputs
  1564. (iota total 1)
  1565. (make-list total total)))))
  1566. (define man-directory
  1567. (string-append #$output "/share/man"))
  1568. (mkdir-p man-directory)
  1569. (format #t "Creating manual page database...~%")
  1570. (force-output)
  1571. (let* ((start (current-time))
  1572. (entries (compute-entries))
  1573. (_ (write-mandb-database (string-append man-directory
  1574. "/index.db")
  1575. entries))
  1576. (duration (time-difference (current-time) start)))
  1577. (newline)
  1578. (format #t "~a entries processed in ~,1f s~%"
  1579. (length entries)
  1580. (+ (time-second duration)
  1581. (* (time-nanosecond duration) (expt 10 -9))))
  1582. (force-output))))))
  1583. (gexp->derivation "manual-database" build
  1584. #:substitutable? #f
  1585. #:local-build? #t
  1586. #:properties
  1587. `((type . profile-hook)
  1588. (hook . manual-database))))
  1589. (define (manual-database/optional manifest)
  1590. "Return a derivation to build the manual database of MANIFEST, but only if
  1591. MANIFEST contains the \"man-db\" package. Otherwise, return #f."
  1592. ;; Building the man database (for "man -k") is expensive and rarely used.
  1593. ;; Build it only if the profile also contains "man-db".
  1594. (mlet %store-monad ((man-db (manifest-lookup-package manifest "man-db")))
  1595. (if man-db
  1596. (manual-database manifest)
  1597. (return #f))))
  1598. (define (texlive-font-maps manifest)
  1599. "Return a derivation that builds the TeX Live font maps for the entries in
  1600. MANIFEST."
  1601. (define entry->texlive-input
  1602. (match-lambda
  1603. (($ <manifest-entry> name version output thing deps)
  1604. (if (string-prefix? "texlive-" name)
  1605. (cons (gexp-input thing output)
  1606. (append-map entry->texlive-input deps))
  1607. '()))))
  1608. (define texlive-inputs
  1609. (append-map entry->texlive-input (manifest-entries manifest)))
  1610. (define texlive-bin
  1611. (module-ref (resolve-interface '(gnu packages tex)) 'texlive-bin))
  1612. (define coreutils
  1613. (module-ref (resolve-interface '(gnu packages base)) 'coreutils))
  1614. (define grep
  1615. (module-ref (resolve-interface '(gnu packages base)) 'grep))
  1616. (define sed
  1617. (module-ref (resolve-interface '(gnu packages base)) 'sed))
  1618. (define updmap.cfg
  1619. (module-ref (resolve-interface '(gnu packages tex))
  1620. 'texlive-default-updmap.cfg))
  1621. (define build
  1622. (with-imported-modules '((guix build utils)
  1623. (guix build union))
  1624. #~(begin
  1625. (use-modules (guix build utils)
  1626. (guix build union)
  1627. (ice-9 popen))
  1628. ;; Build a modifiable union of all texlive inputs. We do this so
  1629. ;; that TeX live can resolve the parent and grandparent directories
  1630. ;; correctly. There might be a more elegant way to accomplish this.
  1631. (union-build "/tmp/texlive"
  1632. '#$texlive-inputs
  1633. #:create-all-directories? #t
  1634. #:log-port (%make-void-port "w"))
  1635. ;; XXX: This is annoying, but it's necessary because texlive-bin
  1636. ;; does not provide wrapped executables.
  1637. (setenv "PATH"
  1638. (string-append #$(file-append coreutils "/bin")
  1639. ":"
  1640. #$(file-append grep "/bin")
  1641. ":"
  1642. #$(file-append sed "/bin")))
  1643. (setenv "PERL5LIB" #$(file-append texlive-bin "/share/tlpkg"))
  1644. (setenv "GUIX_TEXMF" "/tmp/texlive/share/texmf-dist")
  1645. ;; Remove invalid maps from config file.
  1646. (let* ((web2c (string-append #$output "/share/texmf-dist/web2c/"))
  1647. (maproot (string-append #$output "/share/texmf-dist/fonts/map/"))
  1648. (updmap.cfg (string-append web2c "updmap.cfg")))
  1649. (mkdir-p web2c)
  1650. (copy-file #$updmap.cfg updmap.cfg)
  1651. (make-file-writable updmap.cfg)
  1652. (let* ((port (open-pipe* OPEN_WRITE
  1653. #$(file-append texlive-bin "/bin/updmap-sys")
  1654. "--syncwithtrees"
  1655. "--nohash"
  1656. "--force"
  1657. (string-append "--cnffile=" updmap.cfg))))
  1658. (display "Y\n" port)
  1659. (when (not (zero? (status:exit-val (close-pipe port))))
  1660. (error "failed to filter updmap.cfg")))
  1661. ;; Generate font maps.
  1662. (invoke #$(file-append texlive-bin "/bin/updmap-sys")
  1663. (string-append "--cnffile=" updmap.cfg)
  1664. (string-append "--dvipdfmxoutputdir="
  1665. maproot "dvipdfmx/updmap")
  1666. (string-append "--dvipsoutputdir="
  1667. maproot "dvips/updmap")
  1668. (string-append "--pdftexoutputdir="
  1669. maproot "pdftex/updmap"))
  1670. ;; Create ls-R file. I know, that's not *just* for font maps, but
  1671. ;; we've generated new files, so there's no point in running it
  1672. ;; any earlier. The ls-R file must act on a full TeX Live tree,
  1673. ;; but we have two: the one in /tmp containing all packages and
  1674. ;; the one in #$output containing the generated font maps. To
  1675. ;; avoid having to merge ls-R files, we copy the generated stuff
  1676. ;; to /tmp and run mktexlsr only once.
  1677. (let ((a (string-append #$output "/share/texmf-dist"))
  1678. (b "/tmp/texlive/share/texmf-dist")
  1679. (mktexlsr #$(file-append texlive-bin "/bin/mktexlsr")))
  1680. (copy-recursively a b)
  1681. (invoke mktexlsr b)
  1682. (install-file (string-append b "/ls-R") a))))))
  1683. (mlet %store-monad ((texlive-base (manifest-lookup-package manifest "texlive-base")))
  1684. (if (and texlive-base (pair? texlive-inputs))
  1685. (gexp->derivation "texlive-font-maps" build
  1686. #:substitutable? #f
  1687. #:local-build? #t
  1688. #:properties
  1689. `((type . profile-hook)
  1690. (hook . texlive-font-maps)))
  1691. (return #f))))
  1692. (define %default-profile-hooks
  1693. ;; This is the list of derivation-returning procedures that are called by
  1694. ;; default when making a non-empty profile.
  1695. (list info-dir-file
  1696. manual-database/optional
  1697. fonts-dir-file
  1698. ghc-package-cache-file
  1699. ca-certificate-bundle
  1700. emacs-subdirs
  1701. gdk-pixbuf-loaders-cache-file
  1702. glib-schemas
  1703. gtk-icon-themes
  1704. gtk-im-modules
  1705. texlive-font-maps
  1706. xdg-desktop-database
  1707. xdg-mime-database))
  1708. (define* (profile-derivation manifest
  1709. #:key
  1710. (name "profile")
  1711. (hooks %default-profile-hooks)
  1712. (locales? #t)
  1713. (allow-unsupported-packages? #f)
  1714. (allow-collisions? #f)
  1715. (relative-symlinks? #f)
  1716. (format-version %manifest-format-version)
  1717. system target)
  1718. "Return a derivation that builds a profile (aka. 'user environment') with
  1719. the given MANIFEST. The profile includes additional derivations returned by
  1720. the monadic procedures listed in HOOKS--such as an Info 'dir' file, etc.
  1721. Unless ALLOW-COLLISIONS? is true, a '&profile-collision-error' is raised if
  1722. entries in MANIFEST collide (for instance if there are two same-name packages
  1723. with a different version number.) Unless ALLOW-UNSUPPORTED-PACKAGES? is true
  1724. or TARGET is set, raise an error if MANIFEST contains a package that does not
  1725. support SYSTEM.
  1726. When LOCALES? is true, the build is performed under a UTF-8 locale; this adds
  1727. a dependency on the 'glibc-utf8-locales' package.
  1728. When RELATIVE-SYMLINKS? is true, use relative file names for symlink targets.
  1729. This is one of the things to do for the result to be relocatable.
  1730. When TARGET is true, it must be a GNU triplet, and the packages in MANIFEST
  1731. are cross-built for TARGET."
  1732. (define (check-supported-packages system)
  1733. ;; Raise an error if a package in MANIFEST does not support SYSTEM.
  1734. (map-manifest-entries
  1735. (lambda (entry)
  1736. (match (manifest-entry-item entry)
  1737. ((? package? package)
  1738. (unless (supported-package? package system)
  1739. (raise (formatted-message (G_ "package ~a does not support ~a")
  1740. (package-full-name package) system))))
  1741. (_ #t)))
  1742. manifest))
  1743. (mlet* %store-monad ((system (if system
  1744. (return system)
  1745. (current-system)))
  1746. (target (if target
  1747. (return target)
  1748. (current-target-system)))
  1749. (ok? -> (or allow-unsupported-packages? target
  1750. (check-supported-packages system)))
  1751. (ok? (if allow-collisions?
  1752. (return #t)
  1753. (check-for-collisions manifest system
  1754. #:target target)))
  1755. (extras (if (null? (manifest-entries manifest))
  1756. (return '())
  1757. (mapm/accumulate-builds (lambda (hook)
  1758. (hook manifest))
  1759. hooks))))
  1760. (define extra-inputs
  1761. (filter-map (lambda (drv)
  1762. (and (derivation? drv) (gexp-input drv)))
  1763. extras))
  1764. (define glibc-utf8-locales ;lazy reference
  1765. (module-ref (resolve-interface '(gnu packages base))
  1766. 'glibc-utf8-locales))
  1767. (define set-utf8-locale
  1768. ;; Some file names (e.g., in 'nss-certs') are UTF-8 encoded so
  1769. ;; install a UTF-8 locale.
  1770. #~(begin
  1771. (setenv "LOCPATH"
  1772. #$(file-append glibc-utf8-locales "/lib/locale/"
  1773. (version-major+minor
  1774. (package-version glibc-utf8-locales))))
  1775. (setlocale LC_ALL "en_US.utf8")))
  1776. (define builder
  1777. (with-imported-modules '((guix build profiles)
  1778. (guix build union)
  1779. (guix build utils)
  1780. (guix search-paths)
  1781. (guix records))
  1782. #~(begin
  1783. (use-modules (guix build profiles)
  1784. (guix search-paths)
  1785. (srfi srfi-1))
  1786. (let ((line (cond-expand (guile-2.2 'line)
  1787. (else _IOLBF)))) ;Guile 2.0
  1788. (setvbuf (current-output-port) line)
  1789. (setvbuf (current-error-port) line))
  1790. #+(if locales? set-utf8-locale #t)
  1791. (build-profile #$output '#$(manifest->gexp manifest format-version)
  1792. #:extra-inputs '#$extra-inputs
  1793. #:symlink #$(if relative-symlinks?
  1794. #~symlink-relative
  1795. #~symlink)))))
  1796. (gexp->derivation name builder
  1797. #:system system
  1798. #:target target
  1799. ;; Don't complain about _IO* on Guile 2.2.
  1800. #:env-vars '(("GUILE_WARN_DEPRECATED" . "no"))
  1801. ;; Not worth offloading.
  1802. #:local-build? #t
  1803. ;; Disable substitution because it would trigger a
  1804. ;; connection to the substitute server, which is likely
  1805. ;; to have no substitute to offer.
  1806. #:substitutable? #f
  1807. #:properties `((type . profile)
  1808. (profile
  1809. (count
  1810. . ,(length
  1811. (manifest-entries manifest))))))))
  1812. ;; Declarative profile.
  1813. (define-record-type* <profile> profile make-profile
  1814. profile?
  1815. (name profile-name (default "profile")) ;string
  1816. (content profile-content) ;<manifest>
  1817. (hooks profile-hooks ;list of procedures
  1818. (default %default-profile-hooks))
  1819. (locales? profile-locales? ;Boolean
  1820. (default #t))
  1821. (allow-collisions? profile-allow-collisions? ;Boolean
  1822. (default #f))
  1823. (relative-symlinks? profile-relative-symlinks? ;Boolean
  1824. (default #f))
  1825. (format-version profile-format-version ;integer
  1826. (default %manifest-format-version)))
  1827. (define-gexp-compiler (profile-compiler (profile <profile>) system target)
  1828. "Compile PROFILE to a derivation."
  1829. (match profile
  1830. (($ <profile> name manifest hooks
  1831. locales? allow-collisions? relative-symlinks?
  1832. format-version)
  1833. (profile-derivation manifest
  1834. #:name name
  1835. #:hooks hooks
  1836. #:locales? locales?
  1837. #:allow-collisions? allow-collisions?
  1838. #:relative-symlinks? relative-symlinks?
  1839. #:format-version format-version
  1840. #:system system #:target target))))
  1841. (define* (profile-search-paths profile
  1842. #:optional (manifest (profile-manifest profile))
  1843. #:key (getenv (const #f)))
  1844. "Read the manifest of PROFILE and evaluate the values of search path
  1845. environment variables required by PROFILE; return a list of
  1846. specification/value pairs. If MANIFEST is not #f, it is assumed to be the
  1847. manifest of PROFILE, which avoids rereading it.
  1848. Use GETENV to determine the current settings and report only settings not
  1849. already effective."
  1850. (evaluate-search-paths (manifest-search-paths manifest)
  1851. (list profile) getenv))
  1852. (define %precious-variables
  1853. ;; Environment variables in the default 'load-profile' white list.
  1854. '("HOME" "USER" "LOGNAME" "DISPLAY" "XAUTHORITY" "TERM" "TZ" "PAGER"))
  1855. (define (purify-environment white-list white-list-regexps)
  1856. "Unset all environment variables except those that match the regexps in
  1857. WHITE-LIST-REGEXPS and those listed in WHITE-LIST."
  1858. (for-each unsetenv
  1859. (remove (lambda (variable)
  1860. (or (member variable white-list)
  1861. (find (cut regexp-exec <> variable)
  1862. white-list-regexps)))
  1863. (match (get-environment-variables)
  1864. (((names . _) ...)
  1865. names)))))
  1866. (define* (load-profile profile
  1867. #:optional (manifest (profile-manifest profile))
  1868. #:key pure? (white-list-regexps '())
  1869. (white-list %precious-variables))
  1870. "Set the environment variables specified by MANIFEST for PROFILE. When
  1871. PURE? is #t, unset the variables in the current environment except those that
  1872. match the regexps in WHITE-LIST-REGEXPS and those listed in WHITE-LIST.
  1873. Otherwise, augment existing environment variables with additional search
  1874. paths."
  1875. (when pure?
  1876. (purify-environment white-list white-list-regexps))
  1877. (for-each (match-lambda
  1878. ((($ <search-path-specification> variable _ separator) . value)
  1879. (let ((current (getenv variable)))
  1880. (setenv variable
  1881. (if (and current (not pure?))
  1882. (if separator
  1883. (string-append value separator current)
  1884. value)
  1885. value)))))
  1886. (profile-search-paths profile manifest)))
  1887. (define (profile-regexp profile)
  1888. "Return a regular expression that matches PROFILE's name and number."
  1889. (make-regexp (string-append "^" (regexp-quote (basename profile))
  1890. "-([0-9]+)")))
  1891. (define* (generation-number profile
  1892. #:optional (base-profile profile))
  1893. "Return PROFILE's number or 0. An absolute file name must be used.
  1894. Optionally, if BASE-PROFILE is provided, use it instead of PROFILE to
  1895. construct the regexp matching generations. This is useful in special cases
  1896. like: (generation-number \"/run/current-system\" %system-profile)."
  1897. (or (and=> (false-if-exception (regexp-exec (profile-regexp base-profile)
  1898. (basename (readlink profile))))
  1899. (compose string->number (cut match:substring <> 1)))
  1900. 0))
  1901. (define %profile-generation-rx
  1902. ;; Regexp that matches profile generation.
  1903. (make-regexp "(.*)-([0-9]+)-link$"))
  1904. (define (generation-profile file)
  1905. "If FILE is a profile generation GC root such as \"guix-profile-42-link\",
  1906. return its corresponding profile---e.g., \"guix-profile\". Otherwise return
  1907. #f."
  1908. (match (regexp-exec %profile-generation-rx file)
  1909. (#f #f)
  1910. (m (let ((profile (match:substring m 1)))
  1911. (and (file-exists? (string-append profile "/manifest"))
  1912. profile)))))
  1913. (define (generation-numbers profile)
  1914. "Return the sorted list of generation numbers of PROFILE, or '(0) if no
  1915. former profiles were found."
  1916. (match (scandir (dirname profile)
  1917. (cute regexp-exec (profile-regexp profile) <>))
  1918. (#f ; no profile directory
  1919. '(0))
  1920. (() ; no profiles
  1921. '(0))
  1922. ((profiles ...) ; former profiles around
  1923. (sort (map (compose string->number
  1924. (cut match:substring <> 1)
  1925. (cute regexp-exec (profile-regexp profile) <>))
  1926. profiles)
  1927. <))))
  1928. (define (profile-generations profile)
  1929. "Return a list of PROFILE's generations."
  1930. (let ((generations (generation-numbers profile)))
  1931. (if (equal? generations '(0))
  1932. '()
  1933. generations)))
  1934. (define (relative-generation-spec->number profile spec)
  1935. "Return PROFILE's generation specified by SPEC, which is a string. The SPEC
  1936. may be a N, -N, or +N, where N is a number. If the spec is N, then the number
  1937. returned is N. If it is -N, then the number returned is the profile's current
  1938. generation number minus N. If it is +N, then the number returned is the
  1939. profile's current generation number plus N. Return #f if there is no such
  1940. generation."
  1941. (let ((number (string->number spec)))
  1942. (and number
  1943. (case (string-ref spec 0)
  1944. ((#\+ #\-)
  1945. (relative-generation profile number))
  1946. (else (if (memv number (profile-generations profile))
  1947. number
  1948. #f))))))
  1949. (define* (relative-generation profile shift #:optional
  1950. (current (generation-number profile)))
  1951. "Return PROFILE's generation shifted from the CURRENT generation by SHIFT.
  1952. SHIFT is a positive or negative number.
  1953. Return #f if there is no such generation."
  1954. (let* ((abs-shift (abs shift))
  1955. (numbers (profile-generations profile))
  1956. (from-current (memq current
  1957. (if (negative? shift)
  1958. (reverse numbers)
  1959. numbers))))
  1960. (and from-current
  1961. (< abs-shift (length from-current))
  1962. (list-ref from-current abs-shift))))
  1963. (define* (previous-generation-number profile #:optional
  1964. (number (generation-number profile)))
  1965. "Return the number of the generation before generation NUMBER of
  1966. PROFILE, or 0 if none exists. It could be NUMBER - 1, but it's not the
  1967. case when generations have been deleted (there are \"holes\")."
  1968. (or (relative-generation profile -1 number)
  1969. 0))
  1970. (define (generation-file-name profile generation)
  1971. "Return the file name for PROFILE's GENERATION."
  1972. (format #f "~a-~a-link" profile generation))
  1973. (define (generation-time profile number)
  1974. "Return the creation time of a generation in the UTC format."
  1975. (make-time time-utc 0
  1976. (stat:ctime (stat (generation-file-name profile number)))))
  1977. (define (link-to-empty-profile store generation)
  1978. "Link GENERATION, a string, to the empty profile. An error is raised if
  1979. that fails."
  1980. (let* ((drv (run-with-store store
  1981. (profile-derivation (manifest '())
  1982. #:locales? #f)))
  1983. (prof (derivation->output-path drv "out")))
  1984. (build-derivations store (list drv))
  1985. (switch-symlinks generation prof)))
  1986. (define (switch-to-generation profile number)
  1987. "Atomically switch PROFILE to the generation NUMBER. Return the number of
  1988. the generation that was current before switching."
  1989. (let ((current (generation-number profile))
  1990. (generation (generation-file-name profile number)))
  1991. (cond ((not (file-exists? profile))
  1992. (raise (condition (&profile-not-found-error
  1993. (profile profile)))))
  1994. ((not (file-exists? generation))
  1995. (raise (condition (&missing-generation-error
  1996. (profile profile)
  1997. (generation number)))))
  1998. (else
  1999. (switch-symlinks profile (basename generation))
  2000. current))))
  2001. (define (switch-to-previous-generation profile)
  2002. "Atomically switch PROFILE to the previous generation. Return the former
  2003. generation number and the current one."
  2004. (let ((previous (previous-generation-number profile)))
  2005. (values (switch-to-generation profile previous)
  2006. previous)))
  2007. (define (roll-back store profile)
  2008. "Roll back to the previous generation of PROFILE. Return the number of the
  2009. generation that was current before switching and the new generation number."
  2010. (let* ((number (generation-number profile))
  2011. (previous-number (previous-generation-number profile number))
  2012. (previous-generation (generation-file-name profile previous-number)))
  2013. (cond ((not (file-exists? profile)) ;invalid profile
  2014. (raise (condition (&profile-not-found-error
  2015. (profile profile)))))
  2016. ((zero? number) ;empty profile
  2017. (values number number))
  2018. ((or (zero? previous-number) ;going to emptiness
  2019. (not (file-exists? previous-generation)))
  2020. (link-to-empty-profile store previous-generation)
  2021. (switch-to-previous-generation profile))
  2022. (else ;anything else
  2023. (switch-to-previous-generation profile)))))
  2024. (define (delete-generation store profile number)
  2025. "Delete generation with NUMBER from PROFILE. Return the file name of the
  2026. generation that has been deleted, or #f if nothing was done (for instance
  2027. because the NUMBER is zero.)"
  2028. (define (delete-and-return)
  2029. (let ((generation (generation-file-name profile number)))
  2030. (delete-file generation)
  2031. generation))
  2032. (let* ((current-number (generation-number profile))
  2033. (previous-number (previous-generation-number profile number))
  2034. (previous-generation (generation-file-name profile previous-number)))
  2035. (cond ((zero? number) #f) ;do not delete generation 0
  2036. ((and (= number current-number)
  2037. (not (file-exists? previous-generation)))
  2038. (link-to-empty-profile store previous-generation)
  2039. (switch-to-previous-generation profile)
  2040. (delete-and-return))
  2041. ((= number current-number)
  2042. (roll-back store profile)
  2043. (delete-and-return))
  2044. (else
  2045. (delete-and-return)))))
  2046. (define %user-profile-directory
  2047. (and=> (getenv "HOME")
  2048. (cut string-append <> "/.guix-profile")))
  2049. (define %profile-directory
  2050. (string-append %state-directory "/profiles/"
  2051. (or (and=> (or (getenv "USER")
  2052. (getenv "LOGNAME")
  2053. (false-if-exception
  2054. (passwd:name (getpwuid (getuid)))))
  2055. (cut string-append "per-user/" <>))
  2056. "default")))
  2057. (define %current-profile
  2058. ;; Call it `guix-profile', not `profile', to allow Guix profiles to
  2059. ;; coexist with Nix profiles.
  2060. (string-append %profile-directory "/guix-profile"))
  2061. (define (ensure-profile-directory)
  2062. "Attempt to create /…/profiles/per-user/$USER if needed. Nowadays this is
  2063. taken care of by the daemon."
  2064. (let ((s (stat %profile-directory #f)))
  2065. (unless (and s (eq? 'directory (stat:type s)))
  2066. (catch 'system-error
  2067. (lambda ()
  2068. (mkdir-p %profile-directory))
  2069. (lambda args
  2070. ;; Often, we cannot create %PROFILE-DIRECTORY because its
  2071. ;; parent directory is root-owned and we're running
  2072. ;; unprivileged.
  2073. (raise (condition
  2074. (&message
  2075. (message
  2076. (format #f
  2077. (G_ "while creating directory `~a': ~a")
  2078. %profile-directory
  2079. (strerror (system-error-errno args)))))
  2080. (&fix-hint
  2081. (hint
  2082. (format #f (G_ "Please create the @file{~a} directory, \
  2083. with you as the owner.")
  2084. %profile-directory))))))))
  2085. ;; Bail out if it's not owned by the user.
  2086. (unless (or (not s) (= (stat:uid s) (getuid)))
  2087. (raise (condition
  2088. (&message
  2089. (message
  2090. (format #f (G_ "directory `~a' is not owned by you")
  2091. %profile-directory)))
  2092. (&fix-hint
  2093. (hint
  2094. (format #f (G_ "Please change the owner of @file{~a} \
  2095. to user ~s.")
  2096. %profile-directory (or (getenv "USER")
  2097. (getenv "LOGNAME")
  2098. (getuid))))))))))
  2099. (define (canonicalize-profile profile)
  2100. "If PROFILE points to a profile in %PROFILE-DIRECTORY, return that.
  2101. Otherwise return PROFILE unchanged. The goal is to treat '-p ~/.guix-profile'
  2102. as if '-p' was omitted." ; see <http://bugs.gnu.org/17939>
  2103. ;; Trim trailing slashes so 'readlink' can do its job.
  2104. (let ((profile (string-trim-right profile #\/)))
  2105. (catch 'system-error
  2106. (lambda ()
  2107. (let ((target (readlink profile)))
  2108. (if (string=? (dirname target) %profile-directory)
  2109. target
  2110. profile)))
  2111. (const profile))))
  2112. (define %known-shorthand-profiles
  2113. ;; Known shorthand forms for profiles that the user manipulates.
  2114. (list (string-append (config-directory #:ensure? #f) "/current")
  2115. %user-profile-directory))
  2116. (define (user-friendly-profile profile)
  2117. "Return either ~/.guix-profile or ~/.config/guix/current if that's what
  2118. PROFILE refers to, directly or indirectly, or PROFILE."
  2119. (or (find (lambda (shorthand)
  2120. (and shorthand
  2121. (let ((target (false-if-exception
  2122. (readlink shorthand))))
  2123. (and target (string=? target profile)))))
  2124. %known-shorthand-profiles)
  2125. profile))
  2126. ;;; Local Variables:
  2127. ;;; eval: (put 'let-fields 'scheme-indent-function 2)
  2128. ;;; End:
  2129. ;;; profiles.scm ends here