self.scm 55 KB

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