self.scm 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  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/libgc-7))
  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. ("gzip" (ref '(gnu packages compression) 'gzip))
  63. ("bzip2" (ref '(gnu packages compression) 'bzip2))
  64. ("xz" (ref '(gnu packages compression) 'xz))
  65. ("po4a" (ref '(gnu packages gettext) 'po4a))
  66. ("gettext" (ref '(gnu packages gettext) 'gettext-minimal))
  67. ("gcc-toolchain" (ref '(gnu packages commencement) 'gcc-toolchain))
  68. (_ #f)))) ;no such package
  69. ;;;
  70. ;;; Derivations.
  71. ;;;
  72. ;; Node in a DAG of build tasks. Each node maps to a derivation, but it's
  73. ;; easier to express things this way.
  74. (define-record-type <node>
  75. (node name modules source dependencies compiled)
  76. node?
  77. (name node-name) ;string
  78. (modules node-modules) ;list of module names
  79. (source node-source) ;list of source files
  80. (dependencies node-dependencies) ;list of nodes
  81. (compiled node-compiled)) ;node -> lowerable object
  82. ;; File mappings are essentially an alist as passed to 'imported-files'.
  83. (define-record-type <file-mapping>
  84. (file-mapping name alist)
  85. file-mapping?
  86. (name file-mapping-name)
  87. (alist file-mapping-alist))
  88. (define-gexp-compiler (file-mapping-compiler (mapping <file-mapping>)
  89. system target)
  90. ;; Here we use 'imported-files', which can arrange to directly import all
  91. ;; the files instead of creating a derivation, when possible.
  92. (imported-files (map (match-lambda
  93. ((destination (? local-file? file))
  94. (cons destination
  95. (local-file-absolute-file-name file)))
  96. ((destination source)
  97. (cons destination source))) ;silliness
  98. (file-mapping-alist mapping))
  99. #:name (file-mapping-name mapping)
  100. #:system system))
  101. (define (node-source+compiled node)
  102. "Return a \"bundle\" containing both the source code and object files for
  103. NODE's modules, under their FHS directories: share/guile/site and lib/guile."
  104. (define build
  105. (with-imported-modules '((guix build utils))
  106. #~(begin
  107. (use-modules (guix build utils))
  108. (define source
  109. (string-append #$output "/share/guile/site/"
  110. (effective-version)))
  111. (define object
  112. (string-append #$output "/lib/guile/" (effective-version)
  113. "/site-ccache"))
  114. (mkdir-p (dirname source))
  115. (symlink #$(node-source node) source)
  116. (mkdir-p (dirname object))
  117. (symlink #$(node-compiled node) object))))
  118. (computed-file (string-append (node-name node) "-modules")
  119. build
  120. #:options '(#:local-build? #t
  121. ;; "Building" it locally is faster.
  122. #:substitutable? #f)))
  123. (define (node-fold proc init nodes)
  124. (let loop ((nodes nodes)
  125. (visited (setq))
  126. (result init))
  127. (match nodes
  128. (() result)
  129. ((head tail ...)
  130. (if (set-contains? visited head)
  131. (loop tail visited result)
  132. (loop tail (set-insert head visited)
  133. (proc head result)))))))
  134. (define (node-modules/recursive nodes)
  135. (node-fold (lambda (node modules)
  136. (append (node-modules node) modules))
  137. '()
  138. nodes))
  139. (define* (closure modules #:optional (except '()))
  140. (source-module-closure modules
  141. #:select?
  142. (match-lambda
  143. (('guix 'config)
  144. #f)
  145. ((and module
  146. (or ('guix _ ...) ('gnu _ ...)))
  147. (not (member module except)))
  148. (rest #f))))
  149. (define module->import
  150. ;; Return a file-name/file-like object pair for the specified module and
  151. ;; suitable for 'imported-files'.
  152. (match-lambda
  153. ((module '=> thing)
  154. (let ((file (module-name->file-name module)))
  155. (list file thing)))
  156. (module
  157. (let ((file (module-name->file-name module)))
  158. (list file
  159. (local-file (search-path %load-path file)))))))
  160. (define* (scheme-node name modules #:optional (dependencies '())
  161. #:key (extra-modules '()) (extra-files '())
  162. (extensions '())
  163. parallel? guile-for-build)
  164. "Return a node that builds the given Scheme MODULES, and depends on
  165. DEPENDENCIES (a list of nodes). EXTRA-MODULES is a list of additional modules
  166. added to the source, and EXTRA-FILES is a list of additional files.
  167. EXTENSIONS is a set of full-blown Guile packages (e.g., 'guile-json') that
  168. must be present in the search path."
  169. (let* ((modules (append extra-modules
  170. (closure modules
  171. (node-modules/recursive dependencies))))
  172. (module-files (map module->import modules))
  173. (source (file-mapping (string-append name "-source")
  174. (append module-files extra-files))))
  175. (node name modules source dependencies
  176. (compiled-modules name source
  177. (map car module-files)
  178. (map node-source dependencies)
  179. (map node-compiled dependencies)
  180. #:extensions extensions
  181. #:parallel? parallel?
  182. #:guile-for-build guile-for-build))))
  183. (define (file-imports directory sub-directory pred)
  184. "List all the files matching PRED under DIRECTORY/SUB-DIRECTORY. Return a
  185. list of file-name/file-like objects suitable as inputs to 'imported-files'."
  186. (map (lambda (file)
  187. (list (string-drop file (+ 1 (string-length directory)))
  188. (local-file file #:recursive? #t)))
  189. (find-files (string-append directory "/" sub-directory) pred)))
  190. (define* (file-append* item file #:key (recursive? #t))
  191. "Return FILE within ITEM, which may be a file name or a file-like object.
  192. When ITEM is a plain file name (a string), simply return a 'local-file'
  193. record with the new file name."
  194. (match item
  195. ((? string?)
  196. ;; This is the optimal case: we return a new "source". Thus, a
  197. ;; derivation that depends on this sub-directory does not depend on ITEM
  198. ;; itself.
  199. (local-file (string-append item "/" file)
  200. #:recursive? recursive?))
  201. ((? local-file? base)
  202. ;; Likewise, but with a <local-file>.
  203. (if (local-file-recursive? base)
  204. (local-file (string-append (local-file-absolute-file-name base)
  205. "/" file)
  206. (basename file)
  207. #:recursive? recursive?
  208. #:select? (local-file-select? base))
  209. (file-append base file)))
  210. (_
  211. ;; In this case, anything that refers to the result also depends on ITEM,
  212. ;; which isn't great.
  213. (file-append item "/" file))))
  214. (define* (locale-data source domain
  215. #:optional (directory domain))
  216. "Return the locale data from 'po/DIRECTORY' in SOURCE, corresponding to
  217. DOMAIN, a gettext domain."
  218. (define gettext
  219. (module-ref (resolve-interface '(gnu packages gettext))
  220. 'gettext-minimal))
  221. (define build
  222. (with-imported-modules '((guix build utils))
  223. #~(begin
  224. (use-modules (guix build utils)
  225. (srfi srfi-26)
  226. (ice-9 match) (ice-9 ftw))
  227. (define po-directory
  228. #+(file-append* source (string-append "po/" directory)))
  229. (define (compile language)
  230. (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/"
  231. #$domain ".mo")))
  232. (mkdir-p (dirname gmo))
  233. (invoke #+(file-append gettext "/bin/msgfmt")
  234. "-c" "--statistics" "--verbose"
  235. "-o" gmo
  236. (string-append po-directory "/" language ".po"))))
  237. (define (linguas)
  238. ;; Return the list of languages. Note: don't read 'LINGUAS'
  239. ;; because it contains things like 'en@boldquot' that do not have
  240. ;; a corresponding .po file.
  241. (map (cut basename <> ".po")
  242. (scandir po-directory
  243. (cut string-suffix? ".po" <>))))
  244. (for-each compile (linguas)))))
  245. (computed-file (string-append "guix-locale-" domain)
  246. build))
  247. (define (translate-texi-manuals source)
  248. "Return the translated texinfo manuals built from SOURCE."
  249. (define po4a
  250. (specification->package "po4a"))
  251. (define gettext
  252. (specification->package "gettext"))
  253. (define glibc-utf8-locales
  254. (module-ref (resolve-interface '(gnu packages base))
  255. 'glibc-utf8-locales))
  256. (define documentation
  257. (file-append* source "doc"))
  258. (define documentation-po
  259. (file-append* source "po/doc"))
  260. (define build
  261. (with-imported-modules '((guix build utils) (guix build po))
  262. #~(begin
  263. (use-modules (guix build utils) (guix build po)
  264. (ice-9 match) (ice-9 regex) (ice-9 textual-ports)
  265. (ice-9 vlist) (ice-9 threads)
  266. (srfi srfi-1))
  267. (define (translate-tmp-texi po source output)
  268. "Translate Texinfo file SOURCE using messages from PO, and write
  269. the result to OUTPUT."
  270. (invoke #+(file-append po4a "/bin/po4a-translate")
  271. "-M" "UTF-8" "-L" "UTF-8" "-k" "0" "-f" "texinfo"
  272. "-m" source "-p" po "-l" output))
  273. (define (canonicalize-whitespace str)
  274. ;; Change whitespace (newlines, etc.) in STR to #\space.
  275. (string-map (lambda (chr)
  276. (if (char-set-contains? char-set:whitespace chr)
  277. #\space
  278. chr))
  279. str))
  280. (define xref-regexp
  281. ;; Texinfo cross-reference regexp.
  282. (make-regexp "@(px|x)?ref\\{([^,}]+)"))
  283. (define (translate-cross-references texi translations)
  284. ;; Translate the cross-references that appear in TEXI, a Texinfo
  285. ;; file, using the msgid/msgstr pairs from TRANSLATIONS.
  286. (define content
  287. (call-with-input-file texi get-string-all))
  288. (define matches
  289. (list-matches xref-regexp content))
  290. (define translation-map
  291. (fold (match-lambda*
  292. (((msgid . str) result)
  293. (vhash-cons msgid str result)))
  294. vlist-null
  295. translations))
  296. (define translated
  297. ;; Iterate over MATCHES and replace cross-references with their
  298. ;; translation found in TRANSLATION-MAP. (We can't use
  299. ;; 'substitute*' because matches can span multiple lines.)
  300. (let loop ((matches matches)
  301. (offset 0)
  302. (result '()))
  303. (match matches
  304. (()
  305. (string-concatenate-reverse
  306. (cons (string-drop content offset) result)))
  307. ((head . tail)
  308. (let ((prefix (match:substring head 1))
  309. (ref (canonicalize-whitespace (match:substring head 2))))
  310. (define translated
  311. (string-append "@" (or prefix "")
  312. "ref{"
  313. (match (vhash-assoc ref translation-map)
  314. (#f ref)
  315. ((_ . str) str))))
  316. (loop tail
  317. (match:end head)
  318. (append (list translated
  319. (string-take
  320. (string-drop content offset)
  321. (- (match:start head) offset)))
  322. result)))))))
  323. (format (current-error-port)
  324. "translated ~a cross-references in '~a'~%"
  325. (length matches) texi)
  326. (call-with-output-file texi
  327. (lambda (port)
  328. (display translated port))))
  329. (define* (translate-texi prefix po lang
  330. #:key (extras '()))
  331. "Translate the manual for one language LANG using the PO file.
  332. PREFIX must be the prefix of the manual, 'guix' or 'guix-cookbook'. EXTRAS is
  333. a list of extra files, such as '(\"contributing\")."
  334. (let ((translations (call-with-input-file po read-po-file)))
  335. (for-each (lambda (file)
  336. (translate-tmp-texi po (string-append file ".texi")
  337. (string-append file "." lang
  338. ".texi.tmp")))
  339. (cons prefix extras))
  340. (for-each (lambda (file)
  341. (let* ((texi (string-append file "." lang ".texi"))
  342. (tmp (string-append texi ".tmp")))
  343. (copy-file tmp texi)
  344. (translate-cross-references texi
  345. translations)))
  346. (cons prefix extras))))
  347. (define (available-translations directory domain)
  348. ;; Return the list of available translations under DIRECTORY for
  349. ;; DOMAIN, a gettext domain such as "guix-manual". The result is
  350. ;; a list of language/PO file pairs.
  351. (filter-map (lambda (po)
  352. (let ((base (basename po)))
  353. (and (string-prefix? (string-append domain ".")
  354. base)
  355. (match (string-split base #\.)
  356. ((_ ... lang "po")
  357. (cons lang po))))))
  358. (find-files directory
  359. "\\.[a-z]{2}(_[A-Z]{2})?\\.po$")))
  360. (define parallel-jobs
  361. ;; Limit thread creation by 'n-par-for-each'. Going beyond can
  362. ;; lead libgc 8.0.4 to abort with:
  363. ;; mmap(PROT_NONE) failed
  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. (define* (whole-package name modules dependencies
  625. #:key
  626. (guile-version (effective-version))
  627. info daemon miscellany
  628. guile
  629. (command (guix-command modules
  630. #:dependencies dependencies
  631. #:guile guile
  632. #:guile-version guile-version)))
  633. "Return the whole Guix package NAME that uses MODULES, a derivation of all
  634. the modules (under share/guile/site and lib/guile), and DEPENDENCIES, a list
  635. of packages depended on. COMMAND is the 'guix' program to use; INFO is the
  636. Info manual."
  637. (define (wrap daemon)
  638. (program-file "guix-daemon"
  639. #~(begin
  640. ;; Refer to the right 'guix' command for 'guix
  641. ;; substitute' & co.
  642. (setenv "GUIX" #$command)
  643. ;; Honor the user's settings rather than those hardcoded
  644. ;; in the 'guix-daemon' package.
  645. (unless (getenv "GUIX_STATE_DIRECTORY")
  646. (setenv "GUIX_STATE_DIRECTORY"
  647. #$(string-append %localstatedir "/guix")))
  648. (unless (getenv "GUIX_CONFIGURATION_DIRECTORY")
  649. (setenv "GUIX_CONFIGURATION_DIRECTORY"
  650. #$(string-append %sysconfdir "/guix")))
  651. (unless (getenv "NIX_STORE_DIR")
  652. (setenv "NIX_STORE_DIR" #$%storedir))
  653. (apply execl #$(file-append daemon "/bin/guix-daemon")
  654. "guix-daemon" (cdr (command-line))))))
  655. (computed-file name
  656. (with-imported-modules '((guix build utils))
  657. #~(begin
  658. (use-modules (guix build utils))
  659. (define daemon
  660. #$(and daemon (wrap daemon)))
  661. (mkdir-p (string-append #$output "/bin"))
  662. (symlink #$command
  663. (string-append #$output "/bin/guix"))
  664. (when daemon
  665. (symlink daemon
  666. (string-append #$output "/bin/guix-daemon")))
  667. (let ((share (string-append #$output "/share"))
  668. (lib (string-append #$output "/lib"))
  669. (info #$info))
  670. (mkdir-p share)
  671. (symlink #$(file-append modules "/share/guile")
  672. (string-append share "/guile"))
  673. (when info
  674. (symlink #$info (string-append share "/info")))
  675. (mkdir-p lib)
  676. (symlink #$(file-append modules "/lib/guile")
  677. (string-append lib "/guile")))
  678. (when #$miscellany
  679. (copy-recursively #$miscellany #$output
  680. #:log (%make-void-port "w")))))))
  681. (define (transitive-package-dependencies package)
  682. "Return the list of packages propagated by PACKAGE, including PACKAGE
  683. itself."
  684. (match (package-transitive-propagated-inputs package)
  685. (((labels packages _ ...) ...)
  686. (cons package packages))))
  687. (define* (compiled-guix source #:key
  688. (version %guix-version)
  689. (channel-metadata #f)
  690. (pull-version 1)
  691. (name (string-append "guix-" version))
  692. (guile-version (effective-version))
  693. (guile-for-build (default-guile))
  694. (gzip (specification->package "gzip"))
  695. (bzip2 (specification->package "bzip2"))
  696. (xz (specification->package "xz"))
  697. (guix (specification->package "guix")))
  698. "Return a file-like object that contains a compiled Guix."
  699. (define guile-avahi
  700. (specification->package "guile-avahi"))
  701. (define guile-json
  702. (specification->package "guile-json"))
  703. (define guile-ssh
  704. (specification->package "guile-ssh"))
  705. (define guile-lib
  706. (specification->package "guile-lib"))
  707. (define guile-git
  708. (specification->package "guile-git"))
  709. (define guile-sqlite3
  710. (specification->package "guile-sqlite3"))
  711. (define guile-zlib
  712. (specification->package "guile-zlib"))
  713. (define guile-lzlib
  714. (specification->package "guile-lzlib"))
  715. (define guile-zstd
  716. (specification->package "guile-zstd"))
  717. (define guile-gcrypt
  718. (specification->package "guile-gcrypt"))
  719. (define guile-semver
  720. (specification->package "guile-semver"))
  721. (define gnutls
  722. (specification->package "gnutls"))
  723. (define dependencies
  724. (append-map transitive-package-dependencies
  725. (list guile-gcrypt gnutls guile-git guile-avahi
  726. guile-json guile-semver guile-ssh guile-sqlite3
  727. guile-lib guile-zlib guile-lzlib guile-zstd)))
  728. (define *core-modules*
  729. (scheme-node "guix-core"
  730. '((guix)
  731. (guix monad-repl)
  732. (guix packages)
  733. (guix download)
  734. (guix discovery)
  735. (guix profiles)
  736. (guix build-system gnu)
  737. (guix build-system trivial)
  738. (guix build profiles)
  739. (guix build gnu-build-system))
  740. ;; Provide a dummy (guix config) with the default version
  741. ;; number, storedir, etc. This is so that "guix-core" is the
  742. ;; same across all installations and doesn't need to be
  743. ;; rebuilt when the version changes, which in turn means we
  744. ;; can have substitutes for it.
  745. #:extra-modules
  746. `(((guix config) => ,(make-config.scm)))
  747. ;; (guix man-db) is needed at build-time by (guix profiles)
  748. ;; but we don't need to compile it; not compiling it allows
  749. ;; us to avoid an extra dependency on guile-gdbm-ffi.
  750. #:extra-files
  751. `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm"))
  752. ("guix/build/po.scm" ,(local-file "../guix/build/po.scm"))
  753. ("guix/store/schema.sql"
  754. ,(local-file "../guix/store/schema.sql")))
  755. #:extensions (list guile-gcrypt)
  756. #:guile-for-build guile-for-build))
  757. (define *extra-modules*
  758. (scheme-node "guix-extra"
  759. (filter-map (match-lambda
  760. (('guix 'scripts _ ..1) #f)
  761. (('guix 'man-db) #f)
  762. (('guix 'tests _ ...) #f)
  763. (name name))
  764. (scheme-modules* source "guix"))
  765. (list *core-modules*)
  766. #:extra-files
  767. `(("guix/graph.js" ,(local-file "../guix/graph.js"))
  768. ("guix/d3.v3.js" ,(local-file "../guix/d3.v3.js")))
  769. #:extensions dependencies
  770. #:guile-for-build guile-for-build))
  771. (define *core-package-modules*
  772. (scheme-node "guix-packages-base"
  773. `((gnu packages)
  774. (gnu packages base))
  775. (list *core-modules* *extra-modules*)
  776. #:extensions dependencies
  777. ;; Add all the non-Scheme files here. We must do it here so
  778. ;; that 'search-patches' & co. can find them. Ideally we'd
  779. ;; keep them next to the .scm files that use them but it's
  780. ;; difficult to do (XXX).
  781. #:extra-files
  782. (file-imports source "gnu/packages"
  783. (lambda (file stat)
  784. (and (eq? 'regular (stat:type stat))
  785. (not (string-suffix? ".scm" file))
  786. (not (string-suffix? ".go" file))
  787. (not (string-prefix? ".#" file))
  788. (not (string-suffix? "~" file)))))
  789. #:guile-for-build guile-for-build))
  790. (define *package-modules*
  791. (scheme-node "guix-packages"
  792. (scheme-modules* source "gnu/packages")
  793. (list *core-modules* *extra-modules* *core-package-modules*)
  794. #:extensions dependencies
  795. #:guile-for-build guile-for-build))
  796. (define *system-modules*
  797. (scheme-node "guix-system"
  798. `((gnu system)
  799. (gnu services)
  800. ,@(scheme-modules* source "gnu/bootloader")
  801. ,@(scheme-modules* source "gnu/system")
  802. ,@(scheme-modules* source "gnu/services")
  803. ,@(scheme-modules* source "gnu/machine"))
  804. (list *core-package-modules* *package-modules*
  805. *extra-modules* *core-modules*)
  806. #:extensions dependencies
  807. #:extra-files
  808. (append (file-imports source "gnu/system/examples"
  809. (const #t))
  810. ;; All the installer code is on the build-side.
  811. (file-imports source "gnu/installer/"
  812. (const #t))
  813. ;; Build-side code that we don't build. Some of
  814. ;; these depend on guile-rsvg, the Shepherd, etc.
  815. (file-imports source "gnu/build" (const #t)))
  816. #:guile-for-build
  817. guile-for-build))
  818. (define *cli-modules*
  819. (scheme-node "guix-cli"
  820. (append (scheme-modules* source "/guix/scripts")
  821. `((gnu ci)))
  822. (list *core-modules* *extra-modules*
  823. *core-package-modules* *package-modules*
  824. *system-modules*)
  825. #:extensions dependencies
  826. #:guile-for-build guile-for-build))
  827. (define *system-test-modules*
  828. ;; Ship these modules mostly so (gnu ci) can discover them.
  829. (scheme-node "guix-system-tests"
  830. `((gnu tests)
  831. ,@(scheme-modules* source "gnu/tests"))
  832. (list *core-package-modules* *package-modules*
  833. *extra-modules* *system-modules* *core-modules*
  834. *cli-modules*) ;for (guix scripts pack), etc.
  835. #:extensions dependencies
  836. #:guile-for-build guile-for-build))
  837. (define *config*
  838. (scheme-node "guix-config"
  839. '()
  840. #:extra-modules
  841. `(((guix config)
  842. => ,(make-config.scm #:gzip gzip
  843. #:bzip2 bzip2
  844. #:xz xz
  845. #:package-name
  846. %guix-package-name
  847. #:package-version
  848. version
  849. #:channel-metadata
  850. channel-metadata
  851. #:bug-report-address
  852. %guix-bug-report-address
  853. #:home-page-url
  854. %guix-home-page-url)))
  855. #:guile-for-build guile-for-build))
  856. (define (built-modules node-subset)
  857. (directory-union (string-append name "-modules")
  858. (append-map node-subset
  859. ;; Note: *CONFIG* comes first so that it
  860. ;; overrides the (guix config) module that
  861. ;; comes with *CORE-MODULES*.
  862. (list *config*
  863. *cli-modules*
  864. *system-test-modules*
  865. *system-modules*
  866. *package-modules*
  867. *core-package-modules*
  868. *extra-modules*
  869. *core-modules*))
  870. ;; Silently choose the first entry upon collision so that
  871. ;; we choose *CONFIG*.
  872. #:resolve-collision 'first
  873. ;; When we do (add-to-store "utils.scm"), "utils.scm" must
  874. ;; be a regular file, not a symlink. Thus, arrange so that
  875. ;; regular files appear as regular files in the final
  876. ;; output.
  877. #:copy? #t
  878. #:quiet? #t))
  879. ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
  880. ;; Version 1 is when we return the full package.
  881. (cond ((= 1 pull-version)
  882. ;; The whole package, with a standard file hierarchy.
  883. (let* ((modules (built-modules (compose list node-source+compiled)))
  884. (command (guix-command modules
  885. #:source source
  886. #:dependencies dependencies
  887. #:guile guile-for-build
  888. #:guile-version guile-version)))
  889. (whole-package name modules dependencies
  890. #:command command
  891. #:guile guile-for-build
  892. ;; Include 'guix-daemon'. XXX: Here we inject an
  893. ;; older snapshot of guix-daemon, but that's a good
  894. ;; enough approximation for now.
  895. #:daemon (module-ref (resolve-interface
  896. '(gnu packages
  897. package-management))
  898. 'guix-daemon)
  899. #:info (info-manual source)
  900. #:miscellany (miscellaneous-files source)
  901. #:guile-version guile-version)))
  902. ((= 0 pull-version)
  903. ;; Legacy 'guix pull': return the .scm and .go files as one
  904. ;; directory.
  905. (built-modules (lambda (node)
  906. (list (node-source node)
  907. (node-compiled node)))))
  908. (else
  909. ;; Unsupported 'guix pull' version.
  910. #f)))
  911. ;;;
  912. ;;; Generating (guix config).
  913. ;;;
  914. (define %persona-variables
  915. ;; (guix config) variables that define Guix's persona.
  916. '(%guix-package-name
  917. %guix-version
  918. %guix-bug-report-address
  919. %guix-home-page-url))
  920. (define %config-variables
  921. ;; (guix config) variables corresponding to Guix configuration.
  922. (letrec-syntax ((variables (syntax-rules ()
  923. ((_)
  924. '())
  925. ((_ variable rest ...)
  926. (cons `(variable . ,variable)
  927. (variables rest ...))))))
  928. (variables %localstatedir %storedir %sysconfdir)))
  929. (define* (make-config.scm #:key gzip xz bzip2
  930. (package-name "GNU Guix")
  931. (package-version "0")
  932. (channel-metadata #f)
  933. (bug-report-address "bug-guix@gnu.org")
  934. (home-page-url "https://guix.gnu.org"))
  935. ;; Hack so that Geiser is not confused.
  936. (define defmod 'define-module)
  937. (scheme-file "config.scm"
  938. #~(;; The following expressions get spliced.
  939. (#$defmod (guix config)
  940. #:export (%guix-package-name
  941. %guix-version
  942. %guix-bug-report-address
  943. %guix-home-page-url
  944. %channel-metadata
  945. %system
  946. %store-directory
  947. %state-directory
  948. %store-database-directory
  949. %config-directory
  950. %gzip
  951. %bzip2
  952. %xz))
  953. (define %system
  954. #$(%current-system))
  955. #$@(map (match-lambda
  956. ((name . value)
  957. #~(define-public #$name #$value)))
  958. %config-variables)
  959. (define %store-directory
  960. (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
  961. %storedir))
  962. (define %state-directory
  963. ;; This must match `NIX_STATE_DIR' as defined in
  964. ;; `nix/local.mk'.
  965. (or (getenv "GUIX_STATE_DIRECTORY")
  966. (string-append %localstatedir "/guix")))
  967. (define %store-database-directory
  968. (or (getenv "GUIX_DATABASE_DIRECTORY")
  969. (string-append %state-directory "/db")))
  970. (define %config-directory
  971. ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as
  972. ;; defined in `nix/local.mk'.
  973. (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
  974. (string-append %sysconfdir "/guix")))
  975. (define %guix-package-name #$package-name)
  976. (define %guix-version #$package-version)
  977. (define %guix-bug-report-address #$bug-report-address)
  978. (define %guix-home-page-url #$home-page-url)
  979. (define %channel-metadata
  980. ;; Metadata for the 'guix' channel in use. This
  981. ;; information is used by (guix describe).
  982. '#$channel-metadata)
  983. (define %gzip
  984. #+(and gzip (file-append gzip "/bin/gzip")))
  985. (define %bzip2
  986. #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
  987. (define %xz
  988. #+(and xz (file-append xz "/bin/xz"))))
  989. ;; Guile 2.0 *requires* the 'define-module' to be at the
  990. ;; top-level or the 'toplevel-ref' in the resulting .go file are
  991. ;; made relative to a nonexistent anonymous module.
  992. #:splice? #t))
  993. ;;;
  994. ;;; Building.
  995. ;;;
  996. (define* (compiled-modules name module-tree module-files
  997. #:optional
  998. (dependencies '())
  999. (dependencies-compiled '())
  1000. #:key
  1001. (extensions '()) ;full-blown Guile packages
  1002. parallel?
  1003. guile-for-build)
  1004. "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list
  1005. like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory
  1006. containing MODULE-FILES and possibly other files as well."
  1007. ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix
  1008. ;; gexp).
  1009. (define build
  1010. (with-imported-modules (source-module-closure
  1011. '((guix build compile)
  1012. (guix build utils)))
  1013. #~(begin
  1014. (use-modules (srfi srfi-26)
  1015. (ice-9 match)
  1016. (ice-9 format)
  1017. (ice-9 threads)
  1018. (guix build compile)
  1019. (guix build utils))
  1020. (define (regular? file)
  1021. (not (member file '("." ".."))))
  1022. (define (report-load file total completed)
  1023. (display #\cr)
  1024. (format #t
  1025. "[~3@a/~3@a] loading...\t~5,1f% of ~d files"
  1026. ;; Note: Multiply TOTAL by two to account for the
  1027. ;; compilation phase that follows.
  1028. completed (* total 2)
  1029. (* 100. (/ completed total)) total)
  1030. (force-output))
  1031. (define (report-compilation file total completed)
  1032. (display #\cr)
  1033. (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files"
  1034. ;; Add TOTAL to account for the load phase that came
  1035. ;; before.
  1036. (+ total completed) (* total 2)
  1037. (* 100. (/ completed total)) total)
  1038. (force-output))
  1039. (define (process-directory directory files output)
  1040. ;; Hide compilation warnings.
  1041. (parameterize ((current-warning-port (%make-void-port "w")))
  1042. (compile-files directory #$output files
  1043. #:workers (parallel-job-count)
  1044. #:report-load report-load
  1045. #:report-compilation report-compilation)))
  1046. (setvbuf (current-output-port) 'line)
  1047. (setvbuf (current-error-port) 'line)
  1048. (set! %load-path (cons #+module-tree %load-path))
  1049. (set! %load-path
  1050. (append '#+dependencies
  1051. (map (lambda (extension)
  1052. (string-append extension "/share/guile/site/"
  1053. (effective-version)))
  1054. '#+extensions)
  1055. %load-path))
  1056. (set! %load-compiled-path
  1057. (append '#+dependencies-compiled
  1058. (map (lambda (extension)
  1059. (string-append extension "/lib/guile/"
  1060. (effective-version)
  1061. "/site-ccache"))
  1062. '#+extensions)
  1063. %load-compiled-path))
  1064. ;; Load the compiler modules upfront.
  1065. (compile #f)
  1066. (mkdir #$output)
  1067. (chdir #+module-tree)
  1068. (process-directory "." '#+module-files #$output)
  1069. (newline))))
  1070. (computed-file name build
  1071. #:guile guile-for-build
  1072. #:options
  1073. `(#:local-build? #f ;allow substitutes
  1074. ;; Don't annoy people about _IONBF deprecation.
  1075. ;; Initialize 'terminal-width' in (system repl debug)
  1076. ;; to a large-enough value to make backtrace more
  1077. ;; verbose.
  1078. #:env-vars (("GUILE_WARN_DEPRECATED" . "no")
  1079. ("COLUMNS" . "200")))))
  1080. ;;;
  1081. ;;; Building.
  1082. ;;;
  1083. (define* (guix-derivation source version
  1084. #:optional (guile-version (effective-version))
  1085. #:key (pull-version 0)
  1086. channel-metadata)
  1087. "Return, as a monadic value, the derivation to build the Guix from SOURCE
  1088. for GUILE-VERSION. Use VERSION as the version string. Use CHANNEL-METADATA
  1089. as the channel metadata sexp to include in (guix config).
  1090. PULL-VERSION specifies the version of the 'guix pull' protocol. Return #f if
  1091. this PULL-VERSION value is not supported."
  1092. (define (shorten version)
  1093. (if (and (string-every char-set:hex-digit version)
  1094. (> (string-length version) 9))
  1095. (string-take version 9) ;Git commit
  1096. version))
  1097. (define guile
  1098. ;; When PULL-VERSION >= 1, produce a self-contained Guix and use the
  1099. ;; current Guile unconditionally.
  1100. (specification->package "guile"))
  1101. (when (and (< pull-version 1)
  1102. (not (string=? (package-version guile) guile-version)))
  1103. ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and
  1104. ;; can be any version. When that happens and Guile is not current (e.g.,
  1105. ;; it's Guile 2.0), just bail out.
  1106. (raise (condition
  1107. (&message
  1108. (message "Guix is too old and cannot be upgraded")))))
  1109. (mbegin %store-monad
  1110. (set-guile-for-build guile)
  1111. (let ((guix (compiled-guix source
  1112. #:version version
  1113. #:channel-metadata channel-metadata
  1114. #:name (string-append "guix-"
  1115. (shorten version))
  1116. #:pull-version pull-version
  1117. #:guile-version (if (>= pull-version 1)
  1118. "3.0" guile-version)
  1119. #:guile-for-build guile)))
  1120. (if guix
  1121. (lower-object guix)
  1122. (return #f)))))