install.scm 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2016 Andreas Enge <andreas@enge.fr>
  5. ;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
  6. ;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (gnu system install)
  23. #:use-module (gnu)
  24. #:use-module (gnu system)
  25. #:use-module (gnu bootloader u-boot)
  26. #:use-module (guix gexp)
  27. #:use-module (guix store)
  28. #:use-module (guix monads)
  29. #:use-module ((guix store) #:select (%store-prefix))
  30. #:use-module (gnu installer)
  31. #:use-module (gnu services dbus)
  32. #:use-module (gnu services networking)
  33. #:use-module (gnu services shepherd)
  34. #:use-module (gnu services ssh)
  35. #:use-module (gnu packages admin)
  36. #:use-module (gnu packages bash)
  37. #:use-module (gnu packages bootloaders)
  38. #:use-module (gnu packages certs)
  39. #:use-module (gnu packages fonts)
  40. #:use-module (gnu packages fontutils)
  41. #:use-module (gnu packages guile)
  42. #:use-module (gnu packages linux)
  43. #:use-module (gnu packages ssh)
  44. #:use-module (gnu packages cryptsetup)
  45. #:use-module (gnu packages package-management)
  46. #:use-module (gnu packages disk)
  47. #:use-module (gnu packages texinfo)
  48. #:use-module (gnu packages compression)
  49. #:use-module (gnu packages nvi)
  50. #:use-module (ice-9 match)
  51. #:use-module (srfi srfi-26)
  52. #:export (installation-os
  53. a20-olinuxino-lime-installation-os
  54. a20-olinuxino-lime2-emmc-installation-os
  55. a20-olinuxino-micro-installation-os
  56. bananapi-m2-ultra-installation-os
  57. beaglebone-black-installation-os
  58. mx6cuboxi-installation-os
  59. nintendo-nes-classic-edition-installation-os
  60. novena-installation-os
  61. pine64-plus-installation-os
  62. pinebook-installation-os
  63. rk3399-puma-installation-os
  64. wandboard-installation-os
  65. os-with-u-boot))
  66. ;;; Commentary:
  67. ;;;
  68. ;;; This module provides an 'operating-system' definition for use on images
  69. ;;; for USB sticks etc., for the installation of the GNU system.
  70. ;;;
  71. ;;; Code:
  72. (define (log-to-info)
  73. "Return a script that spawns the Info reader on the right section of the
  74. manual."
  75. (program-file "log-to-info"
  76. #~(begin
  77. ;; 'gunzip' is needed to decompress the doc.
  78. (setenv "PATH" (string-append #$gzip "/bin"))
  79. (execl (string-append #$info-reader "/bin/info") "info"
  80. "-d" "/run/current-system/profile/share/info"
  81. "-f" (string-append #$guix "/share/info/guix.info")
  82. "-n" "System Installation"))))
  83. (define %backing-directory
  84. ;; Sub-directory used as the backing store for copy-on-write.
  85. "/tmp/guix-inst")
  86. (define (make-cow-store target)
  87. "Return a gexp that makes the store copy-on-write, using TARGET as the
  88. backing store. This is useful when TARGET is on a hard disk, whereas the
  89. current store is on a RAM disk."
  90. (define (set-store-permissions directory)
  91. ;; Set the right perms on DIRECTORY to use it as the store.
  92. #~(begin
  93. (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
  94. (chmod #$directory #o1775)))
  95. #~(begin
  96. ;; Bind-mount TARGET's /tmp in case we need space to build things.
  97. (let ((tmpdir (string-append #$target "/tmp")))
  98. (mkdir-p tmpdir)
  99. (mount tmpdir "/tmp" "none" MS_BIND))
  100. (let* ((rw-dir (string-append target #$%backing-directory))
  101. (work-dir (string-append rw-dir "/../.overlayfs-workdir")))
  102. (mkdir-p rw-dir)
  103. (mkdir-p work-dir)
  104. (mkdir-p "/.rw-store")
  105. #$(set-store-permissions #~rw-dir)
  106. #$(set-store-permissions "/.rw-store")
  107. ;; Mount the overlay, then atomically make it the store.
  108. (mount "none" "/.rw-store" "overlay" 0
  109. (string-append "lowerdir=" #$(%store-prefix) ","
  110. "upperdir=" rw-dir ","
  111. "workdir=" work-dir))
  112. (mount "/.rw-store" #$(%store-prefix) "" MS_MOVE)
  113. (rmdir "/.rw-store"))))
  114. (define cow-store-service-type
  115. (shepherd-service-type
  116. 'cow-store
  117. (lambda _
  118. (shepherd-service
  119. (requirement '(root-file-system user-processes))
  120. (provision '(cow-store))
  121. (documentation
  122. "Make the store copy-on-write, with writes going to \
  123. the given target.")
  124. ;; This is meant to be explicitly started by the user.
  125. (auto-start? #f)
  126. (start #~(case-lambda
  127. ((target)
  128. #$(make-cow-store #~target)
  129. target)
  130. (else
  131. ;; Do nothing, and mark the service as stopped.
  132. #f)))
  133. (stop #~(lambda (target)
  134. ;; Delete the temporary directory, but leave everything
  135. ;; mounted as there may still be processes using it since
  136. ;; 'user-processes' doesn't depend on us. The 'user-file-systems'
  137. ;; service will unmount TARGET eventually.
  138. (delete-file-recursively
  139. (string-append target #$%backing-directory))))))))
  140. (define (cow-store-service)
  141. "Return a service that makes the store copy-on-write, such that writes go to
  142. the user's target storage device rather than on the RAM disk."
  143. ;; See <http://bugs.gnu.org/18061> for the initial report.
  144. (service cow-store-service-type 'mooooh!))
  145. (define (/etc/configuration-files _)
  146. "Return a list of tuples representing configuration templates to add to
  147. /etc."
  148. (define (file f)
  149. (local-file (string-append "examples/" f)))
  150. (define directory
  151. (computed-file "configuration-templates"
  152. (with-imported-modules '((guix build utils))
  153. #~(begin
  154. (mkdir #$output)
  155. (for-each (lambda (file target)
  156. (copy-file file
  157. (string-append #$output "/"
  158. target)))
  159. '(#$(file "bare-bones.tmpl")
  160. #$(file "beaglebone-black.tmpl")
  161. #$(file "desktop.tmpl")
  162. #$(file "lightweight-desktop.tmpl"))
  163. '("bare-bones.scm"
  164. "beaglebone-black.scm"
  165. "desktop.scm"
  166. "lightweight-desktop.scm"))
  167. #t))))
  168. `(("configuration" ,directory)))
  169. (define configuration-template-service-type
  170. (service-type (name 'configuration-template)
  171. (extensions
  172. (list (service-extension etc-service-type
  173. /etc/configuration-files)))))
  174. (define %configuration-template-service
  175. (service configuration-template-service-type #t))
  176. (define %nscd-minimal-caches
  177. ;; Minimal in-memory caching policy for nscd.
  178. (list (nscd-cache (database 'hosts)
  179. (positive-time-to-live (* 3600 12))
  180. ;; Do not cache lookup failures at all since they are
  181. ;; quite likely (for instance when someone tries to ping a
  182. ;; host before networking is functional.)
  183. (negative-time-to-live 0)
  184. (persistent? #f)
  185. (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
  186. (define %installation-services
  187. ;; List of services of the installation system.
  188. (let ((motd (plain-file "motd" "
  189. \x1b[1;37mWelcome to the installation of the Guix System Distribution!\x1b[0m
  190. \x1b[2mThere is NO WARRANTY, to the extent permitted by law. In particular, you may
  191. LOSE ALL YOUR DATA as a side effect of the installation process. Furthermore,
  192. it is 'beta' software, so it may contain bugs.
  193. You have been warned. Thanks for being so brave.\x1b[0m
  194. ")))
  195. (define (normal-tty tty)
  196. (mingetty-service (mingetty-configuration (tty tty)
  197. (auto-login "root")
  198. (login-pause? #t))))
  199. (define bare-bones-os
  200. (load "examples/bare-bones.tmpl"))
  201. (list (service virtual-terminal-service-type)
  202. (service kmscon-service-type
  203. (kmscon-configuration
  204. (virtual-terminal "tty1")
  205. (login-program (installer-program))))
  206. (login-service (login-configuration
  207. (motd motd)))
  208. ;; Documentation. The manual is in UTF-8, but
  209. ;; 'console-font-service' sets up Unicode support and loads a font
  210. ;; with all the useful glyphs like em dash and quotation marks.
  211. (mingetty-service (mingetty-configuration
  212. (tty "tty2")
  213. (auto-login "guest")
  214. (login-program (log-to-info))))
  215. ;; Documentation add-on.
  216. %configuration-template-service
  217. ;; A bunch of 'root' ttys.
  218. (normal-tty "tty3")
  219. (normal-tty "tty4")
  220. (normal-tty "tty5")
  221. (normal-tty "tty6")
  222. ;; The usual services.
  223. (syslog-service)
  224. ;; The build daemon. Register the hydra.gnu.org key as trusted.
  225. ;; This allows the installation process to use substitutes by
  226. ;; default.
  227. (service guix-service-type
  228. (guix-configuration (authorize-key? #t)))
  229. ;; Start udev so that useful device nodes are available.
  230. ;; Use device-mapper rules for cryptsetup & co; enable the CRDA for
  231. ;; regulations-compliant WiFi access.
  232. (udev-service #:rules (list lvm2 crda))
  233. ;; Add the 'cow-store' service, which users have to start manually
  234. ;; since it takes the installation directory as an argument.
  235. (cow-store-service)
  236. ;; Install Unicode support and a suitable font. Use a font that
  237. ;; doesn't have more than 256 glyphs so that we can use colors with
  238. ;; varying brightness levels (see note in setfont(8)).
  239. (service console-font-service-type
  240. (map (lambda (tty)
  241. (cons tty "lat9u-16"))
  242. '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
  243. ;; To facilitate copy/paste.
  244. (service gpm-service-type)
  245. ;; Add an SSH server to facilitate remote installs.
  246. (service openssh-service-type
  247. (openssh-configuration
  248. (port-number 22)
  249. (permit-root-login #t)
  250. ;; The root account is passwordless, so make sure
  251. ;; a password is set before allowing logins.
  252. (allow-empty-passwords? #f)
  253. (password-authentication? #t)
  254. ;; Don't start it upfront.
  255. (%auto-start? #f)))
  256. ;; Since this is running on a USB stick with a overlayfs as the root
  257. ;; file system, use an appropriate cache configuration.
  258. (nscd-service (nscd-configuration
  259. (caches %nscd-minimal-caches)))
  260. ;; Having /bin/sh is a good idea. In particular it allows Tramp
  261. ;; connections to this system to work.
  262. (service special-files-service-type
  263. `(("/bin/sh" ,(file-append (canonical-package bash)
  264. "/bin/sh"))))
  265. ;; Loopback device, needed by OpenSSH notably.
  266. (service static-networking-service-type
  267. (list (static-networking (interface "lo")
  268. (ip "127.0.0.1")
  269. (requirement '())
  270. (provision '(loopback)))))
  271. (service wpa-supplicant-service-type)
  272. (dbus-service)
  273. (service connman-service-type
  274. (connman-configuration
  275. (disable-vpn? #t)))
  276. ;; Keep a reference to BARE-BONES-OS to make sure it can be
  277. ;; installed without downloading/building anything. Also keep the
  278. ;; things needed by 'profile-derivation' to minimize the amount of
  279. ;; download.
  280. (service gc-root-service-type
  281. (list bare-bones-os
  282. glibc-utf8-locales
  283. texinfo
  284. (canonical-package guile-2.2))))))
  285. (define %issue
  286. ;; Greeting.
  287. "
  288. \x1b[1;37mThis is an installation image of the GNU system. Welcome.\x1b[0m
  289. \x1b[1;33mUse Alt-F2 for documentation.\x1b[0m
  290. ")
  291. (define installation-os
  292. ;; The operating system used on installation images for USB sticks etc.
  293. (operating-system
  294. (host-name "gnu")
  295. (timezone "Europe/Paris")
  296. (locale "en_US.utf8")
  297. (bootloader (bootloader-configuration
  298. (bootloader grub-bootloader)
  299. (target "/dev/sda")))
  300. (file-systems
  301. ;; Note: the disk image build code overrides this root file system with
  302. ;; the appropriate one.
  303. (cons* (file-system
  304. (mount-point "/")
  305. (device (file-system-label "GuixSD_image"))
  306. (type "ext4"))
  307. ;; Make /tmp a tmpfs instead of keeping the overlayfs. This
  308. ;; originally was used for unionfs because FUSE creates
  309. ;; '.fuse_hiddenXYZ' files for each open file, and this confuses
  310. ;; Guix's test suite, for instance (see
  311. ;; <http://bugs.gnu.org/23056>). We keep this for overlayfs to be
  312. ;; on the safe side.
  313. (file-system
  314. (mount-point "/tmp")
  315. (device "none")
  316. (type "tmpfs")
  317. (check? #f))
  318. ;; XXX: This should be %BASE-FILE-SYSTEMS but we don't need
  319. ;; elogind's cgroup file systems.
  320. (list %pseudo-terminal-file-system
  321. %shared-memory-file-system
  322. %immutable-store)))
  323. (users (list (user-account
  324. (name "guest")
  325. (group "users")
  326. (supplementary-groups '("wheel")) ; allow use of sudo
  327. (password "")
  328. (comment "Guest of GNU")
  329. (home-directory "/home/guest"))))
  330. (issue %issue)
  331. (services %installation-services)
  332. ;; We don't need setuid programs, except for 'passwd', which can be handy
  333. ;; if one is to allow remote SSH login to the machine being installed.
  334. (setuid-programs (list (file-append shadow "/bin/passwd")))
  335. (pam-services
  336. ;; Explicitly allow for empty passwords.
  337. (base-pam-services #:allow-empty-passwords? #t))
  338. (packages (cons* (canonical-package glibc) ;for 'tzselect' & co.
  339. parted gptfdisk ddrescue
  340. fontconfig
  341. font-dejavu font-gnu-unifont
  342. grub ;mostly so xrefs to its manual work
  343. cryptsetup
  344. mdadm
  345. dosfstools ;mkfs.fat, for the UEFI boot partition
  346. btrfs-progs
  347. openssh ;we already have sshd, having ssh/scp can help
  348. wireless-tools iw wpa-supplicant-minimal iproute
  349. ;; XXX: We used to have GNU fdisk here, but as of version
  350. ;; 2.0.0a, that pulls Guile 1.8, which takes unreasonable
  351. ;; space; furthermore util-linux's fdisk is already
  352. ;; available here, so we keep that.
  353. bash-completion
  354. nvi ;:wq!
  355. nss-certs ; To access HTTPS, use git, etc.
  356. %base-packages))))
  357. (define* (os-with-u-boot os board #:key (bootloader-target "/dev/mmcblk0")
  358. (triplet "arm-linux-gnueabihf"))
  359. "Given OS, amend it with the u-boot bootloader for BOARD,
  360. installed to BOOTLOADER-TARGET (a drive), compiled for TRIPLET.
  361. If you want a serial console, make sure to specify one in your
  362. operating-system's kernel-arguments (\"console=ttyS0\" or similar)."
  363. (operating-system (inherit os)
  364. (bootloader (bootloader-configuration
  365. (bootloader (bootloader (inherit u-boot-bootloader)
  366. (package (make-u-boot-package board triplet))))
  367. (target bootloader-target)))))
  368. (define* (embedded-installation-os bootloader bootloader-target tty
  369. #:key (extra-modules '()))
  370. "Return an installation os for embedded systems.
  371. The initrd gets the extra modules EXTRA-MODULES.
  372. A getty is provided on TTY.
  373. The bootloader BOOTLOADER is installed to BOOTLOADER-TARGET."
  374. (operating-system
  375. (inherit installation-os)
  376. (bootloader (bootloader-configuration
  377. (bootloader bootloader)
  378. (target bootloader-target)))
  379. (kernel linux-libre)
  380. (kernel-arguments
  381. (cons (string-append "console=" tty)
  382. (operating-system-user-kernel-arguments installation-os)))
  383. (initrd-modules (append extra-modules %base-initrd-modules))))
  384. (define beaglebone-black-installation-os
  385. (embedded-installation-os u-boot-beaglebone-black-bootloader
  386. "/dev/sda"
  387. "ttyO0"
  388. #:extra-modules
  389. ;; This module is required to mount the sd card.
  390. '("omap_hsmmc")))
  391. (define a20-olinuxino-lime-installation-os
  392. (embedded-installation-os u-boot-a20-olinuxino-lime-bootloader
  393. "/dev/mmcblk0" ; SD card storage
  394. "ttyS0"))
  395. (define a20-olinuxino-lime2-emmc-installation-os
  396. (embedded-installation-os u-boot-a20-olinuxino-lime2-bootloader
  397. "/dev/mmcblk1" ; eMMC storage
  398. "ttyS0"))
  399. (define a20-olinuxino-micro-installation-os
  400. (embedded-installation-os u-boot-a20-olinuxino-micro-bootloader
  401. "/dev/mmcblk0" ; SD card storage
  402. "ttyS0"))
  403. (define bananapi-m2-ultra-installation-os
  404. (embedded-installation-os u-boot-bananapi-m2-ultra-bootloader
  405. "/dev/mmcblk1" ; eMMC storage
  406. "ttyS0"))
  407. (define mx6cuboxi-installation-os
  408. (embedded-installation-os u-boot-mx6cuboxi-bootloader
  409. "/dev/mmcblk0" ; SD card storage
  410. "ttymxc0"))
  411. (define novena-installation-os
  412. (embedded-installation-os u-boot-novena-bootloader
  413. "/dev/mmcblk1" ; SD card storage
  414. "ttymxc1"))
  415. (define nintendo-nes-classic-edition-installation-os
  416. (embedded-installation-os u-boot-nintendo-nes-classic-edition-bootloader
  417. "/dev/mmcblk0" ; SD card (solder it yourself)
  418. "ttyS0"))
  419. (define pine64-plus-installation-os
  420. (embedded-installation-os u-boot-pine64-plus-bootloader
  421. "/dev/mmcblk0" ; SD card storage
  422. "ttyS0"))
  423. (define pinebook-installation-os
  424. (embedded-installation-os u-boot-pinebook-bootloader
  425. "/dev/mmcblk0" ; SD card storage
  426. "ttyS0"))
  427. (define rk3399-puma-installation-os
  428. (embedded-installation-os u-boot-puma-rk3399-bootloader
  429. "/dev/mmcblk0" ; SD card storage
  430. "ttyS0"))
  431. (define wandboard-installation-os
  432. (embedded-installation-os u-boot-wandboard-bootloader
  433. "/dev/mmcblk0" ; SD card storage
  434. "ttymxc0"))
  435. ;; Return the default os here so 'guix system' can consume it directly.
  436. installation-os
  437. ;;; install.scm ends here