self.scm 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (guix self)
  20. #:use-module (guix config)
  21. #:use-module (guix i18n)
  22. #:use-module (guix modules)
  23. #:use-module (guix gexp)
  24. #:use-module (guix store)
  25. #:use-module (guix monads)
  26. #:use-module (guix discovery)
  27. #:use-module (guix packages)
  28. #:use-module (guix sets)
  29. #:use-module (guix modules)
  30. #:use-module ((guix utils) #:select (version-major+minor))
  31. #:use-module ((guix build utils) #:select (find-files))
  32. #:use-module (srfi srfi-1)
  33. #:use-module (srfi srfi-9)
  34. #:use-module (srfi srfi-35)
  35. #:use-module (ice-9 match)
  36. #:export (make-config.scm
  37. whole-package ;for internal use in 'guix pull'
  38. compiled-guix
  39. guix-derivation))
  40. ;;;
  41. ;;; Dependency handling.
  42. ;;;
  43. (define specification->package
  44. ;; Use our own variant of that procedure because that of (gnu packages)
  45. ;; would traverse all the .scm files, which is wasteful.
  46. (let ((ref (lambda (module variable)
  47. (module-ref (resolve-interface module) variable))))
  48. (match-lambda
  49. ("guile" (ref '(gnu packages guile) 'guile-3.0-latest))
  50. ("guile-avahi" (ref '(gnu packages guile-xyz) 'guile-avahi))
  51. ("guile-json" (ref '(gnu packages guile) 'guile-json-4))
  52. ("guile-ssh" (ref '(gnu packages ssh) 'guile-ssh))
  53. ("guile-git" (ref '(gnu packages guile) 'guile-git))
  54. ("guile-semver" (ref '(gnu packages guile-xyz) 'guile-semver))
  55. ("guile-lib" (ref '(gnu packages guile-xyz) 'guile-lib))
  56. ("guile-sqlite3" (ref '(gnu packages guile) 'guile-sqlite3))
  57. ("guile-zlib" (ref '(gnu packages guile) 'guile-zlib))
  58. ("guile-lzlib" (ref '(gnu packages guile) 'guile-lzlib))
  59. ("guile-zstd" (ref '(gnu packages guile) 'guile-zstd))
  60. ("guile-gcrypt" (ref '(gnu packages gnupg) 'guile-gcrypt))
  61. ("gnutls" (ref '(gnu packages tls) 'gnutls))
  62. ("disarchive" (ref '(gnu packages backup) 'disarchive))
  63. ("gzip" (ref '(gnu packages compression) 'gzip))
  64. ("bzip2" (ref '(gnu packages compression) 'bzip2))
  65. ("xz" (ref '(gnu packages compression) 'xz))
  66. ("po4a" (ref '(gnu packages gettext) 'po4a))
  67. ("gettext" (ref '(gnu packages gettext) 'gettext-minimal))
  68. ("gcc-toolchain" (ref '(gnu packages commencement) 'gcc-toolchain))
  69. (_ #f)))) ;no such package
  70. ;;;
  71. ;;; Derivations.
  72. ;;;
  73. ;; Node in a DAG of build tasks. Each node maps to a derivation, but it's
  74. ;; easier to express things this way.
  75. (define-record-type <node>
  76. (node name modules source dependencies compiled)
  77. node?
  78. (name node-name) ;string
  79. (modules node-modules) ;list of module names
  80. (source node-source) ;list of source files
  81. (dependencies node-dependencies) ;list of nodes
  82. (compiled node-compiled)) ;node -> lowerable object
  83. ;; File mappings are essentially an alist as passed to 'imported-files'.
  84. (define-record-type <file-mapping>
  85. (file-mapping name alist)
  86. file-mapping?
  87. (name file-mapping-name)
  88. (alist file-mapping-alist))
  89. (define-gexp-compiler (file-mapping-compiler (mapping <file-mapping>)
  90. system target)
  91. ;; Here we use 'imported-files', which can arrange to directly import all
  92. ;; the files instead of creating a derivation, when possible.
  93. (imported-files (map (match-lambda
  94. ((destination (? local-file? file))
  95. (cons destination
  96. (local-file-absolute-file-name file)))
  97. ((destination source)
  98. (cons destination source))) ;silliness
  99. (file-mapping-alist mapping))
  100. #:name (file-mapping-name mapping)
  101. #:system system))
  102. (define (node-source+compiled node)
  103. "Return a \"bundle\" containing both the source code and object files for
  104. NODE's modules, under their FHS directories: share/guile/site and lib/guile."
  105. (define build
  106. (with-imported-modules '((guix build utils))
  107. #~(begin
  108. (use-modules (guix build utils))
  109. (define source
  110. (string-append #$output "/share/guile/site/"
  111. (effective-version)))
  112. (define object
  113. (string-append #$output "/lib/guile/" (effective-version)
  114. "/site-ccache"))
  115. (mkdir-p (dirname source))
  116. (symlink #$(node-source node) source)
  117. (mkdir-p (dirname object))
  118. (symlink #$(node-compiled node) object))))
  119. (computed-file (string-append (node-name node) "-modules")
  120. build
  121. #:options '(#:local-build? #t
  122. ;; "Building" it locally is faster.
  123. #:substitutable? #f)))
  124. (define (node-fold proc init nodes)
  125. (let loop ((nodes nodes)
  126. (visited (setq))
  127. (result init))
  128. (match nodes
  129. (() result)
  130. ((head tail ...)
  131. (if (set-contains? visited head)
  132. (loop tail visited result)
  133. (loop tail (set-insert head visited)
  134. (proc head result)))))))
  135. (define (node-modules/recursive nodes)
  136. (node-fold (lambda (node modules)
  137. (append (node-modules node) modules))
  138. '()
  139. nodes))
  140. (define* (closure modules #:optional (except '()))
  141. (source-module-closure modules
  142. #:select?
  143. (match-lambda
  144. (('guix 'config)
  145. #f)
  146. ((and module
  147. (or ('guix _ ...) ('gnu _ ...)))
  148. (not (member module except)))
  149. (rest #f))))
  150. (define module->import
  151. ;; Return a file-name/file-like object pair for the specified module and
  152. ;; suitable for 'imported-files'.
  153. (match-lambda
  154. ((module '=> thing)
  155. (let ((file (module-name->file-name module)))
  156. (list file thing)))
  157. (module
  158. (let ((file (module-name->file-name module)))
  159. (list file
  160. (local-file (search-path %load-path file)))))))
  161. (define* (scheme-node name modules #:optional (dependencies '())
  162. #:key (extra-modules '()) (extra-files '())
  163. (extensions '())
  164. parallel? guile-for-build)
  165. "Return a node that builds the given Scheme MODULES, and depends on
  166. DEPENDENCIES (a list of nodes). EXTRA-MODULES is a list of additional modules
  167. added to the source, and EXTRA-FILES is a list of additional files.
  168. EXTENSIONS is a set of full-blown Guile packages (e.g., 'guile-json') that
  169. must be present in the search path."
  170. (let* ((modules (append extra-modules
  171. (closure modules
  172. (node-modules/recursive dependencies))))
  173. (module-files (map module->import modules))
  174. (source (file-mapping (string-append name "-source")
  175. (append module-files extra-files))))
  176. (node name modules source dependencies
  177. (compiled-modules name source
  178. (map car module-files)
  179. (map node-source dependencies)
  180. (map node-compiled dependencies)
  181. #:extensions extensions
  182. #:parallel? parallel?
  183. #:guile-for-build guile-for-build))))
  184. (define (file-imports directory sub-directory pred)
  185. "List all the files matching PRED under DIRECTORY/SUB-DIRECTORY. Return a
  186. list of file-name/file-like objects suitable as inputs to 'imported-files'."
  187. (map (lambda (file)
  188. (list (string-drop file (+ 1 (string-length directory)))
  189. (local-file file #:recursive? #t)))
  190. (find-files (string-append directory "/" sub-directory) pred)))
  191. (define* (file-append* item file #:key (recursive? #t))
  192. "Return FILE within ITEM, which may be a file name or a file-like object.
  193. When ITEM is a plain file name (a string), simply return a 'local-file'
  194. record with the new file name."
  195. (match item
  196. ((? string?)
  197. ;; This is the optimal case: we return a new "source". Thus, a
  198. ;; derivation that depends on this sub-directory does not depend on ITEM
  199. ;; itself.
  200. (local-file (string-append item "/" file)
  201. #:recursive? recursive?))
  202. ((? local-file? base)
  203. ;; Likewise, but with a <local-file>.
  204. (if (local-file-recursive? base)
  205. (local-file (string-append (local-file-absolute-file-name base)
  206. "/" file)
  207. (basename file)
  208. #:recursive? recursive?
  209. #:select? (local-file-select? base))
  210. (file-append base file)))
  211. (_
  212. ;; In this case, anything that refers to the result also depends on ITEM,
  213. ;; which isn't great.
  214. (file-append item "/" file))))
  215. (define* (locale-data source domain
  216. #:optional (directory domain))
  217. "Return the locale data from 'po/DIRECTORY' in SOURCE, corresponding to
  218. DOMAIN, a gettext domain."
  219. (define gettext
  220. (module-ref (resolve-interface '(gnu packages gettext))
  221. 'gettext-minimal))
  222. (define build
  223. (with-imported-modules '((guix build utils))
  224. #~(begin
  225. (use-modules (guix build utils)
  226. (srfi srfi-26)
  227. (ice-9 match) (ice-9 ftw))
  228. (define po-directory
  229. #+(file-append* source (string-append "po/" directory)))
  230. (define (compile language)
  231. (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/"
  232. #$domain ".mo")))
  233. (mkdir-p (dirname gmo))
  234. (invoke #+(file-append gettext "/bin/msgfmt")
  235. "-c" "--statistics" "--verbose"
  236. "-o" gmo
  237. (string-append po-directory "/" language ".po"))))
  238. (define (linguas)
  239. ;; Return the list of languages. Note: don't read 'LINGUAS'
  240. ;; because it contains things like 'en@boldquot' that do not have
  241. ;; a corresponding .po file.
  242. (map (cut basename <> ".po")
  243. (scandir po-directory
  244. (cut string-suffix? ".po" <>))))
  245. (for-each compile (linguas)))))
  246. (computed-file (string-append "guix-locale-" domain)
  247. build))
  248. (define (translate-texi-manuals source)
  249. "Return the translated texinfo manuals built from SOURCE."
  250. (define po4a
  251. (specification->package "po4a"))
  252. (define gettext
  253. (specification->package "gettext"))
  254. (define glibc-utf8-locales
  255. (module-ref (resolve-interface '(gnu packages base))
  256. 'glibc-utf8-locales))
  257. (define documentation
  258. (file-append* source "doc"))
  259. (define documentation-po
  260. (file-append* source "po/doc"))
  261. (define build
  262. (with-imported-modules '((guix build utils) (guix build po))
  263. #~(begin
  264. (use-modules (guix build utils) (guix build po)
  265. (ice-9 match) (ice-9 regex) (ice-9 textual-ports)
  266. (ice-9 vlist) (ice-9 threads)
  267. (srfi srfi-1))
  268. (define (translate-tmp-texi po source output)
  269. "Translate Texinfo file SOURCE using messages from PO, and write
  270. the result to OUTPUT."
  271. (invoke #+(file-append po4a "/bin/po4a-translate")
  272. "-M" "UTF-8" "-L" "UTF-8" "-k" "0" "-f" "texinfo"
  273. "-m" source "-p" po "-l" output))
  274. (define (canonicalize-whitespace str)
  275. ;; Change whitespace (newlines, etc.) in STR to #\space.
  276. (string-map (lambda (chr)
  277. (if (char-set-contains? char-set:whitespace chr)
  278. #\space
  279. chr))
  280. str))
  281. (define xref-regexp
  282. ;; Texinfo cross-reference regexp.
  283. (make-regexp "@(px|x)?ref\\{([^,}]+)"))
  284. (define (translate-cross-references texi translations)
  285. ;; Translate the cross-references that appear in TEXI, a Texinfo
  286. ;; file, using the msgid/msgstr pairs from TRANSLATIONS.
  287. (define content
  288. (call-with-input-file texi get-string-all))
  289. (define matches
  290. (list-matches xref-regexp content))
  291. (define translation-map
  292. (fold (match-lambda*
  293. (((msgid . str) result)
  294. (vhash-cons msgid str result)))
  295. vlist-null
  296. translations))
  297. (define translated
  298. ;; Iterate over MATCHES and replace cross-references with their
  299. ;; translation found in TRANSLATION-MAP. (We can't use
  300. ;; 'substitute*' because matches can span multiple lines.)
  301. (let loop ((matches matches)
  302. (offset 0)
  303. (result '()))
  304. (match matches
  305. (()
  306. (string-concatenate-reverse
  307. (cons (string-drop content offset) result)))
  308. ((head . tail)
  309. (let ((prefix (match:substring head 1))
  310. (ref (canonicalize-whitespace (match:substring head 2))))
  311. (define translated
  312. (string-append "@" (or prefix "")
  313. "ref{"
  314. (match (vhash-assoc ref translation-map)
  315. (#f ref)
  316. ((_ . str) str))))
  317. (loop tail
  318. (match:end head)
  319. (append (list translated
  320. (string-take
  321. (string-drop content offset)
  322. (- (match:start head) offset)))
  323. result)))))))
  324. (format (current-error-port)
  325. "translated ~a cross-references in '~a'~%"
  326. (length matches) texi)
  327. (call-with-output-file texi
  328. (lambda (port)
  329. (display translated port))))
  330. (define* (translate-texi prefix po lang
  331. #:key (extras '()))
  332. "Translate the manual for one language LANG using the PO file.
  333. PREFIX must be the prefix of the manual, 'guix' or 'guix-cookbook'. EXTRAS is
  334. a list of extra files, such as '(\"contributing\")."
  335. (let ((translations (call-with-input-file po read-po-file)))
  336. (for-each (lambda (file)
  337. (translate-tmp-texi po (string-append file ".texi")
  338. (string-append file "." lang
  339. ".texi.tmp")))
  340. (cons prefix extras))
  341. (for-each (lambda (file)
  342. (let* ((texi (string-append file "." lang ".texi"))
  343. (tmp (string-append texi ".tmp")))
  344. (copy-file tmp texi)
  345. (translate-cross-references texi
  346. translations)))
  347. (cons prefix extras))))
  348. (define (available-translations directory domain)
  349. ;; Return the list of available translations under DIRECTORY for
  350. ;; DOMAIN, a gettext domain such as "guix-manual". The result is
  351. ;; a list of language/PO file pairs.
  352. (filter-map (lambda (po)
  353. (let ((base (basename po)))
  354. (and (string-prefix? (string-append domain ".")
  355. base)
  356. (match (string-split base #\.)
  357. ((_ ... lang "po")
  358. (cons lang po))))))
  359. (find-files directory
  360. "\\.[a-z]{2}(_[A-Z]{2})?\\.po$")))
  361. (define parallel-jobs
  362. ;; Limit thread creation by 'n-par-for-each', mostly to put an
  363. ;; upper bound on memory usage.
  364. (min (parallel-job-count) 4))
  365. (mkdir #$output)
  366. (copy-recursively #$documentation "."
  367. #:log (%make-void-port "w"))
  368. (for-each
  369. (lambda (file)
  370. (copy-file file (basename file)))
  371. (find-files #$documentation-po ".*.po$"))
  372. (setenv "GUIX_LOCPATH"
  373. #+(file-append glibc-utf8-locales "/lib/locale"))
  374. (setenv "PATH" #+(file-append gettext "/bin"))
  375. (setenv "LC_ALL" "en_US.UTF-8")
  376. (setlocale LC_ALL "en_US.UTF-8")
  377. (n-par-for-each parallel-jobs
  378. (match-lambda
  379. ((language . po)
  380. (translate-texi "guix" po language
  381. #:extras '("contributing"))))
  382. (available-translations "." "guix-manual"))
  383. (n-par-for-each parallel-jobs
  384. (match-lambda
  385. ((language . po)
  386. (translate-texi "guix-cookbook" po language)))
  387. (available-translations "." "guix-cookbook"))
  388. (for-each (lambda (file)
  389. (install-file file #$output))
  390. (append
  391. (find-files "." "contributing\\..*\\.texi$")
  392. (find-files "." "guix\\..*\\.texi$")
  393. (find-files "." "guix-cookbook\\..*\\.texi$"))))))
  394. (computed-file "guix-translated-texinfo" build))
  395. (define (info-manual source)
  396. "Return the Info manual built from SOURCE."
  397. (define texinfo
  398. (module-ref (resolve-interface '(gnu packages texinfo))
  399. 'texinfo))
  400. (define graphviz
  401. (module-ref (resolve-interface '(gnu packages graphviz))
  402. 'graphviz))
  403. (define glibc-utf8-locales
  404. (module-ref (resolve-interface '(gnu packages base))
  405. 'glibc-utf8-locales))
  406. (define documentation
  407. (file-append* source "doc"))
  408. (define examples
  409. (file-append* source "gnu/system/examples"))
  410. (define build
  411. (with-imported-modules '((guix build utils))
  412. #~(begin
  413. (use-modules (guix build utils)
  414. (ice-9 match))
  415. (mkdir #$output)
  416. ;; Create 'version.texi'.
  417. ;; XXX: Can we use a more meaningful version string yet one that
  418. ;; doesn't change at each commit?
  419. (call-with-output-file "version.texi"
  420. (lambda (port)
  421. (let ((version "0.0-git"))
  422. (format port "
  423. @set UPDATED 1 January 1970
  424. @set UPDATED-MONTH January 1970
  425. @set EDITION ~a
  426. @set VERSION ~a\n" version version))))
  427. ;; Copy configuration templates that the manual includes.
  428. (for-each (lambda (template)
  429. (copy-file template
  430. (string-append
  431. "os-config-"
  432. (basename template ".tmpl")
  433. ".texi")))
  434. (find-files #$examples "\\.tmpl$"))
  435. ;; Build graphs.
  436. (mkdir-p (string-append #$output "/images"))
  437. (for-each (lambda (dot-file)
  438. (invoke #+(file-append graphviz "/bin/dot")
  439. "-Tpng" "-Gratio=.9" "-Gnodesep=.005"
  440. "-Granksep=.00005" "-Nfontsize=9"
  441. "-Nheight=.1" "-Nwidth=.1"
  442. "-o" (string-append #$output "/images/"
  443. (basename dot-file ".dot")
  444. ".png")
  445. dot-file))
  446. (find-files (string-append #$documentation "/images")
  447. "\\.dot$"))
  448. ;; Copy other PNGs.
  449. (for-each (lambda (png-file)
  450. (install-file png-file
  451. (string-append #$output "/images")))
  452. (find-files (string-append #$documentation "/images")
  453. "\\.png$"))
  454. ;; Finally build the manual. Copy it the Texinfo files to $PWD and
  455. ;; add a symlink to the 'images' directory so that 'makeinfo' can
  456. ;; see those images and produce image references in the Info output.
  457. (copy-recursively #$documentation "."
  458. #:log (%make-void-port "w"))
  459. (copy-recursively #+(translate-texi-manuals source) "."
  460. #:log (%make-void-port "w"))
  461. (delete-file-recursively "images")
  462. (symlink (string-append #$output "/images") "images")
  463. ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo.
  464. (setenv "GUIX_LOCPATH"
  465. #+(file-append glibc-utf8-locales "/lib/locale"))
  466. (for-each (lambda (texi)
  467. (match (string-split (basename texi) #\.)
  468. (("guix" language "texi")
  469. ;; Create 'version-LL.texi'.
  470. (symlink "version.texi"
  471. (string-append "version-" language
  472. ".texi")))
  473. (_ #f))
  474. (invoke #+(file-append texinfo "/bin/makeinfo")
  475. texi "-I" #$documentation
  476. "-I" "."
  477. "-o" (string-append #$output "/"
  478. (basename texi ".texi")
  479. ".info")))
  480. (cons "guix.texi"
  481. (append (find-files "."
  482. "^guix\\.[a-z]{2}(_[A-Z]{2})?\\.texi$")
  483. (find-files "."
  484. "^guix-cookbook.*\\.texi$"))))
  485. ;; Compress Info files.
  486. (setenv "PATH"
  487. #+(file-append (specification->package "gzip") "/bin"))
  488. (for-each (lambda (file)
  489. (invoke "gzip" "-9n" file))
  490. (find-files #$output "\\.info(-[0-9]+)?$")))))
  491. (computed-file "guix-manual" build))
  492. (define-syntax-rule (prevent-inlining! identifier ...)
  493. (begin (set! identifier identifier) ...))
  494. ;; XXX: These procedures are actually used by 'doc/build.scm'. Protect them
  495. ;; from inlining on Guile 3.
  496. (prevent-inlining! file-append* translate-texi-manuals info-manual)
  497. (define* (guile-module-union things #:key (name "guix-module-union"))
  498. "Return the union of the subset of THINGS (packages, computed files, etc.)
  499. that provide Guile modules."
  500. (define build
  501. (with-imported-modules '((guix build union))
  502. #~(begin
  503. (use-modules (guix build union))
  504. (define (modules directory)
  505. (string-append directory "/share/guile/site"))
  506. (define (objects directory)
  507. (string-append directory "/lib/guile"))
  508. (union-build #$output
  509. (filter (lambda (directory)
  510. (or (file-exists? (modules directory))
  511. (file-exists? (objects directory))))
  512. '#$things)
  513. #:log-port (%make-void-port "w")))))
  514. (computed-file name build))
  515. (define (quiet-guile guile)
  516. "Return a wrapper that does the same as the 'guile' executable of GUILE,
  517. except that it does not complain about locales and falls back to 'en_US.utf8'
  518. instead of 'C'."
  519. (define gcc
  520. (specification->package "gcc-toolchain"))
  521. (define source
  522. (search-path %load-path
  523. "gnu/packages/aux-files/guile-launcher.c"))
  524. (define effective
  525. (version-major+minor (package-version guile)))
  526. (define build
  527. ;; XXX: Reuse <c-compiler> from (guix scripts pack) instead?
  528. (with-imported-modules '((guix build utils))
  529. #~(begin
  530. (use-modules (guix build utils)
  531. (srfi srfi-26))
  532. (mkdir-p (string-append #$output "/bin"))
  533. (setenv "PATH" #$(file-append gcc "/bin"))
  534. (setenv "C_INCLUDE_PATH"
  535. (string-join
  536. (map (cut string-append <> "/include")
  537. '#$(match (bag-transitive-build-inputs
  538. (package->bag guile))
  539. (((labels packages . _) ...)
  540. (filter package? packages))))
  541. ":"))
  542. (setenv "LIBRARY_PATH" #$(file-append gcc "/lib"))
  543. (invoke "gcc" #$(local-file source) "-Wall" "-g0" "-O2"
  544. "-I" #$(file-append guile "/include/guile/" effective)
  545. "-L" #$(file-append guile "/lib")
  546. #$(string-append "-lguile-" effective)
  547. "-o" (string-append #$output "/bin/guile")))))
  548. (computed-file "guile-wrapper" build))
  549. (define* (guix-command modules
  550. #:key source (dependencies '())
  551. guile (guile-version (effective-version)))
  552. "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its
  553. load path."
  554. (define glibc-utf8-locales
  555. (module-ref (resolve-interface '(gnu packages base))
  556. 'glibc-utf8-locales))
  557. (define module-directory
  558. ;; To minimize the number of 'stat' calls needed to locate a module,
  559. ;; create the union of all the module directories.
  560. (guile-module-union (cons modules dependencies)))
  561. (program-file "guix-command"
  562. #~(begin
  563. ;; Remove the empty extension from the search path.
  564. (set! %load-extensions '(".scm"))
  565. (set! %load-path
  566. (append (list (string-append #$module-directory
  567. "/share/guile/site/"
  568. (effective-version))
  569. (string-append #$guile "/share/guile/"
  570. (effective-version)))
  571. %load-path))
  572. (set! %load-compiled-path
  573. (append (list (string-append #$module-directory
  574. "/lib/guile/"
  575. (effective-version)
  576. "/site-ccache")
  577. (string-append #$guile "/lib/guile/"
  578. (effective-version)
  579. "/ccache"))
  580. %load-compiled-path))
  581. ;; To maximize the chances that locales are set up right
  582. ;; out-of-the-box, bundle "common" UTF-8 locales.
  583. (let ((locpath (getenv "GUIX_LOCPATH")))
  584. (setenv "GUIX_LOCPATH"
  585. (string-append (if locpath
  586. (string-append locpath ":")
  587. "")
  588. #$(file-append glibc-utf8-locales
  589. "/lib/locale"))))
  590. (let ((guix-main (module-ref (resolve-interface '(guix ui))
  591. 'guix-main)))
  592. #$(if source
  593. #~(begin
  594. (bindtextdomain "guix"
  595. #$(locale-data source "guix"))
  596. (bindtextdomain "guix-packages"
  597. #$(locale-data source
  598. "guix-packages"
  599. "packages")))
  600. #t)
  601. ;; XXX: It would be more convenient to change it to:
  602. ;; (exit (apply guix-main (command-line)))
  603. (apply guix-main (command-line))))
  604. ;; Use a 'guile' variant that doesn't complain about locales.
  605. #:guile (quiet-guile guile)))
  606. (define (miscellaneous-files source)
  607. "Return data files taken from SOURCE."
  608. (file-mapping "guix-misc"
  609. `(("etc/bash_completion.d/guix"
  610. ,(file-append* source "/etc/completion/bash/guix"))
  611. ("etc/bash_completion.d/guix-daemon"
  612. ,(file-append* source "/etc/completion/bash/guix-daemon"))
  613. ("share/zsh/site-functions/_guix"
  614. ,(file-append* source "/etc/completion/zsh/_guix"))
  615. ("share/fish/vendor_completions.d/guix.fish"
  616. ,(file-append* source "/etc/completion/fish/guix.fish"))
  617. ("share/guix/berlin.guix.gnu.org.pub"
  618. ,(file-append* source
  619. "/etc/substitutes/berlin.guix.gnu.org.pub"))
  620. ("share/guix/ci.guix.gnu.org.pub" ;alias
  621. ,(file-append* source "/etc/substitutes/berlin.guix.gnu.org.pub"))
  622. ("share/guix/ci.guix.info.pub" ;alias
  623. ,(file-append* source "/etc/substitutes/berlin.guix.gnu.org.pub"))
  624. ("share/guix/bordeaux.guix.gnu.org.pub"
  625. ,(file-append* source "/etc/substitutes/bordeaux.guix.gnu.org.pub")))))
  626. (define* (whole-package name modules dependencies
  627. #:key
  628. (guile-version (effective-version))
  629. info daemon miscellany
  630. guile
  631. (command (guix-command modules
  632. #:dependencies dependencies
  633. #:guile guile
  634. #:guile-version guile-version)))
  635. "Return the whole Guix package NAME that uses MODULES, a derivation of all
  636. the modules (under share/guile/site and lib/guile), and DEPENDENCIES, a list
  637. of packages depended on. COMMAND is the 'guix' program to use; INFO is the
  638. Info manual."
  639. (define (wrap daemon)
  640. (program-file "guix-daemon"
  641. #~(begin
  642. ;; Refer to the right 'guix' command for 'guix
  643. ;; substitute' & co.
  644. (setenv "GUIX" #$command)
  645. ;; Honor the user's settings rather than those hardcoded
  646. ;; in the 'guix-daemon' package.
  647. (unless (getenv "GUIX_STATE_DIRECTORY")
  648. (setenv "GUIX_STATE_DIRECTORY"
  649. #$(string-append %localstatedir "/guix")))
  650. (unless (getenv "GUIX_CONFIGURATION_DIRECTORY")
  651. (setenv "GUIX_CONFIGURATION_DIRECTORY"
  652. #$(string-append %sysconfdir "/guix")))
  653. (unless (getenv "NIX_STORE_DIR")
  654. (setenv "NIX_STORE_DIR" #$%storedir))
  655. (apply execl #$(file-append daemon "/bin/guix-daemon")
  656. "guix-daemon" (cdr (command-line))))))
  657. (computed-file name
  658. (with-imported-modules '((guix build utils))
  659. #~(begin
  660. (use-modules (guix build utils))
  661. (define daemon
  662. #$(and daemon (wrap daemon)))
  663. (mkdir-p (string-append #$output "/bin"))
  664. (symlink #$command
  665. (string-append #$output "/bin/guix"))
  666. (when daemon
  667. (symlink daemon
  668. (string-append #$output "/bin/guix-daemon")))
  669. (let ((share (string-append #$output "/share"))
  670. (lib (string-append #$output "/lib"))
  671. (info #$info))
  672. (mkdir-p share)
  673. (symlink #$(file-append modules "/share/guile")
  674. (string-append share "/guile"))
  675. (when info
  676. (symlink #$info (string-append share "/info")))
  677. (mkdir-p lib)
  678. (symlink #$(file-append modules "/lib/guile")
  679. (string-append lib "/guile")))
  680. (when #$miscellany
  681. (copy-recursively #$miscellany #$output
  682. #:log (%make-void-port "w")))))))
  683. (define (transitive-package-dependencies package)
  684. "Return the list of packages propagated by PACKAGE, including PACKAGE
  685. itself."
  686. (match (package-transitive-propagated-inputs package)
  687. (((labels packages _ ...) ...)
  688. (cons package packages))))
  689. (define* (compiled-guix source #:key
  690. (version %guix-version)
  691. (channel-metadata #f)
  692. (pull-version 1)
  693. (name (string-append "guix-" version))
  694. (guile-version (effective-version))
  695. (guile-for-build (default-guile))
  696. (gzip (specification->package "gzip"))
  697. (bzip2 (specification->package "bzip2"))
  698. (xz (specification->package "xz"))
  699. (guix (specification->package "guix")))
  700. "Return a file-like object that contains a compiled Guix."
  701. (define guile-avahi
  702. (specification->package "guile-avahi"))
  703. (define guile-json
  704. (specification->package "guile-json"))
  705. (define guile-ssh
  706. (specification->package "guile-ssh"))
  707. (define guile-lib
  708. (specification->package "guile-lib"))
  709. (define guile-git
  710. (specification->package "guile-git"))
  711. (define guile-sqlite3
  712. (specification->package "guile-sqlite3"))
  713. (define guile-zlib
  714. (specification->package "guile-zlib"))
  715. (define guile-lzlib
  716. (specification->package "guile-lzlib"))
  717. (define guile-zstd
  718. (specification->package "guile-zstd"))
  719. (define guile-gcrypt
  720. (specification->package "guile-gcrypt"))
  721. (define guile-semver
  722. (specification->package "guile-semver"))
  723. (define gnutls
  724. (specification->package "gnutls"))
  725. (define disarchive
  726. (specification->package "disarchive"))
  727. (define dependencies
  728. (append-map transitive-package-dependencies
  729. (list guile-gcrypt gnutls guile-git guile-avahi
  730. guile-json guile-semver guile-ssh guile-sqlite3
  731. guile-lib guile-zlib guile-lzlib guile-zstd)))
  732. (define *core-modules*
  733. (scheme-node "guix-core"
  734. '((guix)
  735. (guix monad-repl)
  736. (guix packages)
  737. (guix download)
  738. (guix discovery)
  739. (guix profiles)
  740. (guix build-system gnu)
  741. (guix build-system trivial)
  742. (guix build profiles)
  743. (guix build gnu-build-system))
  744. ;; Provide a dummy (guix config) with the default version
  745. ;; number, storedir, etc. This is so that "guix-core" is the
  746. ;; same across all installations and doesn't need to be
  747. ;; rebuilt when the version changes, which in turn means we
  748. ;; can have substitutes for it.
  749. #:extra-modules
  750. `(((guix config)
  751. => ,(make-config.scm
  752. #:config-variables %default-config-variables)))
  753. ;; (guix man-db) is needed at build-time by (guix profiles)
  754. ;; but we don't need to compile it; not compiling it allows
  755. ;; us to avoid an extra dependency on guile-gdbm-ffi.
  756. #:extra-files
  757. `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm"))
  758. ("guix/build/po.scm" ,(local-file "../guix/build/po.scm"))
  759. ("guix/store/schema.sql"
  760. ,(local-file "../guix/store/schema.sql")))
  761. #:extensions (list guile-gcrypt
  762. guile-json) ;for (guix swh)
  763. #:guile-for-build guile-for-build))
  764. (define *extra-modules*
  765. (scheme-node "guix-extra"
  766. (filter-map (match-lambda
  767. (('guix 'scripts _ ..1) #f)
  768. (('guix 'man-db) #f)
  769. (('guix 'tests _ ...) #f)
  770. (name name))
  771. (scheme-modules* source "guix"))
  772. (list *core-modules*)
  773. #:extra-files
  774. `(("guix/graph.js" ,(local-file "../guix/graph.js"))
  775. ("guix/d3.v3.js" ,(local-file "../guix/d3.v3.js")))
  776. #:extensions dependencies
  777. #:guile-for-build guile-for-build))
  778. (define *core-package-modules*
  779. (scheme-node "guix-packages-base"
  780. `((gnu packages)
  781. (gnu packages base))
  782. (list *core-modules* *extra-modules*)
  783. #:extensions dependencies
  784. ;; Add all the non-Scheme files here. We must do it here so
  785. ;; that 'search-patches' & co. can find them. Ideally we'd
  786. ;; keep them next to the .scm files that use them but it's
  787. ;; difficult to do (XXX).
  788. #:extra-files
  789. (file-imports source "gnu/packages"
  790. (lambda (file stat)
  791. (and (eq? 'regular (stat:type stat))
  792. (not (string-suffix? ".scm" file))
  793. (not (string-suffix? ".go" file))
  794. (not (string-prefix? ".#" file))
  795. (not (string-suffix? "~" file)))))
  796. #:guile-for-build guile-for-build))
  797. (define *package-modules*
  798. (scheme-node "guix-packages"
  799. (scheme-modules* source "gnu/packages")
  800. (list *core-modules* *extra-modules* *core-package-modules*)
  801. #:extensions dependencies
  802. #:guile-for-build guile-for-build))
  803. (define *system-modules*
  804. (scheme-node "guix-system"
  805. `((gnu system)
  806. (gnu services)
  807. ,@(scheme-modules* source "gnu/bootloader")
  808. ,@(scheme-modules* source "gnu/system")
  809. ,@(scheme-modules* source "gnu/services")
  810. ,@(scheme-modules* source "gnu/machine"))
  811. (list *core-package-modules* *package-modules*
  812. *extra-modules* *core-modules*)
  813. #:extensions dependencies
  814. #:extra-files
  815. (append (file-imports source "gnu/system/examples"
  816. (const #t))
  817. ;; All the installer code is on the build-side.
  818. (file-imports source "gnu/installer/"
  819. (const #t))
  820. ;; Build-side code that we don't build. Some of
  821. ;; these depend on guile-rsvg, the Shepherd, etc.
  822. (file-imports source "gnu/build" (const #t)))
  823. #:guile-for-build
  824. guile-for-build))
  825. (define *cli-modules*
  826. (scheme-node "guix-cli"
  827. (append (scheme-modules* source "/guix/scripts")
  828. `((gnu ci)))
  829. (list *core-modules* *extra-modules*
  830. *core-package-modules* *package-modules*
  831. *system-modules*)
  832. #:extensions dependencies
  833. #:guile-for-build guile-for-build))
  834. (define *system-test-modules*
  835. ;; Ship these modules mostly so (gnu ci) can discover them.
  836. (scheme-node "guix-system-tests"
  837. `((gnu tests)
  838. ,@(scheme-modules* source "gnu/tests"))
  839. (list *core-package-modules* *package-modules*
  840. *extra-modules* *system-modules* *core-modules*
  841. *cli-modules*) ;for (guix scripts pack), etc.
  842. #:extra-files (file-imports source "gnu/tests/data"
  843. (const #t))
  844. #:extensions dependencies
  845. #:guile-for-build guile-for-build))
  846. (define *config*
  847. (scheme-node "guix-config"
  848. '()
  849. #:extra-modules
  850. `(((guix config)
  851. => ,(make-config.scm #:gzip gzip
  852. #:bzip2 bzip2
  853. #:xz xz
  854. #:package-name
  855. %guix-package-name
  856. #:package-version
  857. version
  858. #:channel-metadata
  859. channel-metadata
  860. #:bug-report-address
  861. %guix-bug-report-address
  862. #:home-page-url
  863. %guix-home-page-url)))
  864. #:guile-for-build guile-for-build))
  865. (define (built-modules node-subset)
  866. (directory-union (string-append name "-modules")
  867. (append-map node-subset
  868. ;; Note: *CONFIG* comes first so that it
  869. ;; overrides the (guix config) module that
  870. ;; comes with *CORE-MODULES*.
  871. (list *config*
  872. *cli-modules*
  873. *system-test-modules*
  874. *system-modules*
  875. *package-modules*
  876. *core-package-modules*
  877. *extra-modules*
  878. *core-modules*))
  879. ;; Silently choose the first entry upon collision so that
  880. ;; we choose *CONFIG*.
  881. #:resolve-collision 'first
  882. ;; When we do (add-to-store "utils.scm"), "utils.scm" must
  883. ;; be a regular file, not a symlink. Thus, arrange so that
  884. ;; regular files appear as regular files in the final
  885. ;; output.
  886. #:copy? #t
  887. #:quiet? #t))
  888. ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
  889. ;; Version 1 is when we return the full package.
  890. (cond ((= 1 pull-version)
  891. ;; The whole package, with a standard file hierarchy.
  892. (let* ((modules (built-modules (compose list node-source+compiled)))
  893. (command (guix-command modules
  894. #:source source
  895. #:dependencies
  896. (cons disarchive dependencies)
  897. #:guile guile-for-build
  898. #:guile-version guile-version)))
  899. (whole-package name modules dependencies
  900. #:command command
  901. #:guile guile-for-build
  902. ;; Include 'guix-daemon'. XXX: Here we inject an
  903. ;; older snapshot of guix-daemon, but that's a good
  904. ;; enough approximation for now.
  905. #:daemon (module-ref (resolve-interface
  906. '(gnu packages
  907. package-management))
  908. 'guix-daemon)
  909. #:info (info-manual source)
  910. #:miscellany (miscellaneous-files source)
  911. #:guile-version guile-version)))
  912. ((= 0 pull-version)
  913. ;; Legacy 'guix pull': return the .scm and .go files as one
  914. ;; directory.
  915. (built-modules (lambda (node)
  916. (list (node-source node)
  917. (node-compiled node)))))
  918. (else
  919. ;; Unsupported 'guix pull' version.
  920. #f)))
  921. ;;;
  922. ;;; Generating (guix config).
  923. ;;;
  924. (define %persona-variables
  925. ;; (guix config) variables that define Guix's persona.
  926. '(%guix-package-name
  927. %guix-version
  928. %guix-bug-report-address
  929. %guix-home-page-url))
  930. (define %config-variables
  931. ;; (guix config) variables corresponding to Guix configuration.
  932. (letrec-syntax ((variables (syntax-rules ()
  933. ((_)
  934. '())
  935. ((_ variable rest ...)
  936. (cons `(variable . ,variable)
  937. (variables rest ...))))))
  938. (variables %localstatedir %storedir %sysconfdir)))
  939. (define %default-config-variables
  940. ;; Default values of the configuration variables above.
  941. `((%localstatedir . "/var")
  942. (%storedir . "/gnu/store")
  943. (%sysconfdir . "/etc")))
  944. (define* (make-config.scm #:key gzip xz bzip2
  945. (package-name "GNU Guix")
  946. (package-version "0")
  947. (channel-metadata #f)
  948. (config-variables %config-variables)
  949. (bug-report-address "bug-guix@gnu.org")
  950. (home-page-url "https://guix.gnu.org"))
  951. ;; Hack so that Geiser is not confused.
  952. (define defmod 'define-module)
  953. (scheme-file "config.scm"
  954. #~(;; The following expressions get spliced.
  955. (#$defmod (guix config)
  956. #:export (%guix-package-name
  957. %guix-version
  958. %guix-bug-report-address
  959. %guix-home-page-url
  960. %channel-metadata
  961. %system
  962. %store-directory
  963. %state-directory
  964. %store-database-directory
  965. %config-directory
  966. %gzip
  967. %bzip2
  968. %xz))
  969. (define %system
  970. #$(%current-system))
  971. #$@(map (match-lambda
  972. ((name . value)
  973. #~(define-public #$name #$value)))
  974. config-variables)
  975. (define %store-directory
  976. (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
  977. %storedir))
  978. (define %state-directory
  979. ;; This must match `NIX_STATE_DIR' as defined in
  980. ;; `nix/local.mk'.
  981. (or (getenv "GUIX_STATE_DIRECTORY")
  982. (string-append %localstatedir "/guix")))
  983. (define %store-database-directory
  984. (or (getenv "GUIX_DATABASE_DIRECTORY")
  985. (string-append %state-directory "/db")))
  986. (define %config-directory
  987. ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as
  988. ;; defined in `nix/local.mk'.
  989. (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
  990. (string-append %sysconfdir "/guix")))
  991. (define %guix-package-name #$package-name)
  992. (define %guix-version #$package-version)
  993. (define %guix-bug-report-address #$bug-report-address)
  994. (define %guix-home-page-url #$home-page-url)
  995. (define %channel-metadata
  996. ;; Metadata for the 'guix' channel in use. This
  997. ;; information is used by (guix describe).
  998. '#$channel-metadata)
  999. (define %gzip
  1000. #+(and gzip (file-append gzip "/bin/gzip")))
  1001. (define %bzip2
  1002. #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
  1003. (define %xz
  1004. #+(and xz (file-append xz "/bin/xz"))))
  1005. ;; Guile 2.0 *requires* the 'define-module' to be at the
  1006. ;; top-level or the 'toplevel-ref' in the resulting .go file are
  1007. ;; made relative to a nonexistent anonymous module.
  1008. #:splice? #t))
  1009. ;;;
  1010. ;;; Building.
  1011. ;;;
  1012. (define* (compiled-modules name module-tree module-files
  1013. #:optional
  1014. (dependencies '())
  1015. (dependencies-compiled '())
  1016. #:key
  1017. (extensions '()) ;full-blown Guile packages
  1018. parallel?
  1019. guile-for-build)
  1020. "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list
  1021. like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory
  1022. containing MODULE-FILES and possibly other files as well."
  1023. ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix
  1024. ;; gexp).
  1025. (define build
  1026. (with-imported-modules (source-module-closure
  1027. '((guix build compile)
  1028. (guix build utils)))
  1029. #~(begin
  1030. (use-modules (srfi srfi-26)
  1031. (ice-9 match)
  1032. (ice-9 format)
  1033. (ice-9 threads)
  1034. (guix build compile)
  1035. (guix build utils))
  1036. (define (regular? file)
  1037. (not (member file '("." ".."))))
  1038. (define (report-load file total completed)
  1039. (display #\cr)
  1040. (format #t
  1041. "[~3@a/~3@a] loading...\t~5,1f% of ~d files"
  1042. ;; Note: Multiply TOTAL by two to account for the
  1043. ;; compilation phase that follows.
  1044. completed (* total 2)
  1045. (* 100. (/ completed total)) total)
  1046. (force-output))
  1047. (define (report-compilation file total completed)
  1048. (display #\cr)
  1049. (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files"
  1050. ;; Add TOTAL to account for the load phase that came
  1051. ;; before.
  1052. (+ total completed) (* total 2)
  1053. (* 100. (/ completed total)) total)
  1054. (force-output))
  1055. (define (process-directory directory files output)
  1056. ;; Hide compilation warnings.
  1057. (parameterize ((current-warning-port (%make-void-port "w")))
  1058. (compile-files directory #$output files
  1059. #:workers (parallel-job-count)
  1060. #:report-load report-load
  1061. #:report-compilation report-compilation)))
  1062. (setvbuf (current-output-port) 'line)
  1063. (setvbuf (current-error-port) 'line)
  1064. (set! %load-path (cons #+module-tree %load-path))
  1065. (set! %load-path
  1066. (append '#+dependencies
  1067. (map (lambda (extension)
  1068. (string-append extension "/share/guile/site/"
  1069. (effective-version)))
  1070. '#+extensions)
  1071. %load-path))
  1072. (set! %load-compiled-path
  1073. (append '#+dependencies-compiled
  1074. (map (lambda (extension)
  1075. (string-append extension "/lib/guile/"
  1076. (effective-version)
  1077. "/site-ccache"))
  1078. '#+extensions)
  1079. %load-compiled-path))
  1080. ;; Load the compiler modules upfront.
  1081. (compile #f)
  1082. (mkdir #$output)
  1083. (chdir #+module-tree)
  1084. (process-directory "." '#+module-files #$output)
  1085. (newline))))
  1086. (computed-file name build
  1087. #:guile guile-for-build
  1088. #:options
  1089. `(#:local-build? #f ;allow substitutes
  1090. ;; Don't annoy people about _IONBF deprecation.
  1091. ;; Initialize 'terminal-width' in (system repl debug)
  1092. ;; to a large-enough value to make backtrace more
  1093. ;; verbose.
  1094. #:env-vars (("GUILE_WARN_DEPRECATED" . "no")
  1095. ("COLUMNS" . "200")))))
  1096. ;;;
  1097. ;;; Building.
  1098. ;;;
  1099. (define* (guix-derivation source version
  1100. #:optional (guile-version (effective-version))
  1101. #:key (pull-version 0)
  1102. channel-metadata)
  1103. "Return, as a monadic value, the derivation to build the Guix from SOURCE
  1104. for GUILE-VERSION. Use VERSION as the version string. Use CHANNEL-METADATA
  1105. as the channel metadata sexp to include in (guix config).
  1106. PULL-VERSION specifies the version of the 'guix pull' protocol. Return #f if
  1107. this PULL-VERSION value is not supported."
  1108. (define (shorten version)
  1109. (if (and (string-every char-set:hex-digit version)
  1110. (> (string-length version) 9))
  1111. (string-take version 9) ;Git commit
  1112. version))
  1113. (define guile
  1114. ;; When PULL-VERSION >= 1, produce a self-contained Guix and use the
  1115. ;; current Guile unconditionally.
  1116. (specification->package "guile"))
  1117. (when (and (< pull-version 1)
  1118. (not (string=? (package-version guile) guile-version)))
  1119. ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and
  1120. ;; can be any version. When that happens and Guile is not current (e.g.,
  1121. ;; it's Guile 2.0), just bail out.
  1122. (raise (condition
  1123. (&message
  1124. (message "Guix is too old and cannot be upgraded")))))
  1125. (mbegin %store-monad
  1126. (set-guile-for-build guile)
  1127. (let ((guix (compiled-guix source
  1128. #:version version
  1129. #:channel-metadata channel-metadata
  1130. #:name (string-append "guix-"
  1131. (shorten version))
  1132. #:pull-version pull-version
  1133. #:guile-version (if (>= pull-version 1)
  1134. "3.0" guile-version)
  1135. #:guile-for-build guile)))
  1136. (if guix
  1137. (lower-object guix)
  1138. (return #f)))))