self.scm 54 KB

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