path: root/bootstrap
blob: a47269d87f1d6fd27bbaf634ac7439b38b32cca3 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh
# Create the build system.

set -e -x

# Generate stubs for translations.
langs=`find po/doc -type f -name 'guix-manual*.po' \
        | sed -e 's,guix-manual\.,,' \
        | xargs -n 1 -I{} basename {} .po`
for lang in ${langs}; do
    if [ ! -e "doc/guix.${lang}.texi" ]; then
	echo "@setfilename guix.${lang}.info" > "doc/guix.${lang}.texi"
	echo "@include version-${lang}.texi" >> "doc/guix.${lang}.texi"
	# Ensure .po file is newer.
	touch "po/doc/guix-manual.${lang}.po"
    fi
done
langs=`find po/doc -type f -name 'guix-cookbook*.po' \
        | sed -e 's,guix-cookbook\.,,' \
        | xargs -n 1 -I{} basename {} .po`
for lang in ${langs}; do
    if [ ! -e "doc/guix-cookbook.${lang}.texi" ]; then
	echo "@setfilename guix-cookbook.${lang}.info" > "doc/guix-cookbook.${lang}.texi"
	# Ensure .po file is newer.
	touch "po/doc/guix-cookbook.${lang}.po"
    fi
done

exec autoreconf -vfi
(define etc (string-append root "/etc")) (define (salt) ;; "$6" gives us a SHA512 password hash; the random string must be taken ;; from the './0-9A-Za-z' alphabet (info "(libc) Passphrase Storage"). (string-append "$6$" (random-string 10))) (define users* (map (lambda (user) (define root? (string=? "root" (user-name user))) (sys:user-account (name (user-name user)) (comment (user-real-name user)) (group "users") (uid (if root? 0 #f)) (home-directory (user-home-directory user)) (password (crypt (secret-content (user-password user)) (salt))) ;; We need a string here, not a file-like, hence ;; this choice. (shell "/run/current-system/profile/bin/bash"))) users)) (define-values (group password shadow) (user+group-databases users* sys:%base-groups #:current-passwd '() #:current-groups '() #:current-shadow '())) (mkdir-p etc) (write-group group (string-append etc "/group")) (write-passwd password (string-append etc "/passwd")) (write-shadow shadow (string-append etc "/shadow"))) (define (call-with-mnt-container thunk) "This is a variant of call-with-container. Run THUNK in a new container process, within a separate MNT namespace. The container is not jailed so that it can interact with the rest of the system." (let ((pid (run-container "/" '() '(mnt) 1 thunk))) ;; Catch SIGINT and kill the container process. (sigaction SIGINT (lambda (signum) ;: FIXME: Use of SIGKILL prevents the dynamic-wind exit handler of ;; THUNK to run. (false-if-exception (kill pid SIGKILL)))) (match (waitpid pid) ((_ . status) status)))) (define (install-locale locale) "Install the given LOCALE or the en_US.utf8 locale as a fallback." (let ((supported? (false-if-exception (setlocale LC_ALL locale)))) (if supported? (begin (installer-log-line "install supported locale ~a." locale) (setenv "LC_ALL" locale)) (begin ;; If the selected locale is not supported, install a default UTF-8 ;; locale. This is required to copy some files with UTF-8 ;; characters, in the nss-certs package notably. Set LANGUAGE ;; anyways, to have translated messages if possible. (installer-log-line "~a locale is not supported, installing \ en_US.utf8 locale instead." locale) (setlocale LC_ALL "en_US.utf8") (setenv "LC_ALL" "en_US.utf8") (setenv "LANGUAGE" (string-take locale (or (string-index locale #\_) (string-length locale)))))))) (define* (install-system locale #:key (users '())) "Create /etc/shadow and /etc/passwd on the installation target for USERS. Start COW-STORE service on target directory and launch guix install command in a subshell. LOCALE must be the locale name under which that command will run, or #f. Return #t on success and #f on failure." (define backing-directory ;; Sub-directory used as the backing store for copy-on-write. "/tmp/guix-inst") (define (assert-exit x) (primitive-exit (if x 0 1))) (let* ((options (catch 'system-error (lambda () ;; If this file exists, it can provide ;; additional command-line options. (call-with-input-file "/tmp/installer-system-init-options" read)) (const '()))) (install-command (append `( "guix" "system" "init" "--fallback" ,@(if (target-hurd?) '("--target=i586-pc-gnu") '())) options (list (%installer-configuration-file) (%installer-target-dir)))) (database-dir "/var/guix/db") (database-file (string-append database-dir "/db.sqlite")) (saved-database (string-append database-dir "/db.save")) (ret #f)) (mkdir-p (%installer-target-dir)) ;; We want to initialize user passwords but we don't want to store them in ;; the config file since the password hashes would end up world-readable ;; in the store. Thus, create /etc/shadow & co. here such that, on the ;; first boot, the activation snippet that creates accounts will reuse the ;; passwords that we've put in there. (create-user-database users (%installer-target-dir)) ;; When the store overlay is mounted, other processes such as kmscon, udev ;; and guix-daemon may open files from the store, preventing the ;; underlying install support from being umounted. See: ;; https://lists.gnu.org/archive/html/guix-devel/2018-12/msg00161.html. ;; ;; To avoid this situation, mount the store overlay inside a container, ;; and run the installation from within that container. (zero? (call-with-mnt-container (lambda () (dynamic-wind (lambda () ;; Install the locale before mounting the cow-store, otherwise ;; the loaded cow-store locale files will prevent umounting. (install-locale locale) ;; Stop the daemon and save the database, so that it can be ;; restored once the cow-store is umounted. (stop-service 'guix-daemon) (copy-file database-file saved-database) (installer-log-line "mounting copy-on-write store") (mount-cow-store (%installer-target-dir) backing-directory)) (lambda () ;; We need to drag the guix-daemon to the container MNT ;; namespace, so that it can operate on the cow-store. (start-service 'guix-daemon (list (number->string (getpid)))) (setvbuf (current-output-port) 'none) (setvbuf (current-error-port) 'none) (setenv "PATH" "/run/current-system/profile/bin/") (set! ret (run-command install-command #:tty? #t))) (lambda () ;; Stop guix-daemon so that it does no keep the MNT namespace ;; alive. (stop-service 'guix-daemon) ;; Restore the database and restart it. As part of restoring the ;; database, remove the WAL and shm files in case they were left ;; behind after guix-daemon was stopped. Failing to do so, ;; sqlite might behave as if transactions that appear in the WAL ;; file were committed. (See <https://www.sqlite.org/wal.html>.) (installer-log-line "restoring store database from '~a'" saved-database) (copy-file saved-database database-file) (for-each (lambda (suffix) (false-if-exception (delete-file (string-append database-file suffix)))) '("-wal" "-shm")) (start-service 'guix-daemon) ;; Finally umount the cow-store and exit the container. (installer-log-line "unmounting copy-on-write store") (unmount-cow-store (%installer-target-dir) backing-directory) (assert-exit ret))))))))