guix-cookbook.texi 105 KB

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