guix-cookbook.texi 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998
  1. \input texinfo
  2. @c -*-texinfo-*-
  3. @c %**start of header
  4. @setfilename guix-cookbook.info
  5. @documentencoding UTF-8
  6. @settitle GNU Guix Cookbook
  7. @c %**end of header
  8. @copying
  9. Copyright @copyright{} 2019 Ricardo Wurmus@*
  10. Copyright @copyright{} 2019 Efraim Flashner@*
  11. Copyright @copyright{} 2019 Pierre Neidhardt@*
  12. Copyright @copyright{} 2020 Oleg Pykhalov@*
  13. Copyright @copyright{} 2020 Matthew Brooks@*
  14. Copyright @copyright{} 2020 Marcin Karpezo@*
  15. Copyright @copyright{} 2020 Brice Waegeneire@*
  16. Copyright @copyright{} 2020 André Batista@*
  17. Copyright @copyright{} 2020 Christine Lemmer-Webber@*
  18. Copyright @copyright{} 2021 Joshua Branson@*
  19. Permission is granted to copy, distribute and/or modify this document
  20. under the terms of the GNU Free Documentation License, Version 1.3 or
  21. any later version published by the Free Software Foundation; with no
  22. Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
  23. copy of the license is included in the section entitled ``GNU Free
  24. Documentation License''.
  25. @end copying
  26. @dircategory System administration
  27. @direntry
  28. * Guix cookbook: (guix-cookbook). Tutorials and examples for GNU Guix.
  29. @end direntry
  30. @titlepage
  31. @title GNU Guix Cookbook
  32. @subtitle Tutorials and examples for using the GNU Guix Functional Package Manager
  33. @author The GNU Guix Developers
  34. @page
  35. @vskip 0pt plus 1filll
  36. @insertcopying
  37. @end titlepage
  38. @contents
  39. @c *********************************************************************
  40. @node Top
  41. @top GNU Guix Cookbook
  42. This document presents tutorials and detailed examples for GNU@tie{}Guix, a
  43. functional package management tool written for the GNU system. Please
  44. @pxref{Top,,, guix, GNU Guix reference manual} for details about the system,
  45. its API, and related concepts.
  46. @c TRANSLATORS: You can replace the following paragraph with information on
  47. @c how to join your own translation team and how to report issues with the
  48. @c translation.
  49. This manual is also available in French (@pxref{Top,,, guix-cookbook.fr,
  50. Livre de recettes de GNU Guix}) and German (@pxref{Top,,,
  51. guix-cookbook.de, GNU-Guix-Kochbuch}). If you would like to translate
  52. this document in your native language, consider joining
  53. @uref{https://translate.fedoraproject.org/projects/guix/documentation-cookbook,
  54. Weblate} (@pxref{Translating Guix,,, guix, GNU Guix reference manual}).
  55. @menu
  56. * Scheme tutorials:: Meet your new favorite language!
  57. * Packaging:: Packaging tutorials
  58. * System Configuration:: Customizing the GNU System
  59. * Advanced package management:: Power to the users!
  60. * Environment management:: Control environment
  61. * Acknowledgments:: Thanks!
  62. * GNU Free Documentation License:: The license of this document.
  63. * Concept Index:: Concepts.
  64. @detailmenu
  65. --- The Detailed Node Listing ---
  66. Scheme tutorials
  67. * A Scheme Crash Course:: Learn the basics of Scheme
  68. Packaging
  69. * Packaging Tutorial:: Let's add a package to Guix!
  70. System Configuration
  71. * Auto-Login to a Specific TTY:: Automatically Login a User to a Specific TTY
  72. * Customizing the Kernel:: Creating and using a custom Linux kernel on Guix System.
  73. @end detailmenu
  74. @end menu
  75. @c *********************************************************************
  76. @node Scheme tutorials
  77. @chapter Scheme tutorials
  78. GNU@tie{}Guix is written in the general purpose programming language Scheme,
  79. and many of its features can be accessed and manipulated programmatically.
  80. You can use Scheme to generate package definitions, to modify them, to build
  81. them, to deploy whole operating systems, etc.
  82. Knowing the basics of how to program in Scheme will unlock many of the
  83. advanced features Guix provides --- and you don't even need to be an
  84. experienced programmer to use them!
  85. Let's get started!
  86. @node A Scheme Crash Course
  87. @section A Scheme Crash Course
  88. @cindex Scheme, crash course
  89. Guix uses the Guile implementation of Scheme. To start playing with the
  90. language, install it with @code{guix install guile} and start a
  91. @dfn{REPL}---short for @uref{https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop,
  92. @dfn{read-eval-print loop}}---by running @code{guile} from the command line.
  93. Alternatively you can also run @code{guix environment --ad-hoc guile -- guile}
  94. if you'd rather not have Guile installed in your user profile.
  95. In the following examples, lines show what you would type at the REPL;
  96. lines starting with ``@result{}'' show evaluation results, while lines
  97. starting with ``@print{}'' show things that get printed. @xref{Using Guile
  98. Interactively,,, guile, GNU Guile Reference Manual}, for more details on the
  99. REPL.
  100. @itemize
  101. @item
  102. Scheme syntax boils down to a tree of expressions (or @emph{s-expression} in
  103. Lisp lingo). An expression can be a literal such as numbers and strings, or a
  104. compound which is a parenthesized list of compounds and literals. @code{#true}
  105. and @code{#false} (abbreviated @code{#t} and @code{#f}) stand for the
  106. Booleans ``true'' and ``false'', respectively.
  107. Examples of valid expressions:
  108. @lisp
  109. "Hello World!"
  110. @result{} "Hello World!"
  111. 17
  112. @result{} 17
  113. (display (string-append "Hello " "Guix" "\n"))
  114. @print{} Hello Guix!
  115. @result{} #<unspecified>
  116. @end lisp
  117. @item
  118. This last example is a function call nested in another function call. When a
  119. parenthesized expression is evaluated, the first term is the function and the
  120. rest are the arguments passed to the function. Every function returns the
  121. last evaluated expression as its return value.
  122. @item
  123. Anonymous functions are declared with the @code{lambda} term:
  124. @lisp
  125. (lambda (x) (* x x))
  126. @result{} #<procedure 120e348 at <unknown port>:24:0 (x)>
  127. @end lisp
  128. The above procedure returns the square of its argument. Since everything is
  129. an expression, the @code{lambda} expression returns an anonymous procedure,
  130. which can in turn be applied to an argument:
  131. @lisp
  132. ((lambda (x) (* x x)) 3)
  133. @result{} 9
  134. @end lisp
  135. @item
  136. Anything can be assigned a global name with @code{define}:
  137. @lisp
  138. (define a 3)
  139. (define square (lambda (x) (* x x)))
  140. (square a)
  141. @result{} 9
  142. @end lisp
  143. @item
  144. Procedures can be defined more concisely with the following syntax:
  145. @lisp
  146. (define (square x) (* x x))
  147. @end lisp
  148. @item
  149. A list structure can be created with the @code{list} procedure:
  150. @lisp
  151. (list 2 a 5 7)
  152. @result{} (2 3 5 7)
  153. @end lisp
  154. @item
  155. The @dfn{quote} disables evaluation of a parenthesized expression: the
  156. first term is not called over the other terms (@pxref{Expression Syntax,
  157. quote,, guile, GNU Guile Reference Manual}). Thus it effectively
  158. returns a list of terms.
  159. @lisp
  160. '(display (string-append "Hello " "Guix" "\n"))
  161. @result{} (display (string-append "Hello " "Guix" "\n"))
  162. '(2 a 5 7)
  163. @result{} (2 a 5 7)
  164. @end lisp
  165. @item
  166. The @dfn{quasiquote} disables evaluation of a parenthesized expression
  167. until @dfn{unquote} (a comma) re-enables it. Thus it provides us with
  168. fine-grained control over what is evaluated and what is not.
  169. @lisp
  170. `(2 a 5 7 (2 ,a 5 ,(+ a 4)))
  171. @result{} (2 a 5 7 (2 3 5 7))
  172. @end lisp
  173. Note that the above result is a list of mixed elements: numbers, symbols (here
  174. @code{a}) and the last element is a list itself.
  175. @item
  176. Multiple variables can be named locally with @code{let} (@pxref{Local
  177. Bindings,,, guile, GNU Guile Reference Manual}):
  178. @lisp
  179. (define x 10)
  180. (let ((x 2)
  181. (y 3))
  182. (list x y))
  183. @result{} (2 3)
  184. x
  185. @result{} 10
  186. y
  187. @error{} In procedure module-lookup: Unbound variable: y
  188. @end lisp
  189. Use @code{let*} to allow later variable declarations to refer to earlier
  190. definitions.
  191. @lisp
  192. (let* ((x 2)
  193. (y (* x 3)))
  194. (list x y))
  195. @result{} (2 6)
  196. @end lisp
  197. @item
  198. @dfn{Keywords} are typically used to identify the named parameters of a
  199. procedure. They are prefixed by @code{#:} (hash, colon) followed by
  200. alphanumeric characters: @code{#:like-this}.
  201. @xref{Keywords,,, guile, GNU Guile Reference Manual}.
  202. @item
  203. The percentage @code{%} is typically used for read-only global variables in
  204. the build stage. Note that it is merely a convention, like @code{_} in C.
  205. Scheme treats @code{%} exactly the same as any other letter.
  206. @item
  207. Modules are created with @code{define-module} (@pxref{Creating Guile
  208. Modules,,, guile, GNU Guile Reference Manual}). For instance
  209. @lisp
  210. (define-module (guix build-system ruby)
  211. #:use-module (guix store)
  212. #:export (ruby-build
  213. ruby-build-system))
  214. @end lisp
  215. defines the module @code{guix build-system ruby} which must be located in
  216. @file{guix/build-system/ruby.scm} somewhere in the Guile load path. It
  217. depends on the @code{(guix store)} module and it exports two variables,
  218. @code{ruby-build} and @code{ruby-build-system}.
  219. @end itemize
  220. For a more detailed introduction, check out
  221. @uref{http://www.troubleshooters.com/codecorn/scheme_guile/hello.htm, Scheme
  222. at a Glance}, by Steve Litt.
  223. One of the reference Scheme books is the seminal ``Structure and
  224. Interpretation of Computer Programs'', by Harold Abelson and Gerald Jay
  225. Sussman, with Julie Sussman. You'll find a
  226. @uref{https://mitpress.mit.edu/sites/default/files/sicp/index.html, free copy
  227. online}, together with
  228. @uref{https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/video-lectures/,
  229. videos of the lectures by the authors}. The book is available in Texinfo
  230. format as the @code{sicp} Guix package. Go ahead, run @code{guix install
  231. sicp} and start reading with @code{info sicp} (@pxref{,,, sicp, Structure and Interpretation of Computer Programs}).
  232. An @uref{https://sarabander.github.io/sicp/, unofficial ebook is also
  233. available}.
  234. You'll find more books, tutorials and other resources at
  235. @url{https://schemers.org/}.
  236. @c *********************************************************************
  237. @node Packaging
  238. @chapter Packaging
  239. @cindex packaging
  240. This chapter is dedicated to teaching you how to add packages to the
  241. collection of packages that come with GNU Guix. This involves writing package
  242. definitions in Guile Scheme, organizing them in package modules, and building
  243. them.
  244. @menu
  245. * Packaging Tutorial:: A tutorial on how to add packages to Guix.
  246. @end menu
  247. @node Packaging Tutorial
  248. @section Packaging Tutorial
  249. GNU Guix stands out as the @emph{hackable} package manager, mostly because it
  250. uses @uref{https://www.gnu.org/software/guile/, GNU Guile}, a powerful
  251. high-level programming language, one of the
  252. @uref{https://en.wikipedia.org/wiki/Scheme_%28programming_language%29, Scheme}
  253. dialects from the
  254. @uref{https://en.wikipedia.org/wiki/Lisp_%28programming_language%29, Lisp family}.
  255. Package definitions are also written in Scheme, which empowers Guix in some
  256. very unique ways, unlike most other package managers that use shell scripts or
  257. simple languages.
  258. @itemize
  259. @item
  260. Use functions, structures, macros and all of Scheme expressiveness for your
  261. package definitions.
  262. @item
  263. Inheritance makes it easy to customize a package by inheriting from it and
  264. modifying only what is needed.
  265. @item
  266. Batch processing: the whole package collection can be parsed, filtered and
  267. processed. Building a headless server with all graphical interfaces stripped
  268. out? It's possible. Want to rebuild everything from source using specific
  269. compiler optimization flags? Pass the @code{#:make-flags "..."} argument to
  270. the list of packages. It wouldn't be a stretch to think
  271. @uref{https://wiki.gentoo.org/wiki/USE_flag, Gentoo USE flags} here, but this
  272. goes even further: the changes don't have to be thought out beforehand by the
  273. packager, they can be @emph{programmed} by the user!
  274. @end itemize
  275. The following tutorial covers all the basics around package creation with Guix.
  276. It does not assume much knowledge of the Guix system nor of the Lisp language.
  277. The reader is only expected to be familiar with the command line and to have some
  278. basic programming knowledge.
  279. @node A ``Hello World'' package
  280. @subsection A ``Hello World'' package
  281. The ``Defining Packages'' section of the manual introduces the basics of Guix
  282. packaging (@pxref{Defining Packages,,, guix, GNU Guix Reference Manual}). In
  283. the following section, we will partly go over those basics again.
  284. GNU@tie{}Hello is a dummy project that serves as an idiomatic example for
  285. packaging. It uses the GNU build system (@code{./configure && make && make
  286. install}). Guix already provides a package definition which is a perfect
  287. example to start with. You can look up its declaration with @code{guix edit
  288. hello} from the command line. Let's see how it looks:
  289. @lisp
  290. (define-public hello
  291. (package
  292. (name "hello")
  293. (version "2.10")
  294. (source (origin
  295. (method url-fetch)
  296. (uri (string-append "mirror://gnu/hello/hello-" version
  297. ".tar.gz"))
  298. (sha256
  299. (base32
  300. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
  301. (build-system gnu-build-system)
  302. (synopsis "Hello, GNU world: An example GNU package")
  303. (description
  304. "GNU Hello prints the message \"Hello, world!\" and then exits. It
  305. serves as an example of standard GNU coding practices. As such, it supports
  306. command-line arguments, multiple languages, and so on.")
  307. (home-page "https://www.gnu.org/software/hello/")
  308. (license gpl3+)))
  309. @end lisp
  310. As you can see, most of it is rather straightforward. But let's review the
  311. fields together:
  312. @table @samp
  313. @item name
  314. The project name. Using Scheme conventions, we prefer to keep it
  315. lower case, without underscore and using dash-separated words.
  316. @item source
  317. This field contains a description of the source code origin. The
  318. @code{origin} record contains these fields:
  319. @enumerate
  320. @item The method, here @code{url-fetch} to download via HTTP/FTP, but other methods
  321. exist, such as @code{git-fetch} for Git repositories.
  322. @item The URI, which is typically some @code{https://} location for @code{url-fetch}. Here
  323. the special `mirror://gnu` refers to a set of well known locations, all of
  324. which can be used by Guix to fetch the source, should some of them fail.
  325. @item The @code{sha256} checksum of the requested file. This is essential to ensure
  326. the source is not corrupted. Note that Guix works with base32 strings,
  327. hence the call to the @code{base32} function.
  328. @end enumerate
  329. @item build-system
  330. This is where the power of abstraction provided by the Scheme language really
  331. shines: in this case, the @code{gnu-build-system} abstracts away the famous
  332. @code{./configure && make && make install} shell invocations. Other build
  333. systems include the @code{trivial-build-system} which does not do anything and
  334. requires from the packager to program all the build steps, the
  335. @code{python-build-system}, the @code{emacs-build-system}, and many more
  336. (@pxref{Build Systems,,, guix, GNU Guix Reference Manual}).
  337. @item synopsis
  338. It should be a concise summary of what the package does. For many packages a
  339. tagline from the project's home page can be used as the synopsis.
  340. @item description
  341. Same as for the synopsis, it's fine to re-use the project description from the
  342. homepage. Note that Guix uses Texinfo syntax.
  343. @item home-page
  344. Use HTTPS if available.
  345. @item license
  346. See @code{guix/licenses.scm} in the project source for a full list of
  347. available licenses.
  348. @end table
  349. Time to build our first package! Nothing fancy here for now: we will stick to a
  350. dummy @code{my-hello}, a copy of the above declaration.
  351. As with the ritualistic ``Hello World'' taught with most programming languages,
  352. this will possibly be the most ``manual'' approach. We will work out an ideal
  353. setup later; for now we will go the simplest route.
  354. Save the following to a file @file{my-hello.scm}.
  355. @lisp
  356. (use-modules (guix packages)
  357. (guix download)
  358. (guix build-system gnu)
  359. (guix licenses))
  360. (package
  361. (name "my-hello")
  362. (version "2.10")
  363. (source (origin
  364. (method url-fetch)
  365. (uri (string-append "mirror://gnu/hello/hello-" version
  366. ".tar.gz"))
  367. (sha256
  368. (base32
  369. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
  370. (build-system gnu-build-system)
  371. (synopsis "Hello, Guix world: An example custom Guix package")
  372. (description
  373. "GNU Hello prints the message \"Hello, world!\" and then exits. It
  374. serves as an example of standard GNU coding practices. As such, it supports
  375. command-line arguments, multiple languages, and so on.")
  376. (home-page "https://www.gnu.org/software/hello/")
  377. (license gpl3+))
  378. @end lisp
  379. We will explain the extra code in a moment.
  380. Feel free to play with the different values of the various fields. If you
  381. change the source, you'll need to update the checksum. Indeed, Guix refuses to
  382. build anything if the given checksum does not match the computed checksum of the
  383. source code. To obtain the correct checksum of the package declaration, we
  384. need to download the source, compute the sha256 checksum and convert it to
  385. base32.
  386. Thankfully, Guix can automate this task for us; all we need is to provide the
  387. URI:
  388. @c TRANSLATORS: This is example shell output.
  389. @example sh
  390. $ guix download mirror://gnu/hello/hello-2.10.tar.gz
  391. Starting download of /tmp/guix-file.JLYgL7
  392. From https://ftpmirror.gnu.org/gnu/hello/hello-2.10.tar.gz...
  393. following redirection to `https://mirror.ibcp.fr/pub/gnu/hello/hello-2.10.tar.gz'...
  394. …10.tar.gz 709KiB 2.5MiB/s 00:00 [##################] 100.0%
  395. /gnu/store/hbdalsf5lpf01x4dcknwx6xbn6n5km6k-hello-2.10.tar.gz
  396. 0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i
  397. @end example
  398. In this specific case the output tells us which mirror was chosen.
  399. If the result of the above command is not the same as in the above snippet,
  400. update your @code{my-hello} declaration accordingly.
  401. Note that GNU package tarballs come with an OpenPGP signature, so you
  402. should definitely check the signature of this tarball with `gpg` to
  403. authenticate it before going further:
  404. @c TRANSLATORS: This is example shell output.
  405. @example sh
  406. $ guix download mirror://gnu/hello/hello-2.10.tar.gz.sig
  407. Starting download of /tmp/guix-file.03tFfb
  408. From https://ftpmirror.gnu.org/gnu/hello/hello-2.10.tar.gz.sig...
  409. following redirection to `https://ftp.igh.cnrs.fr/pub/gnu/hello/hello-2.10.tar.gz.sig'...
  410. ….tar.gz.sig 819B 1.2MiB/s 00:00 [##################] 100.0%
  411. /gnu/store/rzs8wba9ka7grrmgcpfyxvs58mly0sx6-hello-2.10.tar.gz.sig
  412. 0q0v86n3y38z17rl146gdakw9xc4mcscpk8dscs412j22glrv9jf
  413. $ gpg --verify /gnu/store/rzs8wba9ka7grrmgcpfyxvs58mly0sx6-hello-2.10.tar.gz.sig /gnu/store/hbdalsf5lpf01x4dcknwx6xbn6n5km6k-hello-2.10.tar.gz
  414. gpg: Signature made Sun 16 Nov 2014 01:08:37 PM CET
  415. gpg: using RSA key A9553245FDE9B739
  416. gpg: Good signature from "Sami Kerola <kerolasa@@iki.fi>" [unknown]
  417. gpg: aka "Sami Kerola (http://www.iki.fi/kerolasa/) <kerolasa@@iki.fi>" [unknown]
  418. gpg: WARNING: This key is not certified with a trusted signature!
  419. gpg: There is no indication that the signature belongs to the owner.
  420. Primary key fingerprint: 8ED3 96E3 7E38 D471 A005 30D3 A955 3245 FDE9 B739
  421. @end example
  422. You can then happily run
  423. @c TRANSLATORS: Do not translate this command
  424. @example sh
  425. $ guix package --install-from-file=my-hello.scm
  426. @end example
  427. You should now have @code{my-hello} in your profile!
  428. @c TRANSLATORS: Do not translate this command
  429. @example sh
  430. $ guix package --list-installed=my-hello
  431. my-hello 2.10 out
  432. /gnu/store/f1db2mfm8syb8qvc357c53slbvf1g9m9-my-hello-2.10
  433. @end example
  434. We've gone as far as we could without any knowledge of Scheme. Before moving
  435. on to more complex packages, now is the right time to brush up on your Scheme
  436. knowledge. @pxref{A Scheme Crash Course} to get up to speed.
  437. @node Setup
  438. @subsection Setup
  439. In the rest of this chapter we will rely on some basic Scheme
  440. programming knowledge. Now let's detail the different possible setups
  441. for working on Guix packages.
  442. There are several ways to set up a Guix packaging environment.
  443. We recommend you work directly on the Guix source checkout since it makes it
  444. easier for everyone to contribute to the project.
  445. But first, let's look at other possibilities.
  446. @node Local file
  447. @subsubsection Local file
  448. This is what we previously did with @samp{my-hello}. With the Scheme basics we've
  449. covered, we are now able to explain the leading chunks. As stated in @code{guix
  450. package --help}:
  451. @example
  452. -f, --install-from-file=FILE
  453. install the package that the code within FILE
  454. evaluates to
  455. @end example
  456. Thus the last expression @emph{must} return a package, which is the case in our
  457. earlier example.
  458. The @code{use-modules} expression tells which of the modules we need in the file.
  459. Modules are a collection of values and procedures. They are commonly called
  460. ``libraries'' or ``packages'' in other programming languages.
  461. @node @samp{GUIX_PACKAGE_PATH}
  462. @subsubsection @samp{GUIX_PACKAGE_PATH}
  463. @emph{Note: Starting from Guix 0.16, the more flexible Guix @dfn{channels} are the
  464. preferred way and supersede @samp{GUIX_PACKAGE_PATH}. See next section.}
  465. It can be tedious to specify the file from the command line instead of simply
  466. calling @code{guix package --install my-hello} as you would do with the official
  467. packages.
  468. Guix makes it possible to streamline the process by adding as many ``package
  469. declaration directories'' as you want.
  470. Create a directory, say @file{~/guix-packages} and add it to the @samp{GUIX_PACKAGE_PATH}
  471. environment variable:
  472. @example
  473. $ mkdir ~/guix-packages
  474. $ export GUIX_PACKAGE_PATH=~/guix-packages
  475. @end example
  476. To add several directories, separate them with a colon (@code{:}).
  477. Our previous @samp{my-hello} needs some adjustments though:
  478. @lisp
  479. (define-module (my-hello)
  480. #:use-module (guix licenses)
  481. #:use-module (guix packages)
  482. #:use-module (guix build-system gnu)
  483. #:use-module (guix download))
  484. (define-public my-hello
  485. (package
  486. (name "my-hello")
  487. (version "2.10")
  488. (source (origin
  489. (method url-fetch)
  490. (uri (string-append "mirror://gnu/hello/hello-" version
  491. ".tar.gz"))
  492. (sha256
  493. (base32
  494. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
  495. (build-system gnu-build-system)
  496. (synopsis "Hello, Guix world: An example custom Guix package")
  497. (description
  498. "GNU Hello prints the message \"Hello, world!\" and then exits. It
  499. serves as an example of standard GNU coding practices. As such, it supports
  500. command-line arguments, multiple languages, and so on.")
  501. (home-page "https://www.gnu.org/software/hello/")
  502. (license gpl3+)))
  503. @end lisp
  504. Note that we have assigned the package value to an exported variable name with
  505. @code{define-public}. This is effectively assigning the package to the @code{my-hello}
  506. variable so that it can be referenced, among other as dependency of other
  507. packages.
  508. If you use @code{guix package --install-from-file=my-hello.scm} on the above file, it
  509. will fail because the last expression, @code{define-public}, does not return a
  510. package. If you want to use @code{define-public} in this use-case nonetheless, make
  511. sure the file ends with an evaluation of @code{my-hello}:
  512. @lisp
  513. ; ...
  514. (define-public my-hello
  515. ; ...
  516. )
  517. my-hello
  518. @end lisp
  519. This last example is not very typical.
  520. Now @samp{my-hello} should be part of the package collection like all other official
  521. packages. You can verify this with:
  522. @example
  523. $ guix package --show=my-hello
  524. @end example
  525. @node Guix channels
  526. @subsubsection Guix channels
  527. Guix 0.16 features channels, which is very similar to @samp{GUIX_PACKAGE_PATH} but
  528. provides better integration and provenance tracking. Channels are not
  529. necessarily local, they can be maintained as a public Git repository for
  530. instance. Of course, several channels can be used at the same time.
  531. @xref{Channels,,, guix, GNU Guix Reference Manual} for setup details.
  532. @node Direct checkout hacking
  533. @subsubsection Direct checkout hacking
  534. Working directly on the Guix project is recommended: it reduces the friction
  535. when the time comes to submit your changes upstream to let the community benefit
  536. from your hard work!
  537. Unlike most software distributions, the Guix repository holds in one place both
  538. the tooling (including the package manager) and the package definitions. This
  539. choice was made so that it would give developers the flexibility to modify the
  540. API without breakage by updating all packages at the same time. This reduces
  541. development inertia.
  542. Check out the official @uref{https://git-scm.com/, Git} repository:
  543. @example
  544. $ git clone https://git.savannah.gnu.org/git/guix.git
  545. @end example
  546. In the rest of this article, we use @samp{$GUIX_CHECKOUT} to refer to the location of
  547. the checkout.
  548. Follow the instructions in the manual (@pxref{Contributing,,, guix, GNU Guix
  549. Reference Manual}) to set up the repository environment.
  550. Once ready, you should be able to use the package definitions from the
  551. repository environment.
  552. Feel free to edit package definitions found in @samp{$GUIX_CHECKOUT/gnu/packages}.
  553. The @samp{$GUIX_CHECKOUT/pre-inst-env} script lets you use @samp{guix} over the package
  554. collection of the repository (@pxref{Running Guix Before It Is
  555. Installed,,, guix, GNU Guix Reference Manual}).
  556. @itemize
  557. @item
  558. Search packages, such as Ruby:
  559. @example
  560. $ cd $GUIX_CHECKOUT
  561. $ ./pre-inst-env guix package --list-available=ruby
  562. ruby 1.8.7-p374 out gnu/packages/ruby.scm:119:2
  563. ruby 2.1.6 out gnu/packages/ruby.scm:91:2
  564. ruby 2.2.2 out gnu/packages/ruby.scm:39:2
  565. @end example
  566. @item
  567. Build a package, here Ruby version 2.1:
  568. @example
  569. $ ./pre-inst-env guix build --keep-failed ruby@@2.1
  570. /gnu/store/c13v73jxmj2nir2xjqaz5259zywsa9zi-ruby-2.1.6
  571. @end example
  572. @item
  573. Install it to your user profile:
  574. @example
  575. $ ./pre-inst-env guix package --install ruby@@2.1
  576. @end example
  577. @item
  578. Check for common mistakes:
  579. @example
  580. $ ./pre-inst-env guix lint ruby@@2.1
  581. @end example
  582. @end itemize
  583. Guix strives at maintaining a high packaging standard; when contributing to the
  584. Guix project, remember to
  585. @itemize
  586. @item
  587. follow the coding style (@pxref{Coding Style,,, guix, GNU Guix Reference Manual}),
  588. @item
  589. and review the check list from the manual (@pxref{Submitting Patches,,, guix, GNU Guix Reference Manual}).
  590. @end itemize
  591. Once you are happy with the result, you are welcome to send your contribution to
  592. make it part of Guix. This process is also detailed in the manual. (@pxref{Contributing,,, guix, GNU Guix Reference Manual})
  593. It's a community effort so the more join in, the better Guix becomes!
  594. @node Extended example
  595. @subsection Extended example
  596. The above ``Hello World'' example is as simple as it goes. Packages can be more
  597. complex than that and Guix can handle more advanced scenarios. Let's look at
  598. another, more sophisticated package (slightly modified from the source):
  599. @lisp
  600. (define-module (gnu packages version-control)
  601. #:use-module ((guix licenses) #:prefix license:)
  602. #:use-module (guix utils)
  603. #:use-module (guix packages)
  604. #:use-module (guix git-download)
  605. #:use-module (guix build-system cmake)
  606. #:use-module (gnu packages ssh)
  607. #:use-module (gnu packages web)
  608. #:use-module (gnu packages pkg-config)
  609. #:use-module (gnu packages python)
  610. #:use-module (gnu packages compression)
  611. #:use-module (gnu packages tls))
  612. (define-public my-libgit2
  613. (let ((commit "e98d0a37c93574d2c6107bf7f31140b548c6a7bf")
  614. (revision "1"))
  615. (package
  616. (name "my-libgit2")
  617. (version (git-version "0.26.6" revision commit))
  618. (source (origin
  619. (method git-fetch)
  620. (uri (git-reference
  621. (url "https://github.com/libgit2/libgit2/")
  622. (commit commit)))
  623. (file-name (git-file-name name version))
  624. (sha256
  625. (base32
  626. "17pjvprmdrx4h6bb1hhc98w9qi6ki7yl57f090n9kbhswxqfs7s3"))
  627. (patches (search-patches "libgit2-mtime-0.patch"))
  628. (modules '((guix build utils)))
  629. ;; Remove bundled software.
  630. (snippet '(delete-file-recursively "deps"))))
  631. (build-system cmake-build-system)
  632. (outputs '("out" "debug"))
  633. (arguments
  634. `(#:tests? #true ; Run the test suite (this is the default)
  635. #:configure-flags '("-DUSE_SHA1DC=ON") ; SHA-1 collision detection
  636. #:phases
  637. (modify-phases %standard-phases
  638. (add-after 'unpack 'fix-hardcoded-paths
  639. (lambda _
  640. (substitute* "tests/repo/init.c"
  641. (("#!/bin/sh") (string-append "#!" (which "sh"))))
  642. (substitute* "tests/clar/fs.h"
  643. (("/bin/cp") (which "cp"))
  644. (("/bin/rm") (which "rm")))))
  645. ;; Run checks more verbosely.
  646. (replace 'check
  647. (lambda _ (invoke "./libgit2_clar" "-v" "-Q")))
  648. (add-after 'unpack 'make-files-writable-for-tests
  649. (lambda _ (for-each make-file-writable (find-files "." ".*")))))))
  650. (inputs
  651. (list libssh2 http-parser python-wrapper))
  652. (native-inputs
  653. (list pkg-config))
  654. (propagated-inputs
  655. ;; These two libraries are in 'Requires.private' in libgit2.pc.
  656. (list openssl zlib))
  657. (home-page "https://libgit2.github.com/")
  658. (synopsis "Library providing Git core methods")
  659. (description
  660. "Libgit2 is a portable, pure C implementation of the Git core methods
  661. provided as a re-entrant linkable library with a solid API, allowing you to
  662. write native speed custom Git applications in any language with bindings.")
  663. ;; GPLv2 with linking exception
  664. (license license:gpl2))))
  665. @end lisp
  666. (In those cases were you only want to tweak a few fields from a package
  667. definition, you should rely on inheritance instead of copy-pasting everything.
  668. See below.)
  669. Let's discuss those fields in depth.
  670. @subsubsection @code{git-fetch} method
  671. Unlike the @code{url-fetch} method, @code{git-fetch} expects a @code{git-reference} which takes
  672. a Git repository and a commit. The commit can be any Git reference such as
  673. tags, so if the @code{version} is tagged, then it can be used directly. Sometimes
  674. the tag is prefixed with a @code{v}, in which case you'd use @code{(commit (string-append
  675. "v" version))}.
  676. To ensure that the source code from the Git repository is stored in a
  677. directory with a descriptive name, we use @code{(file-name (git-file-name name
  678. version))}.
  679. The @code{git-version} procedure can be used to derive the
  680. version when packaging programs for a specific commit, following the
  681. Guix contributor guidelines (@pxref{Version Numbers,,, guix, GNU Guix
  682. Reference Manual}).
  683. How does one obtain the @code{sha256} hash that's in there, you ask? By
  684. invoking @command{guix hash} on a checkout of the desired commit, along
  685. these lines:
  686. @example
  687. git clone https://github.com/libgit2/libgit2/
  688. cd libgit2
  689. git checkout v0.26.6
  690. guix hash -rx .
  691. @end example
  692. @command{guix hash -rx} computes a SHA256 hash over the whole directory,
  693. excluding the @file{.git} sub-directory (@pxref{Invoking guix hash,,,
  694. guix, GNU Guix Reference Manual}).
  695. In the future, @command{guix download} will hopefully be able to do
  696. these steps for you, just like it does for regular downloads.
  697. @subsubsection Snippets
  698. Snippets are quoted (i.e. non-evaluated) Scheme code that are a means of patching
  699. the source. They are a Guix-y alternative to the traditional @file{.patch} files.
  700. Because of the quote, the code in only evaluated when passed to the Guix daemon
  701. for building. There can be as many snippets as needed.
  702. Snippets might need additional Guile modules which can be imported from the
  703. @code{modules} field.
  704. @subsubsection Inputs
  705. There are 3 different input types. In short:
  706. @table @asis
  707. @item native-inputs
  708. Required for building but not runtime -- installing a package
  709. through a substitute won't install these inputs.
  710. @item inputs
  711. Installed in the store but not in the profile, as well as being
  712. present at build time.
  713. @item propagated-inputs
  714. Installed in the store and in the profile, as well as
  715. being present at build time.
  716. @end table
  717. @xref{Package Reference,,, guix, GNU Guix Reference Manual} for more details.
  718. The distinction between the various inputs is important: if a dependency can be
  719. handled as an @emph{input} instead of a @emph{propagated input}, it should be done so, or
  720. else it ``pollutes'' the user profile for no good reason.
  721. For instance, a user installing a graphical program that depends on a
  722. command line tool might only be interested in the graphical part, so there is no
  723. need to force the command line tool into the user profile. The dependency is a
  724. concern to the package, not to the user. @emph{Inputs} make it possible to handle
  725. dependencies without bugging the user by adding undesired executable files (or
  726. libraries) to their profile.
  727. Same goes for @emph{native-inputs}: once the program is installed, build-time
  728. dependencies can be safely garbage-collected.
  729. It also matters when a substitute is available, in which case only the @emph{inputs}
  730. and @emph{propagated inputs} will be fetched: the @emph{native inputs} are not required to
  731. install a package from a substitute.
  732. @quotation Note
  733. You may see here and there snippets where package inputs are written
  734. quite differently, like so:
  735. @lisp
  736. ;; The "old style" for inputs.
  737. (inputs
  738. `(("libssh2" ,libssh2)
  739. ("http-parser" ,http-parser)
  740. ("python" ,python-wrapper)))
  741. @end lisp
  742. This is the ``old style'', where each input in the list is explicitly
  743. given a label (a string). It is still supported but we recommend using
  744. the style above instead. @xref{package Reference,,, guix, GNU Guix
  745. Reference Manual}, for more info.
  746. @end quotation
  747. @subsubsection Outputs
  748. Just like how a package can have multiple inputs, it can also produce multiple
  749. outputs.
  750. Each output corresponds to a separate directory in the store.
  751. The user can choose which output to install; this is useful to save space or
  752. to avoid polluting the user profile with unwanted executables or libraries.
  753. Output separation is optional. When the @code{outputs} field is left out, the
  754. default and only output (the complete package) is referred to as @code{"out"}.
  755. Typical separate output names include @code{debug} and @code{doc}.
  756. It's advised to separate outputs only when you've shown it's worth it: if the
  757. output size is significant (compare with @code{guix size}) or in case the package is
  758. modular.
  759. @subsubsection Build system arguments
  760. The @code{arguments} is a keyword-value list used to configure the build process.
  761. The simplest argument @code{#:tests?} can be used to disable the test suite when
  762. building the package. This is mostly useful when the package does not feature
  763. any test suite. It's strongly recommended to keep the test suite on if there is
  764. one.
  765. Another common argument is @code{:make-flags}, which specifies a list of flags to
  766. append when running make, as you would from the command line. For instance, the
  767. following flags
  768. @lisp
  769. #:make-flags (list (string-append "prefix=" (assoc-ref %outputs "out"))
  770. "CC=gcc")
  771. @end lisp
  772. translate into
  773. @example
  774. $ make CC=gcc prefix=/gnu/store/...-<out>
  775. @end example
  776. This sets the C compiler to @code{gcc} and the @code{prefix} variable (the installation
  777. directory in Make parlance) to @code{(assoc-ref %outputs "out")}, which is a build-stage
  778. global variable pointing to the destination directory in the store (something like
  779. @file{/gnu/store/...-my-libgit2-20180408}).
  780. Similarly, it's possible to set the configure flags:
  781. @lisp
  782. #:configure-flags '("-DUSE_SHA1DC=ON")
  783. @end lisp
  784. The @code{%build-inputs} variable is also generated in scope. It's an association
  785. table that maps the input names to their store directories.
  786. The @code{phases} keyword lists the sequential steps of the build system. Typically
  787. phases include @code{unpack}, @code{configure}, @code{build}, @code{install} and @code{check}. To know
  788. more about those phases, you need to work out the appropriate build system
  789. definition in @samp{$GUIX_CHECKOUT/guix/build/gnu-build-system.scm}:
  790. @lisp
  791. (define %standard-phases
  792. ;; Standard build phases, as a list of symbol/procedure pairs.
  793. (let-syntax ((phases (syntax-rules ()
  794. ((_ p ...) `((p . ,p) ...)))))
  795. (phases set-SOURCE-DATE-EPOCH set-paths install-locale unpack
  796. bootstrap
  797. patch-usr-bin-file
  798. patch-source-shebangs configure patch-generated-file-shebangs
  799. build check install
  800. patch-shebangs strip
  801. validate-runpath
  802. validate-documentation-location
  803. delete-info-dir-file
  804. patch-dot-desktop-files
  805. install-license-files
  806. reset-gzip-timestamps
  807. compress-documentation)))
  808. @end lisp
  809. Or from the REPL:
  810. @lisp
  811. (add-to-load-path "/path/to/guix/checkout")
  812. ,use (guix build gnu-build-system)
  813. (map first %standard-phases)
  814. @result{} (set-SOURCE-DATE-EPOCH set-paths install-locale unpack bootstrap patch-usr-bin-file patch-source-shebangs configure patch-generated-file-shebangs build check install patch-shebangs strip validate-runpath validate-documentation-location delete-info-dir-file patch-dot-desktop-files install-license-files reset-gzip-timestamps compress-documentation)
  815. @end lisp
  816. If you want to know more about what happens during those phases, consult the
  817. associated procedures.
  818. For instance, as of this writing the definition of @code{unpack} for the GNU build
  819. system is:
  820. @lisp
  821. (define* (unpack #:key source #:allow-other-keys)
  822. "Unpack SOURCE in the working directory, and change directory within the
  823. source. When SOURCE is a directory, copy it in a sub-directory of the current
  824. working directory."
  825. (if (file-is-directory? source)
  826. (begin
  827. (mkdir "source")
  828. (chdir "source")
  829. ;; Preserve timestamps (set to the Epoch) on the copied tree so that
  830. ;; things work deterministically.
  831. (copy-recursively source "."
  832. #:keep-mtime? #true))
  833. (begin
  834. (if (string-suffix? ".zip" source)
  835. (invoke "unzip" source)
  836. (invoke "tar" "xvf" source))
  837. (chdir (first-subdirectory "."))))
  838. #true)
  839. @end lisp
  840. Note the @code{chdir} call: it changes the working directory to where the source was
  841. unpacked.
  842. Thus every phase following the @code{unpack} will use the source as a working
  843. directory, which is why we can directly work on the source files.
  844. That is to say, unless a later phase changes the working directory to something
  845. else.
  846. We modify the list of @code{%standard-phases} of the build system with the
  847. @code{modify-phases} macro as per the list of specified modifications, which may have
  848. the following forms:
  849. @itemize
  850. @item
  851. @code{(add-before @var{phase} @var{new-phase} @var{procedure})}: Run @var{procedure} named @var{new-phase} before @var{phase}.
  852. @item
  853. @code{(add-after @var{phase} @var{new-phase} @var{procedure})}: Same, but afterwards.
  854. @item
  855. @code{(replace @var{phase} @var{procedure})}.
  856. @item
  857. @code{(delete @var{phase})}.
  858. @end itemize
  859. The @var{procedure} supports the keyword arguments @code{inputs} and @code{outputs}. Each
  860. input (whether @emph{native}, @emph{propagated} or not) and output directory is referenced
  861. by their name in those variables. Thus @code{(assoc-ref outputs "out")} is the store
  862. directory of the main output of the package. A phase procedure may look like
  863. this:
  864. @lisp
  865. (lambda* (#:key inputs outputs #:allow-other-keys)
  866. (let ((bash-directory (assoc-ref inputs "bash"))
  867. (output-directory (assoc-ref outputs "out"))
  868. (doc-directory (assoc-ref outputs "doc")))
  869. ;; ...
  870. #true))
  871. @end lisp
  872. The procedure must return @code{#true} on success. It's brittle to rely on the return
  873. value of the last expression used to tweak the phase because there is no
  874. guarantee it would be a @code{#true}. Hence the trailing @code{#true} to ensure the right value
  875. is returned on success.
  876. @subsubsection Code staging
  877. The astute reader may have noticed the quasi-quote and comma syntax in the
  878. argument field. Indeed, the build code in the package declaration should not be
  879. evaluated on the client side, but only when passed to the Guix daemon. This
  880. mechanism of passing code around two running processes is called @uref{https://arxiv.org/abs/1709.00833, code staging}.
  881. @subsubsection Utility functions
  882. When customizing @code{phases}, we often need to write code that mimics the
  883. equivalent system invocations (@code{make}, @code{mkdir}, @code{cp}, etc.)@: commonly used during
  884. regular ``Unix-style'' installations.
  885. Some like @code{chmod} are native to Guile.
  886. @xref{,,, guile, Guile reference manual} for a complete list.
  887. Guix provides additional helper functions which prove especially handy in the
  888. context of package management.
  889. Some of those functions can be found in
  890. @samp{$GUIX_CHECKOUT/guix/guix/build/utils.scm}. Most of them mirror the behaviour
  891. of the traditional Unix system commands:
  892. @table @code
  893. @item which
  894. Like the @samp{which} system command.
  895. @item find-files
  896. Akin to the @samp{find} system command.
  897. @item mkdir-p
  898. Like @samp{mkdir -p}, which creates all parents as needed.
  899. @item install-file
  900. Similar to @samp{install} when installing a file to a (possibly
  901. non-existing) directory. Guile has @code{copy-file} which works
  902. like @samp{cp}.
  903. @item copy-recursively
  904. Like @samp{cp -r}.
  905. @item delete-file-recursively
  906. Like @samp{rm -rf}.
  907. @item invoke
  908. Run an executable. This should be used instead of @code{system*}.
  909. @item with-directory-excursion
  910. Run the body in a different working directory,
  911. then restore the previous working directory.
  912. @item substitute*
  913. A ``@command{sed}-like'' function.
  914. @end table
  915. @xref{Build Utilities,,, guix, GNU Guix Reference Manual}, for more
  916. information on these utilities.
  917. @subsubsection Module prefix
  918. The license in our last example needs a prefix: this is because of how the
  919. @code{license} module was imported in the package, as @code{#:use-module ((guix licenses)
  920. #:prefix license:)}. The Guile module import mechanism
  921. (@pxref{Using Guile Modules,,, guile, Guile reference manual})
  922. gives the user full control over namespacing: this is needed to avoid
  923. clashes between, say, the
  924. @samp{zlib} variable from @samp{licenses.scm} (a @emph{license} value) and the @samp{zlib} variable
  925. from @samp{compression.scm} (a @emph{package} value).
  926. @node Other build systems
  927. @subsection Other build systems
  928. What we've seen so far covers the majority of packages using a build system
  929. other than the @code{trivial-build-system}. The latter does not automate anything
  930. and leaves you to build everything manually. This can be more demanding and we
  931. won't cover it here for now, but thankfully it is rarely necessary to fall back
  932. on this system.
  933. For the other build systems, such as ASDF, Emacs, Perl, Ruby and many more, the
  934. process is very similar to the GNU build system except for a few specialized
  935. arguments.
  936. @xref{Build Systems,,, guix, GNU Guix Reference Manual}, for more
  937. information on build systems, or check the source code in the
  938. @samp{$GUIX_CHECKOUT/guix/build} and
  939. @samp{$GUIX_CHECKOUT/guix/build-system} directories.
  940. @node Programmable and automated package definition
  941. @subsection Programmable and automated package definition
  942. We can't repeat it enough: having a full-fledged programming language at hand
  943. empowers us in ways that reach far beyond traditional package management.
  944. Let's illustrate this with some awesome features of Guix!
  945. @node Recursive importers
  946. @subsubsection Recursive importers
  947. You might find some build systems good enough that there is little to do at all
  948. to write a package, to the point that it becomes repetitive and tedious after a
  949. while. A @emph{raison d'être} of computers is to replace human beings at those
  950. boring tasks. So let's tell Guix to do this for us and create the package
  951. definition of an R package from CRAN (the output is trimmed for conciseness):
  952. @example
  953. $ guix import cran --recursive walrus
  954. (define-public r-mc2d
  955. ; ...
  956. (license gpl2+)))
  957. (define-public r-jmvcore
  958. ; ...
  959. (license gpl2+)))
  960. (define-public r-wrs2
  961. ; ...
  962. (license gpl3)))
  963. (define-public r-walrus
  964. (package
  965. (name "r-walrus")
  966. (version "1.0.3")
  967. (source
  968. (origin
  969. (method url-fetch)
  970. (uri (cran-uri "walrus" version))
  971. (sha256
  972. (base32
  973. "1nk2glcvy4hyksl5ipq2mz8jy4fss90hx6cq98m3w96kzjni6jjj"))))
  974. (build-system r-build-system)
  975. (propagated-inputs
  976. (list r-ggplot2 r-jmvcore r-r6 r-wrs2))
  977. (home-page "https://github.com/jamovi/walrus")
  978. (synopsis "Robust Statistical Methods")
  979. (description
  980. "This package provides a toolbox of common robust statistical
  981. tests, including robust descriptives, robust t-tests, and robust ANOVA.
  982. It is also available as a module for 'jamovi' (see
  983. <https://www.jamovi.org> for more information). Walrus is based on the
  984. WRS2 package by Patrick Mair, which is in turn based on the scripts and
  985. work of Rand Wilcox. These analyses are described in depth in the book
  986. 'Introduction to Robust Estimation & Hypothesis Testing'.")
  987. (license gpl3)))
  988. @end example
  989. The recursive importer won't import packages for which Guix already has package
  990. definitions, except for the very first.
  991. Not all applications can be packaged this way, only those relying on a select
  992. number of supported systems. Read about the full list of importers in
  993. the guix import section of the manual
  994. (@pxref{Invoking guix import,,, guix, GNU Guix Reference Manual}).
  995. @node Automatic update
  996. @subsubsection Automatic update
  997. Guix can be smart enough to check for updates on systems it knows. It can
  998. report outdated package definitions with
  999. @example
  1000. $ guix refresh hello
  1001. @end example
  1002. In most cases, updating a package to a newer version requires little more than
  1003. changing the version number and the checksum. Guix can do that automatically as
  1004. well:
  1005. @example
  1006. $ guix refresh hello --update
  1007. @end example
  1008. @node Inheritance
  1009. @subsubsection Inheritance
  1010. If you've started browsing the existing package definitions, you might have
  1011. noticed that a significant number of them have a @code{inherit} field:
  1012. @lisp
  1013. (define-public adwaita-icon-theme
  1014. (package (inherit gnome-icon-theme)
  1015. (name "adwaita-icon-theme")
  1016. (version "3.26.1")
  1017. (source (origin
  1018. (method url-fetch)
  1019. (uri (string-append "mirror://gnome/sources/" name "/"
  1020. (version-major+minor version) "/"
  1021. name "-" version ".tar.xz"))
  1022. (sha256
  1023. (base32
  1024. "17fpahgh5dyckgz7rwqvzgnhx53cx9kr2xw0szprc6bnqy977fi8"))))
  1025. (native-inputs (list `(,gtk+ "bin")))))
  1026. @end lisp
  1027. All unspecified fields are inherited from the parent package. This is very
  1028. convenient to create alternative packages, for instance with different source,
  1029. version or compilation options.
  1030. @node Getting help
  1031. @subsection Getting help
  1032. Sadly, some applications can be tough to package. Sometimes they need a patch to
  1033. work with the non-standard file system hierarchy enforced by the store.
  1034. Sometimes the tests won't run properly. (They can be skipped but this is not
  1035. recommended.) Other times the resulting package won't be reproducible.
  1036. Should you be stuck, unable to figure out how to fix any sort of packaging
  1037. issue, don't hesitate to ask the community for help.
  1038. See the @uref{https://www.gnu.org/software/guix/contact/, Guix homepage} for information on the mailing lists, IRC, etc.
  1039. @node Conclusion
  1040. @subsection Conclusion
  1041. This tutorial was a showcase of the sophisticated package management that Guix
  1042. boasts. At this point we have mostly restricted this introduction to the
  1043. @code{gnu-build-system} which is a core abstraction layer on which more advanced
  1044. abstractions are based.
  1045. Where do we go from here? Next we ought to dissect the innards of the build
  1046. system by removing all abstractions, using the @code{trivial-build-system}: this
  1047. should give us a thorough understanding of the process before investigating some
  1048. more advanced packaging techniques and edge cases.
  1049. Other features worth exploring are the interactive editing and debugging
  1050. capabilities of Guix provided by the Guile REPL@.
  1051. Those fancy features are completely optional and can wait; now is a good time
  1052. to take a well-deserved break. With what we've introduced here you should be
  1053. well armed to package lots of programs. You can get started right away and
  1054. hopefully we will see your contributions soon!
  1055. @node References
  1056. @subsection References
  1057. @itemize
  1058. @item
  1059. The @uref{https://www.gnu.org/software/guix/manual/en/html_node/Defining-Packages.html, package reference in the manual}
  1060. @item
  1061. @uref{https://gitlab.com/pjotrp/guix-notes/blob/master/HACKING.org, Pjotr’s hacking guide to GNU Guix}
  1062. @item
  1063. @uref{https://www.gnu.org/software/guix/guix-ghm-andreas-20130823.pdf, ``GNU Guix: Package without a scheme!''}, by Andreas Enge
  1064. @end itemize
  1065. @c *********************************************************************
  1066. @node System Configuration
  1067. @chapter System Configuration
  1068. Guix offers a flexible language for declaratively configuring your Guix
  1069. System. This flexibility can at times be overwhelming. The purpose of this
  1070. chapter is to demonstrate some advanced configuration concepts.
  1071. @pxref{System Configuration,,, guix, GNU Guix Reference Manual} for a complete
  1072. reference.
  1073. @menu
  1074. * Auto-Login to a Specific TTY:: Automatically Login a User to a Specific TTY
  1075. * Customizing the Kernel:: Creating and using a custom Linux kernel on Guix System.
  1076. * Guix System Image API:: Customizing images to target specific platforms.
  1077. * Connecting to Wireguard VPN:: Connecting to a Wireguard VPN.
  1078. * Customizing a Window Manager:: Handle customization of a Window manager on Guix System.
  1079. * Running Guix on a Linode Server:: Running Guix on a Linode Server
  1080. * Setting up a bind mount:: Setting up a bind mount in the file-systems definition.
  1081. * Getting substitutes from Tor:: Configuring Guix daemon to get substitutes through Tor.
  1082. * Setting up NGINX with Lua:: Configuring NGINX web-server to load Lua modules.
  1083. @end menu
  1084. @node Auto-Login to a Specific TTY
  1085. @section Auto-Login to a Specific TTY
  1086. While the Guix manual explains auto-login one user to @emph{all} TTYs (
  1087. @pxref{auto-login to TTY,,, guix, GNU Guix Reference Manual}), some
  1088. might prefer a situation, in which one user is logged into one TTY with
  1089. the other TTYs either configured to login different users or no one at
  1090. all. Note that one can auto-login one user to any TTY, but it is
  1091. usually advisable to avoid @code{tty1}, which, by default, is used to
  1092. log warnings and errors.
  1093. Here is how one might set up auto login for one user to one tty:
  1094. @lisp
  1095. (define (auto-login-to-tty config tty user)
  1096. (if (string=? tty (mingetty-configuration-tty config))
  1097. (mingetty-configuration
  1098. (inherit config)
  1099. (auto-login user))
  1100. config))
  1101. (define %my-services
  1102. (modify-services %base-services
  1103. ;; @dots{}
  1104. (mingetty-service-type config =>
  1105. (auto-login-to-tty
  1106. config "tty3" "alice"))))
  1107. (operating-system
  1108. ;; @dots{}
  1109. (services %my-services))
  1110. @end lisp
  1111. One could also @code{compose} (@pxref{Higher-Order Functions,,, guile,
  1112. The Guile Reference Manual}) @code{auto-login-to-tty} to login multiple
  1113. users to multiple ttys.
  1114. Finally, here is a note of caution. Setting up auto login to a TTY,
  1115. means that anyone can turn on your computer and run commands as your
  1116. regular user.
  1117. However, if you have an encrypted root partition, and thus already need
  1118. to enter a passphrase when the system boots, auto-login might be a
  1119. convenient option.
  1120. @node Customizing the Kernel
  1121. @section Customizing the Kernel
  1122. Guix is, at its core, a source based distribution with substitutes
  1123. (@pxref{Substitutes,,, guix, GNU Guix Reference Manual}), and as such building
  1124. packages from their source code is an expected part of regular package
  1125. installations and upgrades. Given this starting point, it makes sense that
  1126. efforts are made to reduce the amount of time spent compiling packages, and
  1127. recent changes and upgrades to the building and distribution of substitutes
  1128. continues to be a topic of discussion within Guix.
  1129. The kernel, while not requiring an overabundance of RAM to build, does take a
  1130. rather long time on an average machine. The official kernel configuration, as
  1131. is the case with many GNU/Linux distributions, errs on the side of
  1132. inclusiveness, and this is really what causes the build to take such a long
  1133. time when the kernel is built from source.
  1134. The Linux kernel, however, can also just be described as a regular old
  1135. package, and as such can be customized just like any other package. The
  1136. procedure is a little bit different, although this is primarily due to the
  1137. nature of how the package definition is written.
  1138. The @code{linux-libre} kernel package definition is actually a procedure which
  1139. creates a package.
  1140. @lisp
  1141. (define* (make-linux-libre* version gnu-revision source supported-systems
  1142. #:key
  1143. (extra-version #f)
  1144. ;; A function that takes an arch and a variant.
  1145. ;; See kernel-config for an example.
  1146. (configuration-file #f)
  1147. (defconfig "defconfig")
  1148. (extra-options %default-extra-linux-options))
  1149. ...)
  1150. @end lisp
  1151. The current @code{linux-libre} package is for the 5.15.x series, and is
  1152. declared like this:
  1153. @lisp
  1154. (define-public linux-libre-5.15
  1155. (make-linux-libre* linux-libre-5.15-version
  1156. linux-libre-5.15-gnu-revision
  1157. linux-libre-5.15-source
  1158. '("x86_64-linux" "i686-linux" "armhf-linux" "aarch64-linux" "riscv64-linux")
  1159. #:configuration-file kernel-config))
  1160. @end lisp
  1161. Any keys which are not assigned values inherit their default value from the
  1162. @code{make-linux-libre} definition. When comparing the two snippets above,
  1163. notice the code comment that refers to @code{#:configuration-file}. Because of
  1164. this, it is not actually easy to include a custom kernel configuration from the
  1165. definition, but don't worry, there are other ways to work with what we do have.
  1166. There are two ways to create a kernel with a custom kernel configuration. The
  1167. first is to provide a standard @file{.config} file during the build process by
  1168. including an actual @file{.config} file as a native input to our custom
  1169. kernel. The following is a snippet from the custom @code{'configure} phase of
  1170. the @code{make-linux-libre} package definition:
  1171. @lisp
  1172. (let ((build (assoc-ref %standard-phases 'build))
  1173. (config (assoc-ref (or native-inputs inputs) "kconfig")))
  1174. ;; Use a custom kernel configuration file or a default
  1175. ;; configuration file.
  1176. (if config
  1177. (begin
  1178. (copy-file config ".config")
  1179. (chmod ".config" #o666))
  1180. (invoke "make" ,defconfig)))
  1181. @end lisp
  1182. Below is a sample kernel package. The @code{linux-libre} package is nothing
  1183. special and can be inherited from and have its fields overridden like any
  1184. other package:
  1185. @lisp
  1186. (define-public linux-libre/E2140
  1187. (package
  1188. (inherit linux-libre)
  1189. (native-inputs
  1190. `(("kconfig" ,(local-file "E2140.config"))
  1191. ,@@(alist-delete "kconfig"
  1192. (package-native-inputs linux-libre))))))
  1193. @end lisp
  1194. In the same directory as the file defining @code{linux-libre-E2140} is a file
  1195. named @file{E2140.config}, which is an actual kernel configuration file. The
  1196. @code{defconfig} keyword of @code{make-linux-libre} is left blank here, so the
  1197. only kernel configuration in the package is the one which was included in the
  1198. @code{native-inputs} field.
  1199. The second way to create a custom kernel is to pass a new value to the
  1200. @code{extra-options} keyword of the @code{make-linux-libre} procedure. The
  1201. @code{extra-options} keyword works with another function defined right below
  1202. it:
  1203. @lisp
  1204. (define %default-extra-linux-options
  1205. `(;; https://lists.gnu.org/archive/html/guix-devel/2014-04/msg00039.html
  1206. ("CONFIG_DEVPTS_MULTIPLE_INSTANCES" . #true)
  1207. ;; Modules required for initrd:
  1208. ("CONFIG_NET_9P" . m)
  1209. ("CONFIG_NET_9P_VIRTIO" . m)
  1210. ("CONFIG_VIRTIO_BLK" . m)
  1211. ("CONFIG_VIRTIO_NET" . m)
  1212. ("CONFIG_VIRTIO_PCI" . m)
  1213. ("CONFIG_VIRTIO_BALLOON" . m)
  1214. ("CONFIG_VIRTIO_MMIO" . m)
  1215. ("CONFIG_FUSE_FS" . m)
  1216. ("CONFIG_CIFS" . m)
  1217. ("CONFIG_9P_FS" . m)))
  1218. (define (config->string options)
  1219. (string-join (map (match-lambda
  1220. ((option . 'm)
  1221. (string-append option "=m"))
  1222. ((option . #true)
  1223. (string-append option "=y"))
  1224. ((option . #false)
  1225. (string-append option "=n")))
  1226. options)
  1227. "\n"))
  1228. @end lisp
  1229. And in the custom configure script from the `make-linux-libre` package:
  1230. @lisp
  1231. ;; Appending works even when the option wasn't in the
  1232. ;; file. The last one prevails if duplicated.
  1233. (let ((port (open-file ".config" "a"))
  1234. (extra-configuration ,(config->string extra-options)))
  1235. (display extra-configuration port)
  1236. (close-port port))
  1237. (invoke "make" "oldconfig")
  1238. @end lisp
  1239. So by not providing a configuration-file the @file{.config} starts blank, and
  1240. then we write into it the collection of flags that we want. Here's another
  1241. custom kernel:
  1242. @lisp
  1243. (define %macbook41-full-config
  1244. (append %macbook41-config-options
  1245. %file-systems
  1246. %efi-support
  1247. %emulation
  1248. (@@@@ (gnu packages linux) %default-extra-linux-options)))
  1249. (define-public linux-libre-macbook41
  1250. ;; XXX: Access the internal 'make-linux-libre*' procedure, which is
  1251. ;; private and unexported, and is liable to change in the future.
  1252. ((@@@@ (gnu packages linux) make-linux-libre*)
  1253. (@@@@ (gnu packages linux) linux-libre-version)
  1254. (@@@@ (gnu packages linux) linux-libre-gnu-revision)
  1255. (@@@@ (gnu packages linux) linux-libre-source)
  1256. '("x86_64-linux")
  1257. #:extra-version "macbook41"
  1258. #:extra-options %macbook41-config-options))
  1259. @end lisp
  1260. In the above example @code{%file-systems} is a collection of flags enabling
  1261. different file system support, @code{%efi-support} enables EFI support and
  1262. @code{%emulation} enables a x86_64-linux machine to act in 32-bit mode also.
  1263. @code{%default-extra-linux-options} are the ones quoted above, which had to be
  1264. added in since they were replaced in the @code{extra-options} keyword.
  1265. This all sounds like it should be doable, but how does one even know which
  1266. modules are required for a particular system? Two places that can be helpful
  1267. in trying to answer this question is the
  1268. @uref{https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Kernel, Gentoo
  1269. Handbook} and the
  1270. @uref{https://www.kernel.org/doc/html/latest/admin-guide/README.html?highlight=localmodconfig,
  1271. documentation from the kernel itself}. From the kernel documentation, it
  1272. seems that @code{make localmodconfig} is the command we want.
  1273. In order to actually run @code{make localmodconfig} we first need to get and
  1274. unpack the kernel source code:
  1275. @example shell
  1276. tar xf $(guix build linux-libre --source)
  1277. @end example
  1278. Once inside the directory containing the source code run @code{touch .config}
  1279. to create an initial, empty @file{.config} to start with. @code{make
  1280. localmodconfig} works by seeing what you already have in @file{.config} and
  1281. letting you know what you're missing. If the file is blank then you're
  1282. missing everything. The next step is to run:
  1283. @example shell
  1284. guix environment linux-libre -- make localmodconfig
  1285. @end example
  1286. and note the output. Do note that the @file{.config} file is still empty.
  1287. The output generally contains two types of warnings. The first start with
  1288. "WARNING" and can actually be ignored in our case. The second read:
  1289. @example shell
  1290. module pcspkr did not have configs CONFIG_INPUT_PCSPKR
  1291. @end example
  1292. For each of these lines, copy the @code{CONFIG_XXXX_XXXX} portion into the
  1293. @file{.config} in the directory, and append @code{=m}, so in the end it looks
  1294. like this:
  1295. @example shell
  1296. CONFIG_INPUT_PCSPKR=m
  1297. CONFIG_VIRTIO=m
  1298. @end example
  1299. After copying all the configuration options, run @code{make localmodconfig}
  1300. again to make sure that you don't have any output starting with ``module''.
  1301. After all of these machine specific modules there are a couple more left that
  1302. are also needed. @code{CONFIG_MODULES} is necessary so that you can build and
  1303. load modules separately and not have everything built into the kernel.
  1304. @code{CONFIG_BLK_DEV_SD} is required for reading from hard drives. It is
  1305. possible that there are other modules which you will need.
  1306. This post does not aim to be a guide to configuring your own kernel however,
  1307. so if you do decide to build a custom kernel you'll have to seek out other
  1308. guides to create a kernel which is just right for your needs.
  1309. The second way to setup the kernel configuration makes more use of Guix's
  1310. features and allows you to share configuration segments between different
  1311. kernels. For example, all machines using EFI to boot have a number of EFI
  1312. configuration flags that they need. It is likely that all the kernels will
  1313. share a list of file systems to support. By using variables it is easier to
  1314. see at a glance what features are enabled and to make sure you don't have
  1315. features in one kernel but missing in another.
  1316. Left undiscussed however, is Guix's initrd and its customization. It is
  1317. likely that you'll need to modify the initrd on a machine using a custom
  1318. kernel, since certain modules which are expected to be built may not be
  1319. available for inclusion into the initrd.
  1320. @node Guix System Image API
  1321. @section Guix System Image API
  1322. Historically, Guix System is centered around an @code{operating-system}
  1323. structure. This structure contains various fields ranging from the
  1324. bootloader and kernel declaration to the services to install.
  1325. Depending on the target machine, that can go from a standard
  1326. @code{x86_64} machine to a small ARM single board computer such as the
  1327. Pine64, the image constraints can vary a lot. The hardware
  1328. manufacturers will impose different image formats with various partition
  1329. sizes and offsets.
  1330. To create images suitable for all those machines, a new abstraction is
  1331. necessary: that's the goal of the @code{image} record. This record
  1332. contains all the required information to be transformed into a
  1333. standalone image, that can be directly booted on any target machine.
  1334. @lisp
  1335. (define-record-type* <image>
  1336. image make-image
  1337. image?
  1338. (name image-name ;symbol
  1339. (default #f))
  1340. (format image-format) ;symbol
  1341. (target image-target
  1342. (default #f))
  1343. (size image-size ;size in bytes as integer
  1344. (default 'guess))
  1345. (operating-system image-operating-system ;<operating-system>
  1346. (default #f))
  1347. (partitions image-partitions ;list of <partition>
  1348. (default '()))
  1349. (compression? image-compression? ;boolean
  1350. (default #t))
  1351. (volatile-root? image-volatile-root? ;boolean
  1352. (default #t))
  1353. (substitutable? image-substitutable? ;boolean
  1354. (default #t)))
  1355. @end lisp
  1356. This record contains the operating-system to instantiate. The
  1357. @code{format} field defines the image type and can be @code{efi-raw},
  1358. @code{qcow2} or @code{iso9660} for instance. In the future, it could be
  1359. extended to @code{docker} or other image types.
  1360. A new directory in the Guix sources is dedicated to images definition. For now
  1361. there are four files:
  1362. @itemize @bullet
  1363. @item @file{gnu/system/images/hurd.scm}
  1364. @item @file{gnu/system/images/pine64.scm}
  1365. @item @file{gnu/system/images/novena.scm}
  1366. @item @file{gnu/system/images/pinebook-pro.scm}
  1367. @end itemize
  1368. Let's have a look to @file{pine64.scm}. It contains the
  1369. @code{pine64-barebones-os} variable which is a minimal definition of an
  1370. operating-system dedicated to the @b{Pine A64 LTS} board.
  1371. @lisp
  1372. (define pine64-barebones-os
  1373. (operating-system
  1374. (host-name "vignemale")
  1375. (timezone "Europe/Paris")
  1376. (locale "en_US.utf8")
  1377. (bootloader (bootloader-configuration
  1378. (bootloader u-boot-pine64-lts-bootloader)
  1379. (targets '("/dev/vda"))))
  1380. (initrd-modules '())
  1381. (kernel linux-libre-arm64-generic)
  1382. (file-systems (cons (file-system
  1383. (device (file-system-label "my-root"))
  1384. (mount-point "/")
  1385. (type "ext4"))
  1386. %base-file-systems))
  1387. (services (cons (service agetty-service-type
  1388. (agetty-configuration
  1389. (extra-options '("-L")) ; no carrier detect
  1390. (baud-rate "115200")
  1391. (term "vt100")
  1392. (tty "ttyS0")))
  1393. %base-services))))
  1394. @end lisp
  1395. The @code{kernel} and @code{bootloader} fields are pointing to packages
  1396. dedicated to this board.
  1397. Right below, the @code{pine64-image-type} variable is also defined.
  1398. @lisp
  1399. (define pine64-image-type
  1400. (image-type
  1401. (name 'pine64-raw)
  1402. (constructor (cut image-with-os arm64-disk-image <>))))
  1403. @end lisp
  1404. It's using a record we haven't talked about yet, the @code{image-type} record,
  1405. defined this way:
  1406. @lisp
  1407. (define-record-type* <image-type>
  1408. image-type make-image-type
  1409. image-type?
  1410. (name image-type-name) ;symbol
  1411. (constructor image-type-constructor)) ;<operating-system> -> <image>
  1412. @end lisp
  1413. The main purpose of this record is to associate a name to a procedure
  1414. transforming an @code{operating-system} to an image. To understand why
  1415. it is necessary, let's have a look to the command producing an image
  1416. from an @code{operating-system} configuration file:
  1417. @example
  1418. guix system image my-os.scm
  1419. @end example
  1420. This command expects an @code{operating-system} configuration but how
  1421. should we indicate that we want an image targeting a Pine64 board? We
  1422. need to provide an extra information, the @code{image-type}, by passing
  1423. the @code{--image-type} or @code{-t} flag, this way:
  1424. @example
  1425. guix system image --image-type=pine64-raw my-os.scm
  1426. @end example
  1427. This @code{image-type} parameter points to the @code{pine64-image-type}
  1428. defined above. Hence, the @code{operating-system} declared in
  1429. @code{my-os.scm} will be applied the @code{(cut image-with-os
  1430. arm64-disk-image <>)} procedure to turn it into an image.
  1431. The resulting image looks like:
  1432. @lisp
  1433. (image
  1434. (format 'disk-image)
  1435. (target "aarch64-linux-gnu")
  1436. (operating-system my-os)
  1437. (partitions
  1438. (list (partition
  1439. (inherit root-partition)
  1440. (offset root-offset)))))
  1441. @end lisp
  1442. which is the aggregation of the @code{operating-system} defined in
  1443. @code{my-os.scm} to the @code{arm64-disk-image} record.
  1444. But enough Scheme madness. What does this image API bring to the Guix user?
  1445. One can run:
  1446. @example
  1447. mathieu@@cervin:~$ guix system --list-image-types
  1448. The available image types are:
  1449. - pinebook-pro-raw
  1450. - pine64-raw
  1451. - novena-raw
  1452. - hurd-raw
  1453. - hurd-qcow2
  1454. - qcow2
  1455. - uncompressed-iso9660
  1456. - efi-raw
  1457. - arm64-raw
  1458. - arm32-raw
  1459. - iso9660
  1460. @end example
  1461. and by writing an @code{operating-system} file based on
  1462. @code{pine64-barebones-os}, you can customize your image to your
  1463. preferences in a file (@file{my-pine-os.scm}) like this:
  1464. @lisp
  1465. (use-modules (gnu services linux)
  1466. (gnu system images pine64))
  1467. (let ((base-os pine64-barebones-os))
  1468. (operating-system
  1469. (inherit base-os)
  1470. (timezone "America/Indiana/Indianapolis")
  1471. (services
  1472. (cons
  1473. (service earlyoom-service-type
  1474. (earlyoom-configuration
  1475. (prefer-regexp "icecat|chromium")))
  1476. (operating-system-user-services base-os)))))
  1477. @end lisp
  1478. run:
  1479. @example
  1480. guix system image --image-type=pine64-raw my-pine-os.scm
  1481. @end example
  1482. or,
  1483. @example
  1484. guix system image --image-type=hurd-raw my-hurd-os.scm
  1485. @end example
  1486. to get an image that can be written directly to a hard drive and booted
  1487. from.
  1488. Without changing anything to @code{my-hurd-os.scm}, calling:
  1489. @example
  1490. guix system image --image-type=hurd-qcow2 my-hurd-os.scm
  1491. @end example
  1492. will instead produce a Hurd QEMU image.
  1493. @node Connecting to Wireguard VPN
  1494. @section Connecting to Wireguard VPN
  1495. To connect to a Wireguard VPN server you need the kernel module to be
  1496. loaded in memory and a package providing networking tools that support
  1497. it (e.g. @code{wireguard-tools} or @code{network-manager}).
  1498. Here is a configuration example for Linux-Libre < 5.6, where the module
  1499. is out of tree and need to be loaded manually---following revisions of
  1500. the kernel have it built-in and so don't need such configuration:
  1501. @lisp
  1502. (use-modules (gnu))
  1503. (use-service-modules desktop)
  1504. (use-package-modules vpn)
  1505. (operating-system
  1506. ;; …
  1507. (services (cons (simple-service 'wireguard-module
  1508. kernel-module-loader-service-type
  1509. '("wireguard"))
  1510. %desktop-services))
  1511. (packages (cons wireguard-tools %base-packages))
  1512. (kernel-loadable-modules (list wireguard-linux-compat)))
  1513. @end lisp
  1514. After reconfiguring and restarting your system you can either use
  1515. Wireguard tools or NetworkManager to connect to a VPN server.
  1516. @subsection Using Wireguard tools
  1517. To test your Wireguard setup it is convenient to use @command{wg-quick}.
  1518. Just give it a configuration file @command{wg-quick up ./wg0.conf}; or
  1519. put that file in @file{/etc/wireguard} and run @command{wg-quick up wg0}
  1520. instead.
  1521. @quotation Note
  1522. Be warned that the author described this command as a: “[…] very quick
  1523. and dirty bash script […]”.
  1524. @end quotation
  1525. @subsection Using NetworkManager
  1526. Thanks to NetworkManager support for Wireguard we can connect to our VPN
  1527. using @command{nmcli} command. Up to this point this guide assumes that
  1528. you're using Network Manager service provided by
  1529. @code{%desktop-services}. Ortherwise you need to adjust your services
  1530. list to load @code{network-manager-service-type} and reconfigure your
  1531. Guix system.
  1532. To import your VPN configuration execute nmcli import command:
  1533. @example shell
  1534. # nmcli connection import type wireguard file wg0.conf
  1535. Connection 'wg0' (edbee261-aa5a-42db-b032-6c7757c60fde) successfully added
  1536. @end example
  1537. This will create a configuration file in
  1538. @file{/etc/NetworkManager/wg0.nmconnection}. Next connect to the
  1539. Wireguard server:
  1540. @example shell
  1541. $ nmcli connection up wg0
  1542. Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
  1543. @end example
  1544. By default NetworkManager will connect automatically on system boot. To
  1545. change that behaviour you need to edit your config:
  1546. @example shell
  1547. # nmcli connection modify wg0 connection.autoconnect no
  1548. @end example
  1549. For more specific information about NetworkManager and wireguard
  1550. @uref{https://blogs.gnome.org/thaller/2019/03/15/wireguard-in-networkmanager/,see
  1551. this post by thaller}.
  1552. @node Customizing a Window Manager
  1553. @section Customizing a Window Manager
  1554. @cindex wm
  1555. @node StumpWM
  1556. @subsection StumpWM
  1557. @cindex stumpwm
  1558. You could install StumpWM with a Guix system by adding
  1559. @code{stumpwm} and optionally @code{`(,stumpwm "lib")}
  1560. packages to a system configuration file, e.g.@: @file{/etc/config.scm}.
  1561. An example configuration can look like this:
  1562. @lisp
  1563. (use-modules (gnu))
  1564. (use-package-modules wm)
  1565. (operating-system
  1566. ;; …
  1567. (packages (append (list sbcl stumpwm `(,stumpwm "lib"))
  1568. %base-packages)))
  1569. @end lisp
  1570. @cindex stumpwm fonts
  1571. By default StumpWM uses X11 fonts, which could be small or pixelated on
  1572. your system. You could fix this by installing StumpWM contrib Lisp
  1573. module @code{sbcl-ttf-fonts}, adding it to Guix system packages:
  1574. @lisp
  1575. (use-modules (gnu))
  1576. (use-package-modules fonts wm)
  1577. (operating-system
  1578. ;; …
  1579. (packages (append (list sbcl stumpwm `(,stumpwm "lib"))
  1580. sbcl-ttf-fonts font-dejavu %base-packages)))
  1581. @end lisp
  1582. Then you need to add the following code to a StumpWM configuration file
  1583. @file{~/.stumpwm.d/init.lisp}:
  1584. @lisp
  1585. (require :ttf-fonts)
  1586. (setf xft:*font-dirs* '("/run/current-system/profile/share/fonts/"))
  1587. (setf clx-truetype:+font-cache-filename+ (concat (getenv "HOME") "/.fonts/font-cache.sexp"))
  1588. (xft:cache-fonts)
  1589. (set-font (make-instance 'xft:font :family "DejaVu Sans Mono" :subfamily "Book" :size 11))
  1590. @end lisp
  1591. @node Session lock
  1592. @subsection Session lock
  1593. @cindex sessionlock
  1594. Depending on your environment, locking the screen of your session might come built in
  1595. or it might be something you have to set up yourself. If you use a desktop environment
  1596. like GNOME or KDE, it's usually built in. If you use a plain window manager like
  1597. StumpWM or EXWM, you might have to set it up yourself.
  1598. @node Xorg
  1599. @subsubsection Xorg
  1600. If you use Xorg, you can use the utility
  1601. @uref{https://www.mankier.com/1/xss-lock, xss-lock} to lock the screen of your session.
  1602. xss-lock is triggered by DPMS which since Xorg 1.8 is auto-detected and enabled if
  1603. ACPI is also enabled at kernel runtime.
  1604. To use xss-lock, you can simple execute it and put it into the background before
  1605. you start your window manager from e.g. your @file{~/.xsession}:
  1606. @example
  1607. xss-lock -- slock &
  1608. exec stumpwm
  1609. @end example
  1610. In this example, xss-lock uses @code{slock} to do the actual locking of the screen when
  1611. it determines it's appropriate, like when you suspend your device.
  1612. For slock to be allowed to be a screen locker for the graphical session, it needs to
  1613. be made setuid-root so it can authenticate users, and it needs a PAM service. This
  1614. can be achieved by adding the following service to your @file{config.scm}:
  1615. @lisp
  1616. (screen-locker-service slock)
  1617. @end lisp
  1618. If you manually lock your screen, e.g. by directly calling slock when you want to lock
  1619. your screen but not suspend it, it's a good idea to notify xss-lock about this so no
  1620. confusion occurs. This can be done by executing @code{xset s activate} immediately
  1621. before you execute slock.
  1622. @node Running Guix on a Linode Server
  1623. @section Running Guix on a Linode Server
  1624. @cindex linode, Linode
  1625. To run Guix on a server hosted by @uref{https://www.linode.com, Linode},
  1626. start with a recommended Debian server. We recommend using the default
  1627. distro as a way to bootstrap Guix. Create your SSH keys.
  1628. @example
  1629. ssh-keygen
  1630. @end example
  1631. Be sure to add your SSH key for easy login to the remote server.
  1632. This is trivially done via Linode's graphical interface for adding
  1633. SSH keys. Go to your profile and click add SSH Key.
  1634. Copy into it the output of:
  1635. @example
  1636. cat ~/.ssh/<username>_rsa.pub
  1637. @end example
  1638. Power the Linode down.
  1639. In the Linode's Storage tab, resize the Debian disk to be smaller.
  1640. 30 GB free space is recommended. Then click "Add a disk", and fill
  1641. out the form with the following:
  1642. @itemize @bullet
  1643. @item
  1644. Label: "Guix"
  1645. @item
  1646. Filesystem: ext4
  1647. @item
  1648. Set it to the remaining size
  1649. @end itemize
  1650. In the Configurations tab, press "Edit" on the default Debian profile.
  1651. Under "Block Device Assignment" click "Add a Device". It should be
  1652. @file{/dev/sdc} and you can select the "Guix" disk. Save Changes.
  1653. Now "Add a Configuration", with the following:
  1654. @itemize @bullet
  1655. @item
  1656. Label: Guix
  1657. @item
  1658. Kernel:GRUB 2 (it's at the bottom! This step is @b{IMPORTANT!})
  1659. @item
  1660. Block device assignment:
  1661. @item
  1662. @file{/dev/sda}: Guix
  1663. @item
  1664. @file{/dev/sdb}: swap
  1665. @item
  1666. Root device: @file{/dev/sda}
  1667. @item
  1668. Turn off all the filesystem/boot helpers
  1669. @end itemize
  1670. Now power it back up, booting with the Debian configuration. Once it's
  1671. running, ssh to your server via @code{ssh
  1672. root@@@var{<your-server-IP-here>}}. (You can find your server IP address in
  1673. your Linode Summary section.) Now you can run the "install guix from
  1674. @pxref{Binary Installation,,, guix, GNU Guix}" steps:
  1675. @example
  1676. sudo apt-get install gpg
  1677. wget https://sv.gnu.org/people/viewgpg.php?user_id=15145 -qO - | gpg --import -
  1678. wget https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh
  1679. chmod +x guix-install.sh
  1680. ./guix-install.sh
  1681. guix pull
  1682. @end example
  1683. Now it's time to write out a config for the server. The key information
  1684. is below. Save the resulting file as @file{guix-config.scm}.
  1685. @lisp
  1686. (use-modules (gnu)
  1687. (guix modules))
  1688. (use-service-modules networking
  1689. ssh)
  1690. (use-package-modules admin
  1691. certs
  1692. package-management
  1693. ssh
  1694. tls)
  1695. (operating-system
  1696. (host-name "my-server")
  1697. (timezone "America/New_York")
  1698. (locale "en_US.UTF-8")
  1699. ;; This goofy code will generate the grub.cfg
  1700. ;; without installing the grub bootloader on disk.
  1701. (bootloader (bootloader-configuration
  1702. (bootloader
  1703. (bootloader
  1704. (inherit grub-bootloader)
  1705. (installer #~(const #true))))))
  1706. (file-systems (cons (file-system
  1707. (device "/dev/sda")
  1708. (mount-point "/")
  1709. (type "ext4"))
  1710. %base-file-systems))
  1711. (swap-devices (list "/dev/sdb"))
  1712. (initrd-modules (cons "virtio_scsi" ; Needed to find the disk
  1713. %base-initrd-modules))
  1714. (users (cons (user-account
  1715. (name "janedoe")
  1716. (group "users")
  1717. ;; Adding the account to the "wheel" group
  1718. ;; makes it a sudoer.
  1719. (supplementary-groups '("wheel"))
  1720. (home-directory "/home/janedoe"))
  1721. %base-user-accounts))
  1722. (packages (cons* nss-certs ;for HTTPS access
  1723. openssh-sans-x
  1724. %base-packages))
  1725. (services (cons*
  1726. (service dhcp-client-service-type)
  1727. (service openssh-service-type
  1728. (openssh-configuration
  1729. (openssh openssh-sans-x)
  1730. (password-authentication? #false)
  1731. (authorized-keys
  1732. `(("janedoe" ,(local-file "janedoe_rsa.pub"))
  1733. ("root" ,(local-file "janedoe_rsa.pub"))))))
  1734. %base-services)))
  1735. @end lisp
  1736. Replace the following fields in the above configuration:
  1737. @lisp
  1738. (host-name "my-server") ; replace with your server name
  1739. ; if you chose a linode server outside the U.S., then
  1740. ; use tzselect to find a correct timezone string
  1741. (timezone "America/New_York") ; if needed replace timezone
  1742. (name "janedoe") ; replace with your username
  1743. ("janedoe" ,(local-file "janedoe_rsa.pub")) ; replace with your ssh key
  1744. ("root" ,(local-file "janedoe_rsa.pub")) ; replace with your ssh key
  1745. @end lisp
  1746. The last line in the above example lets you log into the server as root
  1747. and set the initial root password (see the note at the end of this
  1748. recipe about root login). After you have done this, you may
  1749. delete that line from your configuration and reconfigure to prevent root
  1750. login.
  1751. Copy your ssh public key (eg: @file{~/.ssh/id_rsa.pub}) as
  1752. @file{@var{<your-username-here>}_rsa.pub} and put
  1753. @file{guix-config.scm} in the same directory. In a new terminal run
  1754. these commands.
  1755. @example
  1756. sftp root@@<remote server ip address>
  1757. put /path/to/files/<username>_rsa.pub .
  1758. put /path/to/files/guix-config.scm .
  1759. @end example
  1760. In your first terminal, mount the guix drive:
  1761. @example
  1762. mkdir /mnt/guix
  1763. mount /dev/sdc /mnt/guix
  1764. @end example
  1765. Due to the way we set up the bootloader section of the guix-config.scm,
  1766. only the grub configuration file will be installed. So, we need to copy
  1767. over some of the other GRUB stuff already installed on the Debian system:
  1768. @example
  1769. mkdir -p /mnt/guix/boot/grub
  1770. cp -r /boot/grub/* /mnt/guix/boot/grub/
  1771. @end example
  1772. Now initialize the Guix installation:
  1773. @example
  1774. guix system init guix-config.scm /mnt/guix
  1775. @end example
  1776. Ok, power it down!
  1777. Now from the Linode console, select boot and select "Guix".
  1778. Once it boots, you should be able to log in via SSH! (The server config
  1779. will have changed though.) You may encounter an error like:
  1780. @example
  1781. $ ssh root@@<server ip address>
  1782. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1783. @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
  1784. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1785. IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
  1786. Someone could be eavesdropping on you right now (man-in-the-middle attack)!
  1787. It is also possible that a host key has just been changed.
  1788. The fingerprint for the ECDSA key sent by the remote host is
  1789. SHA256:0B+wp33w57AnKQuHCvQP0+ZdKaqYrI/kyU7CfVbS7R4.
  1790. Please contact your system administrator.
  1791. Add correct host key in /home/joshua/.ssh/known_hosts to get rid of this message.
  1792. Offending ECDSA key in /home/joshua/.ssh/known_hosts:3
  1793. ECDSA host key for 198.58.98.76 has changed and you have requested strict checking.
  1794. Host key verification failed.
  1795. @end example
  1796. Either delete @file{~/.ssh/known_hosts} file, or delete the offending line
  1797. starting with your server IP address.
  1798. Be sure to set your password and root's password.
  1799. @example
  1800. ssh root@@<remote ip address>
  1801. passwd ; for the root password
  1802. passwd <username> ; for the user password
  1803. @end example
  1804. You may not be able to run the above commands at this point. If you
  1805. have issues remotely logging into your linode box via SSH, then you may
  1806. still need to set your root and user password initially by clicking on
  1807. the ``Launch Console'' option in your linode. Choose the ``Glish''
  1808. instead of ``Weblish''. Now you should be able to ssh into the machine.
  1809. Hooray! At this point you can shut down the server, delete the
  1810. Debian disk, and resize the Guix to the rest of the size.
  1811. Congratulations!
  1812. By the way, if you save it as a disk image right at this point, you'll
  1813. have an easy time spinning up new Guix images! You may need to
  1814. down-size the Guix image to 6144MB, to save it as an image. Then you
  1815. can resize it again to the max size.
  1816. @node Setting up a bind mount
  1817. @section Setting up a bind mount
  1818. To bind mount a file system, one must first set up some definitions
  1819. before the @code{operating-system} section of the system definition. In
  1820. this example we will bind mount a folder from a spinning disk drive to
  1821. @file{/tmp}, to save wear and tear on the primary SSD, without
  1822. dedicating an entire partition to be mounted as @file{/tmp}.
  1823. First, the source drive that hosts the folder we wish to bind mount
  1824. should be defined, so that the bind mount can depend on it.
  1825. @lisp
  1826. (define source-drive ;; "source-drive" can be named anything you want.
  1827. (file-system
  1828. (device (uuid "UUID goes here"))
  1829. (mount-point "/path-to-spinning-disk-goes-here")
  1830. (type "ext4"))) ;; Make sure to set this to the appropriate type for your drive.
  1831. @end lisp
  1832. The source folder must also be defined, so that guix will know it's not
  1833. a regular block device, but a folder.
  1834. @lisp
  1835. (define (%source-directory) "/path-to-spinning-disk-goes-here/tmp") ;; "source-directory" can be named any valid variable name.
  1836. @end lisp
  1837. Finally, inside the @code{file-systems} definition, we must add the
  1838. mount itself.
  1839. @lisp
  1840. (file-systems (cons*
  1841. ...<other drives omitted for clarity>...
  1842. source-drive ;; Must match the name you gave the source drive in the earlier definition.
  1843. (file-system
  1844. (device (%source-directory)) ;; Make sure "source-directory" matches your earlier definition.
  1845. (mount-point "/tmp")
  1846. (type "none") ;; We are mounting a folder, not a partition, so this type needs to be "none"
  1847. (flags '(bind-mount))
  1848. (dependencies (list source-drive)) ;; Ensure "source-drive" matches what you've named the variable for the drive.
  1849. )
  1850. ...<other drives omitted for clarity>...
  1851. ))
  1852. @end lisp
  1853. @node Getting substitutes from Tor
  1854. @section Getting substitutes from Tor
  1855. Guix daemon can use a HTTP proxy to get substitutes, here we are
  1856. configuring it to get them via Tor.
  1857. @quotation Warning
  1858. @emph{Not all} Guix daemon's traffic will go through Tor! Only
  1859. HTTP/HTTPS will get proxied; FTP, Git protocol, SSH, etc connections
  1860. will still go through the clearnet. Again, this configuration isn't
  1861. foolproof some of your traffic won't get routed by Tor at all. Use it
  1862. at your own risk.
  1863. Also note that the procedure described here applies only to package
  1864. substitution. When you update your guix distribution with
  1865. @command{guix pull}, you still need to use @command{torsocks} if
  1866. you want to route the connection to guix's git repository servers
  1867. through Tor.
  1868. @end quotation
  1869. Guix's substitute server is available as a Onion service, if you want
  1870. to use it to get your substitutes through Tor configure your system as
  1871. follow:
  1872. @lisp
  1873. (use-modules (gnu))
  1874. (use-service-module base networking)
  1875. (operating-system
  1876. (services
  1877. (cons
  1878. (service tor-service-type
  1879. (tor-configuration
  1880. (config-file (plain-file "tor-config"
  1881. "HTTPTunnelPort 127.0.0.1:9250"))))
  1882. (modify-services %base-services
  1883. (guix-service-type
  1884. config => (guix-configuration
  1885. (inherit config)
  1886. ;; ci.guix.gnu.org's Onion service
  1887. (substitute-urls "https://bp7o7ckwlewr4slm.onion")
  1888. (http-proxy "http://localhost:9250")))))))
  1889. @end lisp
  1890. This will keep a tor process running that provides a HTTP CONNECT tunnel
  1891. which will be used by @command{guix-daemon}. The daemon can use other
  1892. protocols than HTTP(S) to get remote resources, request using those
  1893. protocols won't go through Tor since we are only setting a HTTP tunnel
  1894. here. Note that @code{substitutes-urls} is using HTTPS and not HTTP or
  1895. it won't work, that's a limitation of Tor's tunnel; you may want to use
  1896. @command{privoxy} instead to avoid such limitations.
  1897. If you don't want to always get substitutes through Tor but using it just
  1898. some of the times, then skip the @code{guix-configuration}. When you
  1899. want to get a substitute from the Tor tunnel run:
  1900. @example
  1901. sudo herd set-http-proxy guix-daemon http://localhost:9250
  1902. guix build --substitute-urls=https://bp7o7ckwlewr4slm.onion …
  1903. @end example
  1904. @node Setting up NGINX with Lua
  1905. @section Setting up NGINX with Lua
  1906. @cindex nginx, lua, openresty, resty
  1907. NGINX could be extended with Lua scripts.
  1908. Guix provides NGINX service with ability to load Lua module and specific
  1909. Lua packages, and reply to requests by evaluating Lua scripts.
  1910. The following example demonstrates system definition with configuration
  1911. to evaluate @file{index.lua} Lua script on HTTP request to
  1912. @uref{http://localhost/hello} endpoint:
  1913. @example
  1914. local shell = require "resty.shell"
  1915. local stdin = ""
  1916. local timeout = 1000 -- ms
  1917. local max_size = 4096 -- byte
  1918. local ok, stdout, stderr, reason, status =
  1919. shell.run([[/run/current-system/profile/bin/ls /tmp]], stdin, timeout, max_size)
  1920. ngx.say(stdout)
  1921. @end example
  1922. @lisp
  1923. (use-modules (gnu))
  1924. (use-service-modules #;… web)
  1925. (use-package-modules #;… lua)
  1926. (operating-system
  1927. ;; …
  1928. (services
  1929. ;; …
  1930. (service nginx-service-type
  1931. (nginx-configuration
  1932. (modules
  1933. (list
  1934. (file-append nginx-lua-module "/etc/nginx/modules/ngx_http_lua_module.so")))
  1935. (lua-package-path (list lua-resty-core
  1936. lua-resty-lrucache
  1937. lua-resty-signal
  1938. lua-tablepool
  1939. lua-resty-shell))
  1940. (lua-package-cpath (list lua-resty-signal))
  1941. (server-blocks
  1942. (list (nginx-server-configuration
  1943. (server-name '("localhost"))
  1944. (listen '("80"))
  1945. (root "/etc")
  1946. (locations (list
  1947. (nginx-location-configuration
  1948. (uri "/hello")
  1949. (body (list #~(format #f "content_by_lua_file ~s;"
  1950. #$(local-file "index.lua"))))))))))))))
  1951. @end lisp
  1952. @c *********************************************************************
  1953. @node Advanced package management
  1954. @chapter Advanced package management
  1955. Guix is a functional package manager that offers many features beyond
  1956. what more traditional package managers can do. To the uninitiated,
  1957. those features might not have obvious use cases at first. The purpose
  1958. of this chapter is to demonstrate some advanced package management
  1959. concepts.
  1960. @pxref{Package Management,,, guix, GNU Guix Reference Manual} for a complete
  1961. reference.
  1962. @menu
  1963. * Guix Profiles in Practice:: Strategies for multiple profiles and manifests.
  1964. @end menu
  1965. @node Guix Profiles in Practice
  1966. @section Guix Profiles in Practice
  1967. Guix provides a very useful feature that may be quite foreign to newcomers:
  1968. @emph{profiles}. They are a way to group package installations together and all users
  1969. on the same system are free to use as many profiles as they want.
  1970. Whether you're a developer or not, you may find that multiple profiles bring you
  1971. great power and flexibility. While they shift the paradigm somewhat compared to
  1972. @emph{traditional package managers}, they are very convenient to use once you've
  1973. understood how to set them up.
  1974. If you are familiar with Python's @samp{virtualenv}, you can think of a profile as a
  1975. kind of universal @samp{virtualenv} that can hold any kind of software whatsoever, not
  1976. just Python software. Furthermore, profiles are self-sufficient: they capture
  1977. all the runtime dependencies which guarantees that all programs within a profile
  1978. will always work at any point in time.
  1979. Multiple profiles have many benefits:
  1980. @itemize
  1981. @item
  1982. Clean semantic separation of the various packages a user needs for different contexts.
  1983. @item
  1984. Multiple profiles can be made available into the environment either on login
  1985. or within a dedicated shell.
  1986. @item
  1987. Profiles can be loaded on demand. For instance, the user can use multiple
  1988. shells, each of them running different profiles.
  1989. @item
  1990. Isolation: Programs from one profile will not use programs from the other, and
  1991. the user can even install different versions of the same programs to the two
  1992. profiles without conflict.
  1993. @item
  1994. Deduplication: Profiles share dependencies that happens to be the exact same.
  1995. This makes multiple profiles storage-efficient.
  1996. @item
  1997. Reproducible: when used with declarative manifests, a profile can be fully
  1998. specified by the Guix commit that was active when it was set up. This means
  1999. that the exact same profile can be
  2000. @uref{https://guix.gnu.org/blog/2018/multi-dimensional-transactions-and-rollbacks-oh-my/,
  2001. set up anywhere and anytime}, with just the commit information. See the
  2002. section on @ref{Reproducible profiles}.
  2003. @item
  2004. Easier upgrades and maintenance: Multiple profiles make it easy to keep
  2005. package listings at hand and make upgrades completely frictionless.
  2006. @end itemize
  2007. Concretely, here follows some typical profiles:
  2008. @itemize
  2009. @item
  2010. The dependencies of a project you are working on.
  2011. @item
  2012. Your favourite programming language libraries.
  2013. @item
  2014. Laptop-specific programs (like @samp{powertop}) that you don't need on a desktop.
  2015. @item
  2016. @TeX{}live (this one can be really useful when you need to install just one
  2017. package for this one document you've just received over email).
  2018. @item
  2019. Games.
  2020. @end itemize
  2021. Let's dive in the set up!
  2022. @node Basic setup with manifests
  2023. @subsection Basic setup with manifests
  2024. A Guix profile can be set up @emph{via} a so-called @emph{manifest specification} that looks like
  2025. this:
  2026. @lisp
  2027. (specifications->manifest
  2028. '("package-1"
  2029. ;; Version 1.3 of package-2.
  2030. "package-2@@1.3"
  2031. ;; The "lib" output of package-3.
  2032. "package-3:lib"
  2033. ; ...
  2034. "package-N"))
  2035. @end lisp
  2036. @pxref{Invoking guix package,,, guix, GNU Guix Reference Manual}, for
  2037. the syntax details.
  2038. We can create a manifest specification per profile and install them this way:
  2039. @example
  2040. GUIX_EXTRA_PROFILES=$HOME/.guix-extra-profiles
  2041. mkdir -p "$GUIX_EXTRA_PROFILES"/my-project # if it does not exist yet
  2042. guix package --manifest=/path/to/guix-my-project-manifest.scm --profile="$GUIX_EXTRA_PROFILES"/my-project/my-project
  2043. @end example
  2044. Here we set an arbitrary variable @samp{GUIX_EXTRA_PROFILES} to point to the directory
  2045. where we will store our profiles in the rest of this article.
  2046. Placing all your profiles in a single directory, with each profile getting its
  2047. own sub-directory, is somewhat cleaner. This way, each sub-directory will
  2048. contain all the symlinks for precisely one profile. Besides, ``looping over
  2049. profiles'' becomes obvious from any programming language (e.g.@: a shell script) by
  2050. simply looping over the sub-directories of @samp{$GUIX_EXTRA_PROFILES}.
  2051. Note that it's also possible to loop over the output of
  2052. @example
  2053. guix package --list-profiles
  2054. @end example
  2055. although you'll probably have to filter out @file{~/.config/guix/current}.
  2056. To enable all profiles on login, add this to your @file{~/.bash_profile} (or similar):
  2057. @example
  2058. for i in $GUIX_EXTRA_PROFILES/*; do
  2059. profile=$i/$(basename "$i")
  2060. if [ -f "$profile"/etc/profile ]; then
  2061. GUIX_PROFILE="$profile"
  2062. . "$GUIX_PROFILE"/etc/profile
  2063. fi
  2064. unset profile
  2065. done
  2066. @end example
  2067. Note to Guix System users: the above reflects how your default profile
  2068. @file{~/.guix-profile} is activated from @file{/etc/profile}, that latter being loaded by
  2069. @file{~/.bashrc} by default.
  2070. You can obviously choose to only enable a subset of them:
  2071. @example
  2072. for i in "$GUIX_EXTRA_PROFILES"/my-project-1 "$GUIX_EXTRA_PROFILES"/my-project-2; do
  2073. profile=$i/$(basename "$i")
  2074. if [ -f "$profile"/etc/profile ]; then
  2075. GUIX_PROFILE="$profile"
  2076. . "$GUIX_PROFILE"/etc/profile
  2077. fi
  2078. unset profile
  2079. done
  2080. @end example
  2081. When a profile is off, it's straightforward to enable it for an individual shell
  2082. without "polluting" the rest of the user session:
  2083. @example
  2084. GUIX_PROFILE="path/to/my-project" ; . "$GUIX_PROFILE"/etc/profile
  2085. @end example
  2086. The key to enabling a profile is to @emph{source} its @samp{etc/profile} file. This file
  2087. contains shell code that exports the right environment variables necessary to
  2088. activate the software contained in the profile. It is built automatically by
  2089. Guix and meant to be sourced.
  2090. It contains the same variables you would get if you ran:
  2091. @example
  2092. guix package --search-paths=prefix --profile=$my_profile"
  2093. @end example
  2094. Once again, see (@pxref{Invoking guix package,,, guix, GNU Guix Reference Manual})
  2095. for the command line options.
  2096. To upgrade a profile, simply install the manifest again:
  2097. @example
  2098. guix package -m /path/to/guix-my-project-manifest.scm -p "$GUIX_EXTRA_PROFILES"/my-project/my-project
  2099. @end example
  2100. To upgrade all profiles, it's easy enough to loop over them. For instance,
  2101. assuming your manifest specifications are stored in
  2102. @file{~/.guix-manifests/guix-$profile-manifest.scm}, with @samp{$profile} being the name
  2103. of the profile (e.g.@: "project1"), you could do the following in Bourne shell:
  2104. @example
  2105. for profile in "$GUIX_EXTRA_PROFILES"/*; do
  2106. guix package --profile="$profile" --manifest="$HOME/.guix-manifests/guix-$profile-manifest.scm"
  2107. done
  2108. @end example
  2109. Each profile has its own generations:
  2110. @example
  2111. guix package -p "$GUIX_EXTRA_PROFILES"/my-project/my-project --list-generations
  2112. @end example
  2113. You can roll-back to any generation of a given profile:
  2114. @example
  2115. guix package -p "$GUIX_EXTRA_PROFILES"/my-project/my-project --switch-generations=17
  2116. @end example
  2117. Finally, if you want to switch to a profile without inheriting from the
  2118. current environment, you can activate it from an empty shell:
  2119. @example
  2120. env -i $(which bash) --login --noprofile --norc
  2121. . my-project/etc/profile
  2122. @end example
  2123. @node Required packages
  2124. @subsection Required packages
  2125. Activating a profile essentially boils down to exporting a bunch of
  2126. environmental variables. This is the role of the @samp{etc/profile} within the
  2127. profile.
  2128. @emph{Note: Only the environmental variables of the packages that consume them will
  2129. be set.}
  2130. For instance, @samp{MANPATH} won't be set if there is no consumer application for man
  2131. pages within the profile. So if you need to transparently access man pages once
  2132. the profile is loaded, you've got two options:
  2133. @itemize
  2134. @item
  2135. Either export the variable manually, e.g.
  2136. @example
  2137. export MANPATH=/path/to/profile$@{MANPATH:+:@}$MANPATH
  2138. @end example
  2139. @item
  2140. Or include @samp{man-db} to the profile manifest.
  2141. @end itemize
  2142. The same is true for @samp{INFOPATH} (you can install @samp{info-reader}),
  2143. @samp{PKG_CONFIG_PATH} (install @samp{pkg-config}), etc.
  2144. @node Default profile
  2145. @subsection Default profile
  2146. What about the default profile that Guix keeps in @file{~/.guix-profile}?
  2147. You can assign it the role you want. Typically you would install the manifest
  2148. of the packages you want to use all the time.
  2149. Alternatively, you could keep it ``manifest-less'' for throw-away packages
  2150. that you would just use for a couple of days.
  2151. This way makes it convenient to run
  2152. @example
  2153. guix install package-foo
  2154. guix upgrade package-bar
  2155. @end example
  2156. without having to specify the path to a profile.
  2157. @node The benefits of manifests
  2158. @subsection The benefits of manifests
  2159. Manifests are a convenient way to keep your package lists around and, say,
  2160. to synchronize them across multiple machines using a version control system.
  2161. A common complaint about manifests is that they can be slow to install when they
  2162. contain large number of packages. This is especially cumbersome when you just
  2163. want get an upgrade for one package within a big manifest.
  2164. This is one more reason to use multiple profiles, which happen to be just
  2165. perfect to break down manifests into multiple sets of semantically connected
  2166. packages. Using multiple, small profiles provides more flexibility and
  2167. usability.
  2168. Manifests come with multiple benefits. In particular, they ease maintenance:
  2169. @itemize
  2170. @item
  2171. When a profile is set up from a manifest, the manifest itself is
  2172. self-sufficient to keep a ``package listing'' around and reinstall the profile
  2173. later or on a different system. For ad-hoc profiles, we would need to
  2174. generate a manifest specification manually and maintain the package versions
  2175. for the packages that don't use the default version.
  2176. @item
  2177. @code{guix package --upgrade} always tries to update the packages that have
  2178. propagated inputs, even if there is nothing to do. Guix manifests remove this
  2179. problem.
  2180. @item
  2181. When partially upgrading a profile, conflicts may arise (due to diverging
  2182. dependencies between the updated and the non-updated packages) and they can be
  2183. annoying to resolve manually. Manifests remove this problem altogether since
  2184. all packages are always upgraded at once.
  2185. @item
  2186. As mentioned above, manifests allow for reproducible profiles, while the
  2187. imperative @code{guix install}, @code{guix upgrade}, etc. do not, since they produce
  2188. different profiles every time even when they hold the same packages. See
  2189. @uref{https://issues.guix.gnu.org/issue/33285, the related discussion on the matter}.
  2190. @item
  2191. Manifest specifications are usable by other @samp{guix} commands. For example, you
  2192. can run @code{guix weather -m manifest.scm} to see how many substitutes are
  2193. available, which can help you decide whether you want to try upgrading today
  2194. or wait a while. Another example: you can run @code{guix pack -m manifest.scm} to
  2195. create a pack containing all the packages in the manifest (and their
  2196. transitive references).
  2197. @item
  2198. Finally, manifests have a Scheme representation, the @samp{<manifest>} record type.
  2199. They can be manipulated in Scheme and passed to the various Guix @uref{https://en.wikipedia.org/wiki/Api, APIs}.
  2200. @end itemize
  2201. It's important to understand that while manifests can be used to declare
  2202. profiles, they are not strictly equivalent: profiles have the side effect that
  2203. they ``pin'' packages in the store, which prevents them from being
  2204. garbage-collected (@pxref{Invoking guix gc,,, guix, GNU Guix Reference Manual})
  2205. and ensures that they will still be available at any point in
  2206. the future.
  2207. Let's take an example:
  2208. @enumerate
  2209. @item
  2210. We have an environment for hacking on a project for which there isn't a Guix
  2211. package yet. We build the environment using a manifest, and then run @code{guix
  2212. environment -m manifest.scm}. So far so good.
  2213. @item
  2214. Many weeks pass and we have run a couple of @code{guix pull} in the mean time.
  2215. Maybe a dependency from our manifest has been updated; or we may have run
  2216. @code{guix gc} and some packages needed by our manifest have been
  2217. garbage-collected.
  2218. @item
  2219. Eventually, we set to work on that project again, so we run @code{guix environment
  2220. -m manifest.scm}. But now we have to wait for Guix to build and install
  2221. stuff!
  2222. @end enumerate
  2223. Ideally, we could spare the rebuild time. And indeed we can, all we need is to
  2224. install the manifest to a profile and use @code{GUIX_PROFILE=/the/profile;
  2225. . "$GUIX_PROFILE"/etc/profile} as explained above: this guarantees that our
  2226. hacking environment will be available at all times.
  2227. @emph{Security warning:} While keeping old profiles around can be convenient, keep in
  2228. mind that outdated packages may not have received the latest security fixes.
  2229. @node Reproducible profiles
  2230. @subsection Reproducible profiles
  2231. To reproduce a profile bit-for-bit, we need two pieces of information:
  2232. @itemize
  2233. @item
  2234. a manifest,
  2235. @item
  2236. a Guix channel specification.
  2237. @end itemize
  2238. Indeed, manifests alone might not be enough: different Guix versions (or
  2239. different channels) can produce different outputs for a given manifest.
  2240. You can output the Guix channel specification with @samp{guix describe
  2241. --format=channels}.
  2242. Save this to a file, say @samp{channel-specs.scm}.
  2243. On another computer, you can use the channel specification file and the manifest
  2244. to reproduce the exact same profile:
  2245. @example
  2246. GUIX_EXTRA_PROFILES=$HOME/.guix-extra-profiles
  2247. GUIX_EXTRA=$HOME/.guix-extra
  2248. mkdir "$GUIX_EXTRA"/my-project
  2249. guix pull --channels=channel-specs.scm --profile "$GUIX_EXTRA/my-project/guix"
  2250. mkdir -p "$GUIX_EXTRA_PROFILES/my-project"
  2251. "$GUIX_EXTRA"/my-project/guix/bin/guix package --manifest=/path/to/guix-my-project-manifest.scm --profile="$GUIX_EXTRA_PROFILES"/my-project/my-project
  2252. @end example
  2253. It's safe to delete the Guix channel profile you've just installed with the
  2254. channel specification, the project profile does not depend on it.
  2255. @c *********************************************************************
  2256. @node Environment management
  2257. @chapter Environment management
  2258. Guix provides multiple tools to manage environment. This chapter
  2259. demonstrate such utilities.
  2260. @menu
  2261. * Guix environment via direnv:: Setup Guix environment with direnv
  2262. @end menu
  2263. @node Guix environment via direnv
  2264. @section Guix environment via direnv
  2265. Guix provides a @samp{direnv} package, which could extend shell after
  2266. directory change. This tool could be used to prepare a pure Guix
  2267. environment.
  2268. The following example provides a shell function for @file{~/.direnvrc}
  2269. file, which could be used from Guix Git repository in
  2270. @file{~/src/guix/.envrc} file to setup a build environment similar to
  2271. described in @pxref{Building from Git,,, guix, GNU Guix Reference
  2272. Manual}.
  2273. Create a @file{~/.direnvrc} with a Bash code:
  2274. @example
  2275. # Thanks <https://github.com/direnv/direnv/issues/73#issuecomment-152284914>
  2276. export_function()
  2277. @{
  2278. local name=$1
  2279. local alias_dir=$PWD/.direnv/aliases
  2280. mkdir -p "$alias_dir"
  2281. PATH_add "$alias_dir"
  2282. local target="$alias_dir/$name"
  2283. if declare -f "$name" >/dev/null; then
  2284. echo "#!$SHELL" > "$target"
  2285. declare -f "$name" >> "$target" 2>/dev/null
  2286. # Notice that we add shell variables to the function trigger.
  2287. echo "$name \$*" >> "$target"
  2288. chmod +x "$target"
  2289. fi
  2290. @}
  2291. use_guix()
  2292. @{
  2293. # Set GitHub token.
  2294. export GUIX_GITHUB_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  2295. # Unset 'GUIX_PACKAGE_PATH'.
  2296. export GUIX_PACKAGE_PATH=""
  2297. # Recreate a garbage collector root.
  2298. gcroots="$HOME/.config/guix/gcroots"
  2299. mkdir -p "$gcroots"
  2300. gcroot="$gcroots/guix"
  2301. if [ -L "$gcroot" ]
  2302. then
  2303. rm -v "$gcroot"
  2304. fi
  2305. # Miscellaneous packages.
  2306. PACKAGES_MAINTENANCE=(
  2307. direnv
  2308. git
  2309. git:send-email
  2310. git-cal
  2311. gnupg
  2312. guile-colorized
  2313. guile-readline
  2314. less
  2315. ncurses
  2316. openssh
  2317. xdot
  2318. )
  2319. # Environment packages.
  2320. PACKAGES=(help2man guile-sqlite3 guile-gcrypt)
  2321. # Thanks <https://lists.gnu.org/archive/html/guix-devel/2016-09/msg00859.html>
  2322. eval "$(guix environment --search-paths --root="$gcroot" --pure guix --ad-hoc $@{PACKAGES[@@]@} $@{PACKAGES_MAINTENANCE[@@]@} "$@@")"
  2323. # Predefine configure flags.
  2324. configure()
  2325. @{
  2326. ./configure --localstatedir=/var --prefix=
  2327. @}
  2328. export_function configure
  2329. # Run make and optionally build something.
  2330. build()
  2331. @{
  2332. make -j 2
  2333. if [ $# -gt 0 ]
  2334. then
  2335. ./pre-inst-env guix build "$@@"
  2336. fi
  2337. @}
  2338. export_function build
  2339. # Predefine push Git command.
  2340. push()
  2341. @{
  2342. git push --set-upstream origin
  2343. @}
  2344. export_function push
  2345. clear # Clean up the screen.
  2346. git-cal --author='Your Name' # Show contributions calendar.
  2347. # Show commands help.
  2348. echo "
  2349. build build a package or just a project if no argument provided
  2350. configure run ./configure with predefined parameters
  2351. push push to upstream Git repository
  2352. "
  2353. @}
  2354. @end example
  2355. Every project containing @file{.envrc} with a string @code{use guix}
  2356. will have predefined environment variables and procedures.
  2357. Run @command{direnv allow} to setup the environment for the first time.
  2358. @c *********************************************************************
  2359. @node Acknowledgments
  2360. @chapter Acknowledgments
  2361. Guix is based on the @uref{https://nixos.org/nix/, Nix package manager},
  2362. which was designed and
  2363. implemented by Eelco Dolstra, with contributions from other people (see
  2364. the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
  2365. management, and promoted unprecedented features, such as transactional
  2366. package upgrades and rollbacks, per-user profiles, and referentially
  2367. transparent build processes. Without this work, Guix would not exist.
  2368. The Nix-based software distributions, Nixpkgs and NixOS, have also been
  2369. an inspiration for Guix.
  2370. GNU@tie{}Guix itself is a collective work with contributions from a
  2371. number of people. See the @file{AUTHORS} file in Guix for more
  2372. information on these fine people. The @file{THANKS} file lists people
  2373. who have helped by reporting bugs, taking care of the infrastructure,
  2374. providing artwork and themes, making suggestions, and more---thank you!
  2375. This document includes adapted sections from articles that have previously
  2376. been published on the Guix blog at @uref{https://guix.gnu.org/blog}.
  2377. @c *********************************************************************
  2378. @node GNU Free Documentation License
  2379. @appendix GNU Free Documentation License
  2380. @cindex license, GNU Free Documentation License
  2381. @include fdl-1.3.texi
  2382. @c *********************************************************************
  2383. @node Concept Index
  2384. @unnumbered Concept Index
  2385. @printindex cp
  2386. @bye
  2387. @c Local Variables:
  2388. @c ispell-local-dictionary: "american";
  2389. @c End: