self.scm 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  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'. Going beyond can
  363. ;; lead libgc 8.0.4 to abort with:
  364. ;; mmap(PROT_NONE) failed
  365. (min (parallel-job-count) 4))
  366. (mkdir #$output)
  367. (copy-recursively #$documentation "."
  368. #:log (%make-void-port "w"))
  369. (for-each
  370. (lambda (file)
  371. (copy-file file (basename file)))
  372. (find-files #$documentation-po ".*.po$"))
  373. (setenv "GUIX_LOCPATH"
  374. #+(file-append glibc-utf8-locales "/lib/locale"))
  375. (setenv "PATH" #+(file-append gettext "/bin"))
  376. (setenv "LC_ALL" "en_US.UTF-8")
  377. (setlocale LC_ALL "en_US.UTF-8")
  378. (n-par-for-each parallel-jobs
  379. (match-lambda
  380. ((language . po)
  381. (translate-texi "guix" po language
  382. #:extras '("contributing"))))
  383. (available-translations "." "guix-manual"))
  384. (n-par-for-each parallel-jobs
  385. (match-lambda
  386. ((language . po)
  387. (translate-texi "guix-cookbook" po language)))
  388. (available-translations "." "guix-cookbook"))
  389. (for-each (lambda (file)
  390. (install-file file #$output))
  391. (append
  392. (find-files "." "contributing\\..*\\.texi$")
  393. (find-files "." "guix\\..*\\.texi$")
  394. (find-files "." "guix-cookbook\\..*\\.texi$"))))))
  395. (computed-file "guix-translated-texinfo" build))
  396. (define (info-manual source)
  397. "Return the Info manual built from SOURCE."
  398. (define texinfo
  399. (module-ref (resolve-interface '(gnu packages texinfo))
  400. 'texinfo))
  401. (define graphviz
  402. (module-ref (resolve-interface '(gnu packages graphviz))
  403. 'graphviz))
  404. (define glibc-utf8-locales
  405. (module-ref (resolve-interface '(gnu packages base))
  406. 'glibc-utf8-locales))
  407. (define documentation
  408. (file-append* source "doc"))
  409. (define examples
  410. (file-append* source "gnu/system/examples"))
  411. (define build
  412. (with-imported-modules '((guix build utils))
  413. #~(begin
  414. (use-modules (guix build utils)
  415. (ice-9 match))
  416. (mkdir #$output)
  417. ;; Create 'version.texi'.
  418. ;; XXX: Can we use a more meaningful version string yet one that
  419. ;; doesn't change at each commit?
  420. (call-with-output-file "version.texi"
  421. (lambda (port)
  422. (let ((version "0.0-git"))
  423. (format port "
  424. @set UPDATED 1 January 1970
  425. @set UPDATED-MONTH January 1970
  426. @set EDITION ~a
  427. @set VERSION ~a\n" version version))))
  428. ;; Copy configuration templates that the manual includes.
  429. (for-each (lambda (template)
  430. (copy-file template
  431. (string-append
  432. "os-config-"
  433. (basename template ".tmpl")
  434. ".texi")))
  435. (find-files #$examples "\\.tmpl$"))
  436. ;; Build graphs.
  437. (mkdir-p (string-append #$output "/images"))
  438. (for-each (lambda (dot-file)
  439. (invoke #+(file-append graphviz "/bin/dot")
  440. "-Tpng" "-Gratio=.9" "-Gnodesep=.005"
  441. "-Granksep=.00005" "-Nfontsize=9"
  442. "-Nheight=.1" "-Nwidth=.1"
  443. "-o" (string-append #$output "/images/"
  444. (basename dot-file ".dot")
  445. ".png")
  446. dot-file))
  447. (find-files (string-append #$documentation "/images")
  448. "\\.dot$"))
  449. ;; Copy other PNGs.
  450. (for-each (lambda (png-file)
  451. (install-file png-file
  452. (string-append #$output "/images")))
  453. (find-files (string-append #$documentation "/images")
  454. "\\.png$"))
  455. ;; Finally build the manual. Copy it the Texinfo files to $PWD and
  456. ;; add a symlink to the 'images' directory so that 'makeinfo' can
  457. ;; see those images and produce image references in the Info output.
  458. (copy-recursively #$documentation "."
  459. #:log (%make-void-port "w"))
  460. (copy-recursively #+(translate-texi-manuals source) "."
  461. #:log (%make-void-port "w"))
  462. (delete-file-recursively "images")
  463. (symlink (string-append #$output "/images") "images")
  464. ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo.
  465. (setenv "GUIX_LOCPATH"
  466. #+(file-append glibc-utf8-locales "/lib/locale"))
  467. (for-each (lambda (texi)
  468. (match (string-split (basename texi) #\.)
  469. (("guix" language "texi")
  470. ;; Create 'version-LL.texi'.
  471. (symlink "version.texi"
  472. (string-append "version-" language
  473. ".texi")))
  474. (_ #f))
  475. (invoke #+(file-append texinfo "/bin/makeinfo")
  476. texi "-I" #$documentation
  477. "-I" "."
  478. "-o" (string-append #$output "/"
  479. (basename texi ".texi")
  480. ".info")))
  481. (cons "guix.texi"
  482. (append (find-files "."
  483. "^guix\\.[a-z]{2}(_[A-Z]{2})?\\.texi$")
  484. (find-files "."
  485. "^guix-cookbook.*\\.texi$"))))
  486. ;; Compress Info files.
  487. (setenv "PATH"
  488. #+(file-append (specification->package "gzip") "/bin"))
  489. (for-each (lambda (file)
  490. (invoke "gzip" "-9n" file))
  491. (find-files #$output "\\.info(-[0-9]+)?$")))))
  492. (computed-file "guix-manual" build))
  493. (define-syntax-rule (prevent-inlining! identifier ...)
  494. (begin (set! identifier identifier) ...))
  495. ;; XXX: These procedures are actually used by 'doc/build.scm'. Protect them
  496. ;; from inlining on Guile 3.
  497. (prevent-inlining! file-append* translate-texi-manuals info-manual)
  498. (define* (guile-module-union things #:key (name "guix-module-union"))
  499. "Return the union of the subset of THINGS (packages, computed files, etc.)
  500. that provide Guile modules."
  501. (define build
  502. (with-imported-modules '((guix build union))
  503. #~(begin
  504. (use-modules (guix build union))
  505. (define (modules directory)
  506. (string-append directory "/share/guile/site"))
  507. (define (objects directory)
  508. (string-append directory "/lib/guile"))
  509. (union-build #$output
  510. (filter (lambda (directory)
  511. (or (file-exists? (modules directory))
  512. (file-exists? (objects directory))))
  513. '#$things)
  514. #:log-port (%make-void-port "w")))))
  515. (computed-file name build))
  516. (define (quiet-guile guile)
  517. "Return a wrapper that does the same as the 'guile' executable of GUILE,
  518. except that it does not complain about locales and falls back to 'en_US.utf8'
  519. instead of 'C'."
  520. (define gcc
  521. (specification->package "gcc-toolchain"))
  522. (define source
  523. (search-path %load-path
  524. "gnu/packages/aux-files/guile-launcher.c"))
  525. (define effective
  526. (version-major+minor (package-version guile)))
  527. (define build
  528. ;; XXX: Reuse <c-compiler> from (guix scripts pack) instead?
  529. (with-imported-modules '((guix build utils))
  530. #~(begin
  531. (use-modules (guix build utils)
  532. (srfi srfi-26))
  533. (mkdir-p (string-append #$output "/bin"))
  534. (setenv "PATH" #$(file-append gcc "/bin"))
  535. (setenv "C_INCLUDE_PATH"
  536. (string-join
  537. (map (cut string-append <> "/include")
  538. '#$(match (bag-transitive-build-inputs
  539. (package->bag guile))
  540. (((labels packages . _) ...)
  541. (filter package? packages))))
  542. ":"))
  543. (setenv "LIBRARY_PATH" #$(file-append gcc "/lib"))
  544. (invoke "gcc" #$(local-file source) "-Wall" "-g0" "-O2"
  545. "-I" #$(file-append guile "/include/guile/" effective)
  546. "-L" #$(file-append guile "/lib")
  547. #$(string-append "-lguile-" effective)
  548. "-o" (string-append #$output "/bin/guile")))))
  549. (computed-file "guile-wrapper" build))
  550. (define* (guix-command modules
  551. #:key source (dependencies '())
  552. guile (guile-version (effective-version)))
  553. "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its
  554. load path."
  555. (define glibc-utf8-locales
  556. (module-ref (resolve-interface '(gnu packages base))
  557. 'glibc-utf8-locales))
  558. (define module-directory
  559. ;; To minimize the number of 'stat' calls needed to locate a module,
  560. ;; create the union of all the module directories.
  561. (guile-module-union (cons modules dependencies)))
  562. (program-file "guix-command"
  563. #~(begin
  564. ;; Remove the empty extension from the search path.
  565. (set! %load-extensions '(".scm"))
  566. (set! %load-path
  567. (append (list (string-append #$module-directory
  568. "/share/guile/site/"
  569. (effective-version))
  570. (string-append #$guile "/share/guile/"
  571. (effective-version)))
  572. %load-path))
  573. (set! %load-compiled-path
  574. (append (list (string-append #$module-directory
  575. "/lib/guile/"
  576. (effective-version)
  577. "/site-ccache")
  578. (string-append #$guile "/lib/guile/"
  579. (effective-version)
  580. "/ccache"))
  581. %load-compiled-path))
  582. ;; To maximize the chances that locales are set up right
  583. ;; out-of-the-box, bundle "common" UTF-8 locales.
  584. (let ((locpath (getenv "GUIX_LOCPATH")))
  585. (setenv "GUIX_LOCPATH"
  586. (string-append (if locpath
  587. (string-append locpath ":")
  588. "")
  589. #$(file-append glibc-utf8-locales
  590. "/lib/locale"))))
  591. (let ((guix-main (module-ref (resolve-interface '(guix ui))
  592. 'guix-main)))
  593. #$(if source
  594. #~(begin
  595. (bindtextdomain "guix"
  596. #$(locale-data source "guix"))
  597. (bindtextdomain "guix-packages"
  598. #$(locale-data source
  599. "guix-packages"
  600. "packages")))
  601. #t)
  602. ;; XXX: It would be more convenient to change it to:
  603. ;; (exit (apply guix-main (command-line)))
  604. (apply guix-main (command-line))))
  605. ;; Use a 'guile' variant that doesn't complain about locales.
  606. #:guile (quiet-guile guile)))
  607. (define (miscellaneous-files source)
  608. "Return data files taken from SOURCE."
  609. (file-mapping "guix-misc"
  610. `(("etc/bash_completion.d/guix"
  611. ,(file-append* source "/etc/completion/bash/guix"))
  612. ("etc/bash_completion.d/guix-daemon"
  613. ,(file-append* source "/etc/completion/bash/guix-daemon"))
  614. ("share/zsh/site-functions/_guix"
  615. ,(file-append* source "/etc/completion/zsh/_guix"))
  616. ("share/fish/vendor_completions.d/guix.fish"
  617. ,(file-append* source "/etc/completion/fish/guix.fish"))
  618. ("share/guix/berlin.guix.gnu.org.pub"
  619. ,(file-append* source
  620. "/etc/substitutes/berlin.guix.gnu.org.pub"))
  621. ("share/guix/ci.guix.gnu.org.pub" ;alias
  622. ,(file-append* source "/etc/substitutes/berlin.guix.gnu.org.pub"))
  623. ("share/guix/ci.guix.info.pub" ;alias
  624. ,(file-append* source "/etc/substitutes/berlin.guix.gnu.org.pub")))))
  625. (define* (whole-package name modules dependencies
  626. #:key
  627. (guile-version (effective-version))
  628. info daemon miscellany
  629. guile
  630. (command (guix-command modules
  631. #:dependencies dependencies
  632. #:guile guile
  633. #:guile-version guile-version)))
  634. "Return the whole Guix package NAME that uses MODULES, a derivation of all
  635. the modules (under share/guile/site and lib/guile), and DEPENDENCIES, a list
  636. of packages depended on. COMMAND is the 'guix' program to use; INFO is the
  637. Info manual."
  638. (define (wrap daemon)
  639. (program-file "guix-daemon"
  640. #~(begin
  641. ;; Refer to the right 'guix' command for 'guix
  642. ;; substitute' & co.
  643. (setenv "GUIX" #$command)
  644. ;; Honor the user's settings rather than those hardcoded
  645. ;; in the 'guix-daemon' package.
  646. (unless (getenv "GUIX_STATE_DIRECTORY")
  647. (setenv "GUIX_STATE_DIRECTORY"
  648. #$(string-append %localstatedir "/guix")))
  649. (unless (getenv "GUIX_CONFIGURATION_DIRECTORY")
  650. (setenv "GUIX_CONFIGURATION_DIRECTORY"
  651. #$(string-append %sysconfdir "/guix")))
  652. (unless (getenv "NIX_STORE_DIR")
  653. (setenv "NIX_STORE_DIR" #$%storedir))
  654. (apply execl #$(file-append daemon "/bin/guix-daemon")
  655. "guix-daemon" (cdr (command-line))))))
  656. (computed-file name
  657. (with-imported-modules '((guix build utils))
  658. #~(begin
  659. (use-modules (guix build utils))
  660. (define daemon
  661. #$(and daemon (wrap daemon)))
  662. (mkdir-p (string-append #$output "/bin"))
  663. (symlink #$command
  664. (string-append #$output "/bin/guix"))
  665. (when daemon
  666. (symlink daemon
  667. (string-append #$output "/bin/guix-daemon")))
  668. (let ((share (string-append #$output "/share"))
  669. (lib (string-append #$output "/lib"))
  670. (info #$info))
  671. (mkdir-p share)
  672. (symlink #$(file-append modules "/share/guile")
  673. (string-append share "/guile"))
  674. (when info
  675. (symlink #$info (string-append share "/info")))
  676. (mkdir-p lib)
  677. (symlink #$(file-append modules "/lib/guile")
  678. (string-append lib "/guile")))
  679. (when #$miscellany
  680. (copy-recursively #$miscellany #$output
  681. #:log (%make-void-port "w")))))))
  682. (define (transitive-package-dependencies package)
  683. "Return the list of packages propagated by PACKAGE, including PACKAGE
  684. itself."
  685. (match (package-transitive-propagated-inputs package)
  686. (((labels packages _ ...) ...)
  687. (cons package packages))))
  688. (define* (compiled-guix source #:key
  689. (version %guix-version)
  690. (channel-metadata #f)
  691. (pull-version 1)
  692. (name (string-append "guix-" version))
  693. (guile-version (effective-version))
  694. (guile-for-build (default-guile))
  695. (gzip (specification->package "gzip"))
  696. (bzip2 (specification->package "bzip2"))
  697. (xz (specification->package "xz"))
  698. (guix (specification->package "guix")))
  699. "Return a file-like object that contains a compiled Guix."
  700. (define guile-avahi
  701. (specification->package "guile-avahi"))
  702. (define guile-json
  703. (specification->package "guile-json"))
  704. (define guile-ssh
  705. (specification->package "guile-ssh"))
  706. (define guile-lib
  707. (specification->package "guile-lib"))
  708. (define guile-git
  709. (specification->package "guile-git"))
  710. (define guile-sqlite3
  711. (specification->package "guile-sqlite3"))
  712. (define guile-zlib
  713. (specification->package "guile-zlib"))
  714. (define guile-lzlib
  715. (specification->package "guile-lzlib"))
  716. (define guile-zstd
  717. (specification->package "guile-zstd"))
  718. (define guile-gcrypt
  719. (specification->package "guile-gcrypt"))
  720. (define guile-semver
  721. (specification->package "guile-semver"))
  722. (define gnutls
  723. (specification->package "gnutls"))
  724. (define disarchive
  725. (specification->package "disarchive"))
  726. (define dependencies
  727. (append-map transitive-package-dependencies
  728. (list guile-gcrypt gnutls guile-git guile-avahi
  729. guile-json guile-semver guile-ssh guile-sqlite3
  730. guile-lib guile-zlib guile-lzlib guile-zstd)))
  731. (define *core-modules*
  732. (scheme-node "guix-core"
  733. '((guix)
  734. (guix monad-repl)
  735. (guix packages)
  736. (guix download)
  737. (guix discovery)
  738. (guix profiles)
  739. (guix build-system gnu)
  740. (guix build-system trivial)
  741. (guix build profiles)
  742. (guix build gnu-build-system))
  743. ;; Provide a dummy (guix config) with the default version
  744. ;; number, storedir, etc. This is so that "guix-core" is the
  745. ;; same across all installations and doesn't need to be
  746. ;; rebuilt when the version changes, which in turn means we
  747. ;; can have substitutes for it.
  748. #:extra-modules
  749. `(((guix config) => ,(make-config.scm)))
  750. ;; (guix man-db) is needed at build-time by (guix profiles)
  751. ;; but we don't need to compile it; not compiling it allows
  752. ;; us to avoid an extra dependency on guile-gdbm-ffi.
  753. #:extra-files
  754. `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm"))
  755. ("guix/build/po.scm" ,(local-file "../guix/build/po.scm"))
  756. ("guix/store/schema.sql"
  757. ,(local-file "../guix/store/schema.sql")))
  758. #:extensions (list guile-gcrypt
  759. guile-json) ;for (guix swh)
  760. #:guile-for-build guile-for-build))
  761. (define *extra-modules*
  762. (scheme-node "guix-extra"
  763. (filter-map (match-lambda
  764. (('guix 'scripts _ ..1) #f)
  765. (('guix 'man-db) #f)
  766. (('guix 'tests _ ...) #f)
  767. (name name))
  768. (scheme-modules* source "guix"))
  769. (list *core-modules*)
  770. #:extra-files
  771. `(("guix/graph.js" ,(local-file "../guix/graph.js"))
  772. ("guix/d3.v3.js" ,(local-file "../guix/d3.v3.js")))
  773. #:extensions dependencies
  774. #:guile-for-build guile-for-build))
  775. (define *core-package-modules*
  776. (scheme-node "guix-packages-base"
  777. `((gnu packages)
  778. (gnu packages base))
  779. (list *core-modules* *extra-modules*)
  780. #:extensions dependencies
  781. ;; Add all the non-Scheme files here. We must do it here so
  782. ;; that 'search-patches' & co. can find them. Ideally we'd
  783. ;; keep them next to the .scm files that use them but it's
  784. ;; difficult to do (XXX).
  785. #:extra-files
  786. (file-imports source "gnu/packages"
  787. (lambda (file stat)
  788. (and (eq? 'regular (stat:type stat))
  789. (not (string-suffix? ".scm" file))
  790. (not (string-suffix? ".go" file))
  791. (not (string-prefix? ".#" file))
  792. (not (string-suffix? "~" file)))))
  793. #:guile-for-build guile-for-build))
  794. (define *package-modules*
  795. (scheme-node "guix-packages"
  796. (scheme-modules* source "gnu/packages")
  797. (list *core-modules* *extra-modules* *core-package-modules*)
  798. #:extensions dependencies
  799. #:guile-for-build guile-for-build))
  800. (define *system-modules*
  801. (scheme-node "guix-system"
  802. `((gnu system)
  803. (gnu services)
  804. ,@(scheme-modules* source "gnu/bootloader")
  805. ,@(scheme-modules* source "gnu/system")
  806. ,@(scheme-modules* source "gnu/services")
  807. ,@(scheme-modules* source "gnu/machine"))
  808. (list *core-package-modules* *package-modules*
  809. *extra-modules* *core-modules*)
  810. #:extensions dependencies
  811. #:extra-files
  812. (append (file-imports source "gnu/system/examples"
  813. (const #t))
  814. ;; All the installer code is on the build-side.
  815. (file-imports source "gnu/installer/"
  816. (const #t))
  817. ;; Build-side code that we don't build. Some of
  818. ;; these depend on guile-rsvg, the Shepherd, etc.
  819. (file-imports source "gnu/build" (const #t)))
  820. #:guile-for-build
  821. guile-for-build))
  822. (define *cli-modules*
  823. (scheme-node "guix-cli"
  824. (append (scheme-modules* source "/guix/scripts")
  825. `((gnu ci)))
  826. (list *core-modules* *extra-modules*
  827. *core-package-modules* *package-modules*
  828. *system-modules*)
  829. #:extensions dependencies
  830. #:guile-for-build guile-for-build))
  831. (define *system-test-modules*
  832. ;; Ship these modules mostly so (gnu ci) can discover them.
  833. (scheme-node "guix-system-tests"
  834. `((gnu tests)
  835. ,@(scheme-modules* source "gnu/tests"))
  836. (list *core-package-modules* *package-modules*
  837. *extra-modules* *system-modules* *core-modules*
  838. *cli-modules*) ;for (guix scripts pack), etc.
  839. #:extensions dependencies
  840. #:guile-for-build guile-for-build))
  841. (define *config*
  842. (scheme-node "guix-config"
  843. '()
  844. #:extra-modules
  845. `(((guix config)
  846. => ,(make-config.scm #:gzip gzip
  847. #:bzip2 bzip2
  848. #:xz xz
  849. #:package-name
  850. %guix-package-name
  851. #:package-version
  852. version
  853. #:channel-metadata
  854. channel-metadata
  855. #:bug-report-address
  856. %guix-bug-report-address
  857. #:home-page-url
  858. %guix-home-page-url)))
  859. #:guile-for-build guile-for-build))
  860. (define (built-modules node-subset)
  861. (directory-union (string-append name "-modules")
  862. (append-map node-subset
  863. ;; Note: *CONFIG* comes first so that it
  864. ;; overrides the (guix config) module that
  865. ;; comes with *CORE-MODULES*.
  866. (list *config*
  867. *cli-modules*
  868. *system-test-modules*
  869. *system-modules*
  870. *package-modules*
  871. *core-package-modules*
  872. *extra-modules*
  873. *core-modules*))
  874. ;; Silently choose the first entry upon collision so that
  875. ;; we choose *CONFIG*.
  876. #:resolve-collision 'first
  877. ;; When we do (add-to-store "utils.scm"), "utils.scm" must
  878. ;; be a regular file, not a symlink. Thus, arrange so that
  879. ;; regular files appear as regular files in the final
  880. ;; output.
  881. #:copy? #t
  882. #:quiet? #t))
  883. ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
  884. ;; Version 1 is when we return the full package.
  885. (cond ((= 1 pull-version)
  886. ;; The whole package, with a standard file hierarchy.
  887. (let* ((modules (built-modules (compose list node-source+compiled)))
  888. (command (guix-command modules
  889. #:source source
  890. #:dependencies
  891. (cons disarchive dependencies)
  892. #:guile guile-for-build
  893. #:guile-version guile-version)))
  894. (whole-package name modules dependencies
  895. #:command command
  896. #:guile guile-for-build
  897. ;; Include 'guix-daemon'. XXX: Here we inject an
  898. ;; older snapshot of guix-daemon, but that's a good
  899. ;; enough approximation for now.
  900. #:daemon (module-ref (resolve-interface
  901. '(gnu packages
  902. package-management))
  903. 'guix-daemon)
  904. #:info (info-manual source)
  905. #:miscellany (miscellaneous-files source)
  906. #:guile-version guile-version)))
  907. ((= 0 pull-version)
  908. ;; Legacy 'guix pull': return the .scm and .go files as one
  909. ;; directory.
  910. (built-modules (lambda (node)
  911. (list (node-source node)
  912. (node-compiled node)))))
  913. (else
  914. ;; Unsupported 'guix pull' version.
  915. #f)))
  916. ;;;
  917. ;;; Generating (guix config).
  918. ;;;
  919. (define %persona-variables
  920. ;; (guix config) variables that define Guix's persona.
  921. '(%guix-package-name
  922. %guix-version
  923. %guix-bug-report-address
  924. %guix-home-page-url))
  925. (define %config-variables
  926. ;; (guix config) variables corresponding to Guix configuration.
  927. (letrec-syntax ((variables (syntax-rules ()
  928. ((_)
  929. '())
  930. ((_ variable rest ...)
  931. (cons `(variable . ,variable)
  932. (variables rest ...))))))
  933. (variables %localstatedir %storedir %sysconfdir)))
  934. (define* (make-config.scm #:key gzip xz bzip2
  935. (package-name "GNU Guix")
  936. (package-version "0")
  937. (channel-metadata #f)
  938. (bug-report-address "bug-guix@gnu.org")
  939. (home-page-url "https://guix.gnu.org"))
  940. ;; Hack so that Geiser is not confused.
  941. (define defmod 'define-module)
  942. (scheme-file "config.scm"
  943. #~(;; The following expressions get spliced.
  944. (#$defmod (guix config)
  945. #:export (%guix-package-name
  946. %guix-version
  947. %guix-bug-report-address
  948. %guix-home-page-url
  949. %channel-metadata
  950. %system
  951. %store-directory
  952. %state-directory
  953. %store-database-directory
  954. %config-directory
  955. %gzip
  956. %bzip2
  957. %xz))
  958. (define %system
  959. #$(%current-system))
  960. #$@(map (match-lambda
  961. ((name . value)
  962. #~(define-public #$name #$value)))
  963. %config-variables)
  964. (define %store-directory
  965. (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
  966. %storedir))
  967. (define %state-directory
  968. ;; This must match `NIX_STATE_DIR' as defined in
  969. ;; `nix/local.mk'.
  970. (or (getenv "GUIX_STATE_DIRECTORY")
  971. (string-append %localstatedir "/guix")))
  972. (define %store-database-directory
  973. (or (getenv "GUIX_DATABASE_DIRECTORY")
  974. (string-append %state-directory "/db")))
  975. (define %config-directory
  976. ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as
  977. ;; defined in `nix/local.mk'.
  978. (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
  979. (string-append %sysconfdir "/guix")))
  980. (define %guix-package-name #$package-name)
  981. (define %guix-version #$package-version)
  982. (define %guix-bug-report-address #$bug-report-address)
  983. (define %guix-home-page-url #$home-page-url)
  984. (define %channel-metadata
  985. ;; Metadata for the 'guix' channel in use. This
  986. ;; information is used by (guix describe).
  987. '#$channel-metadata)
  988. (define %gzip
  989. #+(and gzip (file-append gzip "/bin/gzip")))
  990. (define %bzip2
  991. #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
  992. (define %xz
  993. #+(and xz (file-append xz "/bin/xz"))))
  994. ;; Guile 2.0 *requires* the 'define-module' to be at the
  995. ;; top-level or the 'toplevel-ref' in the resulting .go file are
  996. ;; made relative to a nonexistent anonymous module.
  997. #:splice? #t))
  998. ;;;
  999. ;;; Building.
  1000. ;;;
  1001. (define* (compiled-modules name module-tree module-files
  1002. #:optional
  1003. (dependencies '())
  1004. (dependencies-compiled '())
  1005. #:key
  1006. (extensions '()) ;full-blown Guile packages
  1007. parallel?
  1008. guile-for-build)
  1009. "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list
  1010. like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory
  1011. containing MODULE-FILES and possibly other files as well."
  1012. ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix
  1013. ;; gexp).
  1014. (define build
  1015. (with-imported-modules (source-module-closure
  1016. '((guix build compile)
  1017. (guix build utils)))
  1018. #~(begin
  1019. (use-modules (srfi srfi-26)
  1020. (ice-9 match)
  1021. (ice-9 format)
  1022. (ice-9 threads)
  1023. (guix build compile)
  1024. (guix build utils))
  1025. (define (regular? file)
  1026. (not (member file '("." ".."))))
  1027. (define (report-load file total completed)
  1028. (display #\cr)
  1029. (format #t
  1030. "[~3@a/~3@a] loading...\t~5,1f% of ~d files"
  1031. ;; Note: Multiply TOTAL by two to account for the
  1032. ;; compilation phase that follows.
  1033. completed (* total 2)
  1034. (* 100. (/ completed total)) total)
  1035. (force-output))
  1036. (define (report-compilation file total completed)
  1037. (display #\cr)
  1038. (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files"
  1039. ;; Add TOTAL to account for the load phase that came
  1040. ;; before.
  1041. (+ total completed) (* total 2)
  1042. (* 100. (/ completed total)) total)
  1043. (force-output))
  1044. (define (process-directory directory files output)
  1045. ;; Hide compilation warnings.
  1046. (parameterize ((current-warning-port (%make-void-port "w")))
  1047. (compile-files directory #$output files
  1048. #:workers (parallel-job-count)
  1049. #:report-load report-load
  1050. #:report-compilation report-compilation)))
  1051. (setvbuf (current-output-port) 'line)
  1052. (setvbuf (current-error-port) 'line)
  1053. (set! %load-path (cons #+module-tree %load-path))
  1054. (set! %load-path
  1055. (append '#+dependencies
  1056. (map (lambda (extension)
  1057. (string-append extension "/share/guile/site/"
  1058. (effective-version)))
  1059. '#+extensions)
  1060. %load-path))
  1061. (set! %load-compiled-path
  1062. (append '#+dependencies-compiled
  1063. (map (lambda (extension)
  1064. (string-append extension "/lib/guile/"
  1065. (effective-version)
  1066. "/site-ccache"))
  1067. '#+extensions)
  1068. %load-compiled-path))
  1069. ;; Load the compiler modules upfront.
  1070. (compile #f)
  1071. (mkdir #$output)
  1072. (chdir #+module-tree)
  1073. (process-directory "." '#+module-files #$output)
  1074. (newline))))
  1075. (computed-file name build
  1076. #:guile guile-for-build
  1077. #:options
  1078. `(#:local-build? #f ;allow substitutes
  1079. ;; Don't annoy people about _IONBF deprecation.
  1080. ;; Initialize 'terminal-width' in (system repl debug)
  1081. ;; to a large-enough value to make backtrace more
  1082. ;; verbose.
  1083. #:env-vars (("GUILE_WARN_DEPRECATED" . "no")
  1084. ("COLUMNS" . "200")))))
  1085. ;;;
  1086. ;;; Building.
  1087. ;;;
  1088. (define* (guix-derivation source version
  1089. #:optional (guile-version (effective-version))
  1090. #:key (pull-version 0)
  1091. channel-metadata)
  1092. "Return, as a monadic value, the derivation to build the Guix from SOURCE
  1093. for GUILE-VERSION. Use VERSION as the version string. Use CHANNEL-METADATA
  1094. as the channel metadata sexp to include in (guix config).
  1095. PULL-VERSION specifies the version of the 'guix pull' protocol. Return #f if
  1096. this PULL-VERSION value is not supported."
  1097. (define (shorten version)
  1098. (if (and (string-every char-set:hex-digit version)
  1099. (> (string-length version) 9))
  1100. (string-take version 9) ;Git commit
  1101. version))
  1102. (define guile
  1103. ;; When PULL-VERSION >= 1, produce a self-contained Guix and use the
  1104. ;; current Guile unconditionally.
  1105. (specification->package "guile"))
  1106. (when (and (< pull-version 1)
  1107. (not (string=? (package-version guile) guile-version)))
  1108. ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and
  1109. ;; can be any version. When that happens and Guile is not current (e.g.,
  1110. ;; it's Guile 2.0), just bail out.
  1111. (raise (condition
  1112. (&message
  1113. (message "Guix is too old and cannot be upgraded")))))
  1114. (mbegin %store-monad
  1115. (set-guile-for-build guile)
  1116. (let ((guix (compiled-guix source
  1117. #:version version
  1118. #:channel-metadata channel-metadata
  1119. #:name (string-append "guix-"
  1120. (shorten version))
  1121. #:pull-version pull-version
  1122. #:guile-version (if (>= pull-version 1)
  1123. "3.0" guile-version)
  1124. #:guile-for-build guile)))
  1125. (if guix
  1126. (lower-object guix)
  1127. (return #f)))))