self.scm 54 KB

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