profiles.scm 99 KB

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