From 00b7776c0dc294c26c3b09bff236ccacbedd2080 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 29 Aug 2014 14:13:26 +0200 Subject: gnu: Add nss-mdns. * gnu/packages/avahi.scm (nss-mdns): New variable. --- gnu/packages/avahi.scm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/avahi.scm b/gnu/packages/avahi.scm index d3a92844c2..3f2fdffc28 100644 --- a/gnu/packages/avahi.scm +++ b/gnu/packages/avahi.scm @@ -68,3 +68,25 @@ network. It is an implementation of the mDNS (for \"Multicast DNS\") and DNS-SD (for \"DNS-Based Service Discovery\") protocols.") (license lgpl2.1+))) + +(define-public nss-mdns + (package + (name "nss-mdns") + (version "0.10") + (source (origin + (method url-fetch) + (uri (string-append + "http://0pointer.de/lennart/projects/nss-mdns/nss-mdns-" + version ".tar.gz")) + (sha256 + (base32 + "0vgs6j0qsl0mwzh5a0m0bykr7x6bx79vnbyn0r3q289rghp3qs0y")))) + (build-system gnu-build-system) + (home-page "http://0pointer.de/lennart/projects/nss-mdns/") + (synopsis "The mDNS Name Service Switch (NSS) plug-in") + (description + "'nss-mdns' is a plug-in for the Name Service Switch (NSS) functionality +of the GNU C Library, providing host name resolution via Multicast DNS (mDNS). +It allows for name resolution by programs in the ad-hoc mDNS domain +'.local'.") + (license lgpl2.1+))) -- cgit v1.2.3 From d474d5d0c6ca0aa085e68533b1f16ed29fd10f7c Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 31 Aug 2014 22:18:47 +0200 Subject: gnu: gcc-toolchain: Inherit GCC's search path specifications. Reported by Federico Beffa . * gnu/packages/commencement.scm (gcc-toolchain): Add 'native-search-paths' and 'search-paths' fields. --- gnu/packages/commencement.scm | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm index 6c49d0a9f5..a1d2fcaaed 100644 --- a/gnu/packages/commencement.scm +++ b/gnu/packages/commencement.scm @@ -732,6 +732,10 @@ COREUTILS-FINAL vs. COREUTILS, etc." (union-build (assoc-ref %outputs "debug") (list (assoc-ref %build-inputs "libc-debug")))))) + + (native-search-paths (package-native-search-paths gcc)) + (search-paths (package-search-paths gcc)) + (license (package-license gcc)) (synopsis "Complete GCC tool chain for C/C++ development") (description -- cgit v1.2.3 From 5c97df3ae6657a1798c12059bb9c6b24cb6192ab Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 1 Sep 2014 23:55:23 +0200 Subject: gnu: help2man: Update to 1.46.1. * gnu/packages/man.scm (help2man): Update to 1.46.1. --- gnu/packages/man.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/packages/man.scm b/gnu/packages/man.scm index 2e319a897e..1dbc4c96d5 100644 --- a/gnu/packages/man.scm +++ b/gnu/packages/man.scm @@ -145,7 +145,7 @@ Linux kernel and C library interfaces employed by user-space programs.") (define-public help2man (package (name "help2man") - (version "1.45.1") + (version "1.46.1") (source (origin (method url-fetch) @@ -153,7 +153,7 @@ Linux kernel and C library interfaces employed by user-space programs.") version ".tar.xz")) (sha256 (base32 - "1hk7ciqinq7djdb7s94y3jxh06rp8i93bpjmg4r40cniws8wf3y7")))) + "0iqwb3qirl7rp1wwpbh01q89qxvi4h3bc73wi03av6hl4sh05z9x")))) (build-system gnu-build-system) (arguments `(;; There's no `check' target. #:tests? #f)) -- cgit v1.2.3 From 7239e4119657f44b13879ebfbe37690d1f251758 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 1 Sep 2014 23:56:01 +0200 Subject: gnu: parallel: Update to 20140822. * gnu/packages/parallel.scm (parallel): Update to 20140822. --- gnu/packages/parallel.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/packages/parallel.scm b/gnu/packages/parallel.scm index a4755e043d..92f15adbc4 100644 --- a/gnu/packages/parallel.scm +++ b/gnu/packages/parallel.scm @@ -27,7 +27,7 @@ (define-public parallel (package (name "parallel") - (version "20140722") + (version "20140822") (source (origin (method url-fetch) @@ -35,7 +35,7 @@ version ".tar.bz2")) (sha256 (base32 - "165vf8hpl47z38aswsll1284l8xa9a8jwx3a3d2rzshm9yzbiq5n")))) + "1m3z77fnc2bfissq642p44xgw1jyp00wiwk1slhqj8bipicnl54a")))) (build-system gnu-build-system) (inputs `(("perl" ,perl))) (home-page "http://www.gnu.org/software/parallel/") -- cgit v1.2.3 From f0214ece31b64a17d6e6ed2f8197726f5e8fea86 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 1 Sep 2014 23:57:05 +0200 Subject: gnu: datamash: Update to 1.0.6. * gnu/packages/datamash.scm (datamash): Update to 1.0.6. --- gnu/packages/datamash.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/packages/datamash.scm b/gnu/packages/datamash.scm index 543cd038d3..f44025e2ea 100644 --- a/gnu/packages/datamash.scm +++ b/gnu/packages/datamash.scm @@ -27,7 +27,7 @@ (define-public datamash (package (name "datamash") - (version "1.0.5") + (version "1.0.6") (source (origin (method url-fetch) @@ -35,7 +35,7 @@ version ".tar.gz")) (sha256 (base32 - "0f4rbbhl18fb851npza9cl8biynzr081f37ih2xsbvjlyrxhnz6b")))) + "0621a1xyf8gvcks0vb26g72dm4zh1s6y3a4cc5nnnl5m8mfc4m01")))) (native-inputs `(("which" ,which) ;for tests ("perl" ,perl))) ;for help2man -- cgit v1.2.3 From 86da684c3d9aa96660805edc5c39c68b4faae8ce Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 2 Sep 2014 00:01:11 +0200 Subject: gnu: libtasn1: Update to 4.1. * gnu/packages/gnutls.scm (libtasn1): Update to 4.1. --- gnu/packages/gnutls.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/packages/gnutls.scm b/gnu/packages/gnutls.scm index 03b21c169b..917dfdd228 100644 --- a/gnu/packages/gnutls.scm +++ b/gnu/packages/gnutls.scm @@ -36,7 +36,7 @@ (define-public libtasn1 (package (name "libtasn1") - (version "3.6") + (version "4.1") (source (origin (method url-fetch) @@ -44,7 +44,7 @@ version ".tar.gz")) (sha256 (base32 - "0c547qa1vfk1x2jzgjhf65izf4sfi86c6g46q7779g4aldk4gqqr")))) + "00gkyppzw6fqi5mnc3d8paf7bp6nfhi9213481awy07sviqnbvk0")))) (build-system gnu-build-system) (native-inputs `(("perl" ,perl) -- cgit v1.2.3 From 8b8ea8078124cd4a4a8d2c2effb20577a9c42b66 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 2 Sep 2014 00:01:38 +0200 Subject: gnu: ucommon: Update to 6.1.10. * gnu/packages/telephony.scm (ucommon): Update to 6.1.10. --- gnu/packages/telephony.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/packages/telephony.scm b/gnu/packages/telephony.scm index 363058dd54..b127d70976 100644 --- a/gnu/packages/telephony.scm +++ b/gnu/packages/telephony.scm @@ -56,13 +56,13 @@ reimplementation.") (define-public ucommon (package (name "ucommon") - (version "6.1.8") + (version "6.1.10") (source (origin (method url-fetch) (uri (string-append "mirror://gnu/commoncpp/" name "-" version ".tar.gz")) (sha256 (base32 - "1ibz5snb2gq0psw8z152qcbd1zaijpsksc3lrp6av60inyq3waws")))) + "14myyz4vdq1hzp39k835lk1c9pr4pkhzapsxv50qnh9w3v9mx8fp")))) (build-system gnu-build-system) (synopsis "(u)Common C++ framework for threaded applications") (description "GNU Common C++ is an portable, optimized class framework for -- cgit v1.2.3 From bf2a56f8ecd889817f9e3e0040ad1b48293547ba Mon Sep 17 00:00:00 2001 From: Marek Benc Date: Tue, 2 Sep 2014 15:18:20 +0200 Subject: gnu: Add nvi. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/packages/nvi.scm: New file. * gnu/packages/patches/nvi-assume-preserve-path.patch: New file. * gnu-system.am: Add them. Signed-off-by: Ludovic Courtès --- gnu-system.am | 2 + gnu/packages/nvi.scm | 68 ++++++++++++++++++++++ .../patches/nvi-assume-preserve-path.patch | 30 ++++++++++ 3 files changed, 100 insertions(+) create mode 100644 gnu/packages/nvi.scm create mode 100644 gnu/packages/patches/nvi-assume-preserve-path.patch (limited to 'gnu') diff --git a/gnu-system.am b/gnu-system.am index e439f51fa7..a3f04ec575 100644 --- a/gnu-system.am +++ b/gnu-system.am @@ -180,6 +180,7 @@ GNU_SYSTEM_MODULES = \ gnu/packages/nettle.scm \ gnu/packages/node.scm \ gnu/packages/noweb.scm \ + gnu/packages/nvi.scm \ gnu/packages/ocaml.scm \ gnu/packages/ocrad.scm \ gnu/packages/onc-rpc.scm \ @@ -351,6 +352,7 @@ dist_patch_DATA = \ gnu/packages/patches/mit-krb5-init-fix.patch \ gnu/packages/patches/mpc123-initialize-ao.patch \ gnu/packages/patches/module-init-tools-moduledir.patch \ + gnu/packages/patches/nvi-assume-preserve-path.patch \ gnu/packages/patches/orpheus-cast-errors-and-includes.patch \ gnu/packages/patches/patchelf-page-size.patch \ gnu/packages/patches/patchutils-xfail-gendiff-tests.patch \ diff --git a/gnu/packages/nvi.scm b/gnu/packages/nvi.scm new file mode 100644 index 0000000000..3037e5bafc --- /dev/null +++ b/gnu/packages/nvi.scm @@ -0,0 +1,68 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2014 Marek Benc +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu packages nvi) + #:use-module (gnu packages) + #:use-module (gnu packages bdb) + #:use-module (gnu packages ncurses) + #:use-module (guix packages) + #:use-module (guix download) + #:use-module (guix build-system gnu) + #:use-module (guix licenses)) + +(define-public nvi + (package + (name "nvi") + (version "1.81.6") + (source + (origin + (method url-fetch) + (uri ;; sites.google.coma/bostic.com/keithbostic/vi is stale. + (string-append "http://harrier.slackbuilds.org/misc/nvi-" version + ".tar.bz2")) + (sha256 + (base32 "0nbbs1inyrqds0ywn3ln5slv54v5zraq7lszkg8nsavv4kivhh9l")) + (patches (list (search-patch "nvi-assume-preserve-path.patch"))) + (snippet + ;; Create a wrapper for the configure script, make it executable. + '(let ((conf-wrap (open-output-file "configure"))) + (display "#!/bin/sh" conf-wrap) + (newline conf-wrap) + (display + "../nvi-1.81.6/dist/configure --srcdir=../nvi-1.81.6/dist $@" + conf-wrap) + (newline conf-wrap) + (close-output-port conf-wrap) + (chmod "configure" #o0755))))) + + (build-system gnu-build-system) + (arguments + `(#:out-of-source? #t)) + (inputs + `(("bdb" ,bdb) + ("ncurses" ,ncurses))) + (synopsis "The Berkeley Vi Editor") + (description + "Vi is the original screen based text editor for Unix systems. It is +considered the standard text editor, and is available on almost all Unix +systems. Nvi is intended as a \"bug-for-bug compatible\" clone of the original +BSD vi editor. As such, it doesn't have a lot of snazzy features as do some +of the other vi clones such as elvis and vim. However, if all you want is vi, +this is the one to get.") + (home-page "https://sites.google.com/a/bostic.com/keithbostic/vi") + (license bsd-3))) diff --git a/gnu/packages/patches/nvi-assume-preserve-path.patch b/gnu/packages/patches/nvi-assume-preserve-path.patch new file mode 100644 index 0000000000..18a8f68cca --- /dev/null +++ b/gnu/packages/patches/nvi-assume-preserve-path.patch @@ -0,0 +1,30 @@ +Make configure assume nvi can store backups in /var/tmp. + +--- a/dist/configure 2014-09-01 14:46:01.075778095 +0200 ++++ b/dist/configure 2014-09-01 14:52:08.411790122 +0200 +@@ -21319,23 +21319,8 @@ + if test "${vi_cv_path_preserve+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 + else +- dirlist="/var/preserve /var/tmp /usr/tmp" +- vi_cv_path_preserve=no +- for i in $dirlist; do +- if test -d $i/vi.recover; then +- vi_cv_path_preserve=$i/vi.recover +- break; +- fi +- done +- if test "$vi_cv_path_preserve" = no; then +- for i in $dirlist; do +- if test -d $i -a -w $i; then +- vi_cv_path_preserve=$i/vi.recover +- break; +- fi +- done +- +- fi ++# Assume /var/tmp ++ vi_cv_path_preserve=/var/tmp/vi.recover + fi + + if test "$vi_cv_path_preserve" = no; then -- cgit v1.2.3 From 5e3b388b51780373e68c19a46a279a809e82d461 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Mon, 1 Sep 2014 01:45:09 +0200 Subject: Move specification->package to gnu/packages.scm. * guix/scripts/build.scm (specification->package): Move from here... * gnu/packages.scm: ... to here. --- gnu/packages.scm | 26 +++++++++++++++++++++++++- guix/scripts/build.scm | 23 +---------------------- 2 files changed, 26 insertions(+), 23 deletions(-) (limited to 'gnu') diff --git a/gnu/packages.scm b/gnu/packages.scm index 14ad75561c..26d87c6b16 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm @@ -28,6 +28,7 @@ #:use-module (ice-9 vlist) #:use-module (ice-9 match) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) #:use-module (srfi srfi-39) #:export (search-patch @@ -45,7 +46,9 @@ package-transitive-dependents package-covering-dependents - check-package-freshness)) + check-package-freshness + + specification->package)) ;;; Commentary: ;;; @@ -326,3 +329,24 @@ but ~a is available upstream~%") (case key ((getaddrinfo-error ftp-error) #f) (else (apply throw key args)))))) + +(define (specification->package spec) + "Return a package matching SPEC. SPEC may be a package name, or a package +name followed by a hyphen and a version number. If the version number is not +present, return the preferred newest version." + (let-values (((name version) + (package-name->name+version spec))) + (match (find-best-packages-by-name name version) + ((p) ; one match + p) + ((p x ...) ; several matches + (warning (_ "ambiguous package specification `~a'~%") spec) + (warning (_ "choosing ~a from ~a~%") + (package-full-name p) + (location->string (package-location p))) + p) + (_ ; no matches + (if version + (leave (_ "~A: package not found for version ~a~%") + name version) + (leave (_ "~A: unknown package~%") name)))))) diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm index 5e4647de79..09401e923c 100644 --- a/guix/scripts/build.scm +++ b/guix/scripts/build.scm @@ -33,7 +33,7 @@ #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) #:use-module (srfi srfi-37) - #:autoload (gnu packages) (find-best-packages-by-name) + #:autoload (gnu packages) (specification->package) #:autoload (guix download) (download-to-store) #:export (%standard-build-options set-build-options-from-command-line @@ -41,27 +41,6 @@ guix-build)) -(define (specification->package spec) - "Return a package matching SPEC. SPEC may be a package name, or a package -name followed by a hyphen and a version number. If the version number is not -present, return the preferred newest version." - (let-values (((name version) - (package-name->name+version spec))) - (match (find-best-packages-by-name name version) - ((p) ; one match - p) - ((p x ...) ; several matches - (warning (_ "ambiguous package specification `~a'~%") spec) - (warning (_ "choosing ~a from ~a~%") - (package-full-name p) - (location->string (package-location p))) - p) - (_ ; no matches - (if version - (leave (_ "~A: package not found for version ~a~%") - name version) - (leave (_ "~A: unknown package~%") name)))))) - (define (register-root store paths root) "Register ROOT as an indirect GC root for all of PATHS." (let* ((root (string-append (canonicalize-path (dirname root)) -- cgit v1.2.3 From 52bd0810a86396e961ca4c92f7e9e5ea0e8c547b Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 2 Sep 2014 19:06:45 -0400 Subject: gnu: Add postgresql. * gnu/packages/postgresql.scm: New file. * gnu-system.am (GNU_SYSTEM_MODULES): Add it. --- gnu-system.am | 1 + gnu/packages/postgresql.scm | 52 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 gnu/packages/postgresql.scm (limited to 'gnu') diff --git a/gnu-system.am b/gnu-system.am index a3f04ec575..abfb27fade 100644 --- a/gnu-system.am +++ b/gnu-system.am @@ -199,6 +199,7 @@ GNU_SYSTEM_MODULES = \ gnu/packages/pkg-config.scm \ gnu/packages/plotutils.scm \ gnu/packages/popt.scm \ + gnu/packages/postgresql.scm \ gnu/packages/pth.scm \ gnu/packages/pulseaudio.scm \ gnu/packages/pretty-print.scm \ diff --git a/gnu/packages/postgresql.scm b/gnu/packages/postgresql.scm new file mode 100644 index 0000000000..d6b505f6a2 --- /dev/null +++ b/gnu/packages/postgresql.scm @@ -0,0 +1,52 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2014 David Thompson +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu packages postgresql) + #:use-module ((guix licenses) #:select (x11-style)) + #:use-module (guix packages) + #:use-module (guix download) + #:use-module (guix build-system gnu) + #:use-module (gnu packages) + #:use-module (gnu packages compression) + #:use-module (gnu packages readline)) + +(define-public postgresql + (package + (name "postgresql") + (version "9.3.5") + (source (origin + (method url-fetch) + (uri (string-append "http://ftp.postgresql.org/pub/source/v" + version "/postgresql-" version ".tar.gz")) + (sha256 + (base32 + "08kga00izykgvnx7hn995wc4zjqslspapaa8z63045p1ya14mr4g")))) + (build-system gnu-build-system) + (inputs + `(("readline" ,readline) + ("zlib" ,zlib))) + (home-page "http://www.postgresql.org/") + (synopsis "Powerful object-relational database system") + (description + "PostgreSQL is a powerful object-relational database system. It is fully +ACID compliant, has full support for foreign keys, joins, views, triggers, and +stored procedures (in multiple languages). It includes most SQL:2008 data +types, including INTEGER, NUMERIC, BOOLEAN, CHAR, VARCHAR, DATE, INTERVAL, and +TIMESTAMP. It also supports storage of binary large objects, including +pictures, sounds, or video.") + (license (x11-style "file://COPYRIGHT")))) -- cgit v1.2.3 From 548f7a8fa2a4745d0e35e175e201513857440991 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 3 Sep 2014 10:47:05 +0200 Subject: Move operating system helpers from (guix build …) to (gnu build …). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/build/activation.scm, guix/build/install.scm, guix/build/linux-initrd.scm, guix/build/vm.scm: Move to... * gnu/build: ... here. * Makefile.am (MODULES): Remove the above guix/build/ files. * gnu-system.am (GNU_SYSTEM_MODULES): Add the above gnu/build/ files here. * gnu/services/base.scm, gnu/services/dmd.scm, gnu/system.scm, gnu/system/linux-initrd.scm, gnu/system/vm.scm, guix/scripts/system.scm: Adjust to the new module names. --- Makefile.am | 4 - gnu-system.am | 16 +- gnu/build/activation.scm | 226 ++++++++++++++ gnu/build/install.scm | 135 +++++++++ gnu/build/linux-initrd.scm | 702 ++++++++++++++++++++++++++++++++++++++++++++ gnu/build/vm.scm | 259 ++++++++++++++++ gnu/services/base.scm | 2 +- gnu/services/dmd.scm | 4 +- gnu/system.scm | 8 +- gnu/system/linux-initrd.scm | 6 +- gnu/system/vm.scm | 12 +- guix/build/activation.scm | 226 -------------- guix/build/install.scm | 136 --------- guix/build/linux-initrd.scm | 702 -------------------------------------------- guix/build/vm.scm | 259 ---------------- guix/scripts/system.scm | 2 +- 16 files changed, 1350 insertions(+), 1349 deletions(-) create mode 100644 gnu/build/activation.scm create mode 100644 gnu/build/install.scm create mode 100644 gnu/build/linux-initrd.scm create mode 100644 gnu/build/vm.scm delete mode 100644 guix/build/activation.scm delete mode 100644 guix/build/install.scm delete mode 100644 guix/build/linux-initrd.scm delete mode 100644 guix/build/vm.scm (limited to 'gnu') diff --git a/Makefile.am b/Makefile.am index 371b85c235..d25eeeb76e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -62,7 +62,6 @@ MODULES = \ guix/build/git.scm \ guix/build/gnu-build-system.scm \ guix/build/gnu-dist.scm \ - guix/build/linux-initrd.scm \ guix/build/perl-build-system.scm \ guix/build/python-build-system.scm \ guix/build/utils.scm \ @@ -70,9 +69,6 @@ MODULES = \ guix/build/pull.scm \ guix/build/rpath.scm \ guix/build/svn.scm \ - guix/build/vm.scm \ - guix/build/install.scm \ - guix/build/activation.scm \ guix/build/syscalls.scm \ guix/build/emacs-utils.scm \ guix/packages.scm \ diff --git a/gnu-system.am b/gnu-system.am index abfb27fade..2c303ac109 100644 --- a/gnu-system.am +++ b/gnu-system.am @@ -28,7 +28,7 @@ GNU_SYSTEM_MODULES = \ gnu/packages/acl.scm \ gnu/packages/admin.scm \ gnu/packages/algebra.scm \ - gnu/packages/aidc.scm \ + gnu/packages/aidc.scm \ gnu/packages/apl.scm \ gnu/packages/apr.scm \ gnu/packages/asciidoc.scm \ @@ -58,7 +58,7 @@ GNU_SYSTEM_MODULES = \ gnu/packages/compression.scm \ gnu/packages/complexity.scm \ gnu/packages/conkeror.scm \ - gnu/packages/cook.scm \ + gnu/packages/cook.scm \ gnu/packages/cpio.scm \ gnu/packages/cppi.scm \ gnu/packages/cross-base.scm \ @@ -151,7 +151,7 @@ GNU_SYSTEM_MODULES = \ gnu/packages/lightning.scm \ gnu/packages/links.scm \ gnu/packages/linux.scm \ - gnu/packages/lisp.scm \ + gnu/packages/lisp.scm \ gnu/packages/lout.scm \ gnu/packages/lsh.scm \ gnu/packages/lsof.scm \ @@ -180,7 +180,7 @@ GNU_SYSTEM_MODULES = \ gnu/packages/nettle.scm \ gnu/packages/node.scm \ gnu/packages/noweb.scm \ - gnu/packages/nvi.scm \ + gnu/packages/nvi.scm \ gnu/packages/ocaml.scm \ gnu/packages/ocrad.scm \ gnu/packages/onc-rpc.scm \ @@ -277,7 +277,13 @@ GNU_SYSTEM_MODULES = \ gnu/system/linux.scm \ gnu/system/linux-initrd.scm \ gnu/system/shadow.scm \ - gnu/system/vm.scm + gnu/system/vm.scm \ + \ + gnu/build/activation.scm \ + gnu/build/install.scm \ + gnu/build/linux-initrd.scm \ + gnu/build/vm.scm + patchdir = $(guilemoduledir)/gnu/packages/patches dist_patch_DATA = \ diff --git a/gnu/build/activation.scm b/gnu/build/activation.scm new file mode 100644 index 0000000000..bb1165ac47 --- /dev/null +++ b/gnu/build/activation.scm @@ -0,0 +1,226 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2013, 2014 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu build activation) + #:use-module (gnu build linux-initrd) + #:use-module (guix build utils) + #:use-module (ice-9 ftw) + #:use-module (ice-9 match) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:export (activate-users+groups + activate-etc + activate-setuid-programs + activate-current-system)) + +;;; Commentary: +;;; +;;; This module provides "activation" helpers. Activation is the process that +;;; consists in setting up system-wide files and directories so that an +;;; 'operating-system' configuration becomes active. +;;; +;;; Code: + +(define* (add-group name #:key gid password system? + (log-port (current-error-port))) + "Add NAME as a user group, with the given numeric GID if specified." + ;; Use 'groupadd' from the Shadow package. + (format log-port "adding group '~a'...~%" name) + (let ((args `(,@(if gid `("-g" ,(number->string gid)) '()) + ,@(if password `("-p" ,password) '()) + ,@(if system? `("--system") '()) + ,name))) + (zero? (apply system* "groupadd" args)))) + +(define* (add-user name group + #:key uid comment home shell password system? + (supplementary-groups '()) + (log-port (current-error-port))) + "Create an account for user NAME part of GROUP, with the specified +properties. Return #t on success." + (format log-port "adding user '~a'...~%" name) + + (if (and uid (zero? uid)) + + ;; 'useradd' fails with "Cannot determine your user name" if the root + ;; account doesn't exist. Thus, for bootstrapping purposes, create that + ;; one manually. + (begin + (call-with-output-file "/etc/shadow" + (cut format <> "~a::::::::~%" name)) + (call-with-output-file "/etc/passwd" + (cut format <> "~a:x:~a:~a:~a:~a:~a~%" + name "0" "0" comment home shell)) + (chmod "/etc/shadow" #o600) + #t) + + ;; Use 'useradd' from the Shadow package. + (let ((args `(,@(if uid `("-u" ,(number->string uid)) '()) + "-g" ,(if (number? group) (number->string group) group) + ,@(if (pair? supplementary-groups) + `("-G" ,(string-join supplementary-groups ",")) + '()) + ,@(if comment `("-c" ,comment) '()) + ,@(if home + (if (file-exists? home) + `("-d" ,home) ; avoid warning from 'useradd' + `("-d" ,home "--create-home")) + '()) + ,@(if shell `("-s" ,shell) '()) + ,@(if password `("-p" ,password) '()) + ,@(if system? '("--system") '()) + ,name))) + (zero? (apply system* "useradd" args))))) + +(define (activate-users+groups users groups) + "Make sure the accounts listed in USERS and the user groups listed in GROUPS +are all available. + +Each item in USERS is a list of all the characteristics of a user account; +each item in GROUPS is a tuple with the group name, group password or #f, and +numeric gid or #f." + (define (touch file) + (close-port (open-file file "a0b"))) + + (define activate-user + (match-lambda + ((name uid group supplementary-groups comment home shell password system?) + (unless (false-if-exception (getpwnam name)) + (let ((profile-dir (string-append "/var/guix/profiles/per-user/" + name))) + (add-user name group + #:uid uid + #:system? system? + #:supplementary-groups supplementary-groups + #:comment comment + #:home home + #:shell shell + #:password password) + + (unless system? + ;; Create the profile directory for the new account. + (let ((pw (getpwnam name))) + (mkdir-p profile-dir) + (chown profile-dir (passwd:uid pw) (passwd:gid pw))))))))) + + ;; 'groupadd' aborts if the file doesn't already exist. + (touch "/etc/group") + + ;; Create the root account so we can use 'useradd' and 'groupadd'. + (activate-user (find (match-lambda + ((name (? zero?) _ ...) #t) + (_ #f)) + users)) + + ;; Then create the groups. + (for-each (match-lambda + ((name password gid system?) + (unless (false-if-exception (getgrnam name)) + (add-group name + #:gid gid #:password password + #:system? system?)))) + groups) + + ;; Finally create the other user accounts. + (for-each activate-user users)) + +(define (activate-etc etc) + "Install ETC, a directory in the store, as the source of static files for +/etc." + + ;; /etc is a mixture of static and dynamic settings. Here is where we + ;; initialize it from the static part. + + (format #t "populating /etc from ~a...~%" etc) + (let ((rm-f (lambda (f) + (false-if-exception (delete-file f))))) + (rm-f "/etc/static") + (symlink etc "/etc/static") + (for-each (lambda (file) + ;; TODO: Handle 'shadow' specially so that changed + ;; password aren't lost. + (let ((target (string-append "/etc/" file)) + (source (string-append "/etc/static/" file))) + (rm-f target) + (symlink source target))) + (scandir etc + (lambda (file) + (not (member file '("." "..")))) + + ;; The default is 'string-locale)) + (scandir %setuid-directory + (lambda (file) + (not (member file '("." "..")))) + string +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu build install) + #:use-module (guix build utils) + #:use-module (srfi srfi-26) + #:use-module (ice-9 match) + #:export (install-grub + populate-root-file-system + reset-timestamps + register-closure)) + +;;; Commentary: +;;; +;;; This module supports the installation of the GNU system on a hard disk. +;;; It is meant to be used both in a build environment (in derivations that +;;; build VM images), and on the bare metal (when really installing the +;;; system.) +;;; +;;; Code: + +(define* (install-grub grub.cfg device mount-point) + "Install GRUB with GRUB.CFG on DEVICE, which is assumed to be mounted on +MOUNT-POINT." + (let* ((target (string-append mount-point "/boot/grub/grub.cfg")) + (pivot (string-append target ".new"))) + (mkdir-p (dirname target)) + + ;; Copy GRUB.CFG instead of just symlinking it since it's not a GC root. + ;; Do that atomically. + (copy-file grub.cfg pivot) + (rename-file pivot target) + + (unless (zero? (system* "grub-install" "--no-floppy" + "--boot-directory" + (string-append mount-point "/boot") + device)) + (error "failed to install GRUB")))) + +(define (evaluate-populate-directive directive target) + "Evaluate DIRECTIVE, an sexp describing a file or directory to create under +directory TARGET." + (let loop ((directive directive)) + (match directive + (('directory name) + (mkdir-p (string-append target name))) + (('directory name uid gid) + (let ((dir (string-append target name))) + (mkdir-p dir) + (chown dir uid gid))) + (('directory name uid gid mode) + (loop `(directory ,name ,uid ,gid)) + (chmod (string-append target name) mode)) + ((new '-> old) + (symlink old (string-append target new)))))) + +(define (directives store) + "Return a list of directives to populate the root file system that will host +STORE." + `(;; Note: the store's GID is fixed precisely so we can set it here rather + ;; than at activation time. + (directory ,store 0 30000 #o1775) + + (directory "/etc") + (directory "/var/log") ; for dmd + (directory "/var/guix/gcroots") + (directory "/var/empty") ; for no-login accounts + (directory "/var/db") ; for dhclient, etc. + (directory "/var/run") + (directory "/run") + (directory "/mnt") + (directory "/var/guix/profiles/per-user/root" 0 0) + + ;; Link to the initial system generation. + ("/var/guix/profiles/system" -> "system-1-link") + + ("/var/guix/gcroots/booted-system" -> "/run/booted-system") + ("/var/guix/gcroots/current-system" -> "/run/current-system") + + (directory "/bin") + ("/bin/sh" -> "/run/current-system/profile/bin/bash") + (directory "/tmp" 0 0 #o1777) ; sticky bit + + (directory "/root" 0 0) ; an exception + (directory "/home" 0 0))) + +(define (populate-root-file-system system target) + "Make the essential non-store files and directories on TARGET. This +includes /etc, /var, /run, /bin/sh, etc., and all the symlinks to SYSTEM." + (for-each (cut evaluate-populate-directive <> target) + (directives (%store-directory))) + + ;; Add system generation 1. + (symlink system + (string-append target "/var/guix/profiles/system-1-link"))) + +(define (reset-timestamps directory) + "Reset the timestamps of all the files under DIRECTORY, so that they appear +as created and modified at the Epoch." + (display "clearing file timestamps...\n") + (for-each (lambda (file) + (let ((s (lstat file))) + ;; XXX: Guile uses libc's 'utime' function (not 'futime'), so + ;; the timestamp of symlinks cannot be changed, and there are + ;; symlinks here pointing to /gnu/store, which is the host, + ;; read-only store. + (unless (eq? (stat:type s) 'symlink) + (utime file 0 0 0 0)))) + (find-files directory ""))) + +(define (register-closure store closure) + "Register CLOSURE in STORE, where STORE is the directory name of the target +store and CLOSURE is the name of a file containing a reference graph as used +by 'guix-register'. As a side effect, this resets timestamps on store files." + (let ((status (system* "guix-register" "--prefix" store + closure))) + (unless (zero? status) + (error "failed to register store items" closure)))) + +;;; install.scm ends here diff --git a/gnu/build/linux-initrd.scm b/gnu/build/linux-initrd.scm new file mode 100644 index 0000000000..60c5eec10f --- /dev/null +++ b/gnu/build/linux-initrd.scm @@ -0,0 +1,702 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2013, 2014 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu build linux-initrd) + #:use-module (rnrs io ports) + #:use-module (rnrs bytevectors) + #:use-module (system foreign) + #:use-module (system repl error-handling) + #:autoload (system repl repl) (start-repl) + #:autoload (system base compile) (compile-file) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:use-module (ice-9 match) + #:use-module (ice-9 rdelim) + #:use-module (ice-9 ftw) + #:use-module (guix build utils) + #:export (mount-essential-file-systems + linux-command-line + find-long-option + make-essential-device-nodes + configure-qemu-networking + + disk-partitions + partition-label-predicate + find-partition-by-label + canonicalize-device-spec + + mount-flags->bit-mask + check-file-system + mount-file-system + bind-mount + + load-linux-module* + device-number + boot-system)) + +;;; Commentary: +;;; +;;; Utility procedures useful in a Linux initial RAM disk (initrd). Note that +;;; many of these use procedures not yet available in vanilla Guile (`mount', +;;; `load-linux-module', etc.); these are provided by a Guile patch used in +;;; the GNU distribution. +;;; +;;; Code: + +(define* (mount-essential-file-systems #:key (root "/")) + "Mount /proc and /sys under ROOT." + (define (scope dir) + (string-append root + (if (string-suffix? "/" root) + "" + "/") + dir)) + + (unless (file-exists? (scope "proc")) + (mkdir (scope "proc"))) + (mount "none" (scope "proc") "proc") + + (unless (file-exists? (scope "sys")) + (mkdir (scope "sys"))) + (mount "none" (scope "sys") "sysfs")) + +(define (move-essential-file-systems root) + "Move currently mounted essential file systems to ROOT." + (for-each (lambda (dir) + (let ((target (string-append root dir))) + (unless (file-exists? target) + (mkdir target)) + (mount dir target "" MS_MOVE))) + '("/proc" "/sys"))) + +(define (linux-command-line) + "Return the Linux kernel command line as a list of strings." + (string-tokenize + (call-with-input-file "/proc/cmdline" + get-string-all))) + +(define (find-long-option option arguments) + "Find OPTION among ARGUMENTS, where OPTION is something like \"--load\". +Return the value associated with OPTION, or #f on failure." + (let ((opt (string-append option "="))) + (and=> (find (cut string-prefix? opt <>) + arguments) + (lambda (arg) + (substring arg (+ 1 (string-index arg #\=))))))) + +(define-syntax %ext2-endianness + ;; Endianness of ext2 file systems. + (identifier-syntax (endianness little))) + +;; Offset in bytes of interesting parts of an ext2 superblock. See +;; . +;; TODO: Use "packed structs" from Guile-OpenGL or similar. +(define-syntax %ext2-sblock-magic (identifier-syntax 56)) +(define-syntax %ext2-sblock-creator-os (identifier-syntax 72)) +(define-syntax %ext2-sblock-uuid (identifier-syntax 104)) +(define-syntax %ext2-sblock-volume-name (identifier-syntax 120)) + +(define (read-ext2-superblock device) + "Return the raw contents of DEVICE's ext2 superblock as a bytevector, or #f +if DEVICE does not contain an ext2 file system." + (define %ext2-magic + ;; The magic bytes that identify an ext2 file system. + #xef53) + + (define superblock-size + ;; Size of the interesting part of an ext2 superblock. + 264) + + (define block + ;; The superblock contents. + (make-bytevector superblock-size)) + + (call-with-input-file device + (lambda (port) + (seek port 1024 SEEK_SET) + + ;; Note: work around . + (and (eqv? superblock-size (get-bytevector-n! port block 0 + superblock-size)) + (let ((magic (bytevector-u16-ref block %ext2-sblock-magic + %ext2-endianness))) + (and (= magic %ext2-magic) + block)))))) + +(define (ext2-superblock-uuid sblock) + "Return the UUID of ext2 superblock SBLOCK as a 16-byte bytevector." + (let ((uuid (make-bytevector 16))) + (bytevector-copy! sblock %ext2-sblock-uuid uuid 0 16) + uuid)) + +(define (ext2-superblock-volume-name sblock) + "Return the volume name of SBLOCK as a string of at most 16 characters, or +#f if SBLOCK has no volume name." + (let ((bv (make-bytevector 16))) + (bytevector-copy! sblock %ext2-sblock-volume-name bv 0 16) + + ;; This is a Latin-1, nul-terminated string. + (let ((bytes (take-while (negate zero?) (bytevector->u8-list bv)))) + (if (null? bytes) + #f + (list->string (map integer->char bytes)))))) + +(define (disk-partitions) + "Return the list of device names corresponding to valid disk partitions." + (define (partition? major minor) + (let ((marker (format #f "/sys/dev/block/~a:~a/partition" major minor))) + (catch 'system-error + (lambda () + (not (zero? (call-with-input-file marker read)))) + (lambda args + (if (= ENOENT (system-error-errno args)) + #f + (apply throw args)))))) + + (call-with-input-file "/proc/partitions" + (lambda (port) + ;; Skip the two header lines. + (read-line port) + (read-line port) + + ;; Read each subsequent line, and extract the last space-separated + ;; field. + (let loop ((parts '())) + (let ((line (read-line port))) + (if (eof-object? line) + (reverse parts) + (match (string-tokenize line) + (((= string->number major) (= string->number minor) + blocks name) + (if (partition? major minor) + (loop (cons name parts)) + (loop parts)))))))))) + +(define (partition-label-predicate label) + "Return a procedure that, when applied to a partition name such as \"sda1\", +return #t if that partition's volume name is LABEL." + (lambda (part) + (let* ((device (string-append "/dev/" part)) + (sblock (catch 'system-error + (lambda () + (read-ext2-superblock device)) + (lambda args + ;; When running on the hand-made /dev, + ;; 'disk-partitions' could return partitions for which + ;; we have no /dev node. Handle that gracefully. + (if (= ENOENT (system-error-errno args)) + (begin + (format (current-error-port) + "warning: device '~a' not found~%" + device) + #f) + (apply throw args)))))) + (and sblock + (let ((volume (ext2-superblock-volume-name sblock))) + (and volume + (string=? volume label))))))) + +(define (find-partition-by-label label) + "Return the first partition found whose volume name is LABEL, or #f if none +were found." + (and=> (find (partition-label-predicate label) + (disk-partitions)) + (cut string-append "/dev/" <>))) + +(define* (canonicalize-device-spec spec #:optional (title 'any)) + "Return the device name corresponding to SPEC. TITLE is a symbol, one of +the following: + + • 'device', in which case SPEC is known to designate a device node--e.g., + \"/dev/sda1\"; + • 'label', in which case SPEC is known to designate a partition label--e.g., + \"my-root-part\"; + • 'any', in which case SPEC can be anything. +" + (define max-trials + ;; Number of times we retry partition label resolution, 1 second per + ;; trial. Note: somebody reported a delay of 16 seconds (!) before their + ;; USB key would be detected by the kernel, so we must wait for at least + ;; this long. + 20) + + (define canonical-title + ;; The realm of canonicalization. + (if (eq? title 'any) + (if (string-prefix? "/" spec) + 'device + 'label) + title)) + + (case canonical-title + ((device) + ;; Nothing to do. + spec) + ((label) + ;; Resolve the label. + (let loop ((count 0)) + (let ((device (find-partition-by-label spec))) + (or device + ;; Some devices take a bit of time to appear, most notably USB + ;; storage devices. Thus, wait for the device to appear. + (if (> count max-trials) + (error "failed to resolve partition label" spec) + (begin + (format #t "waiting for partition '~a' to appear...~%" + spec) + (sleep 1) + (loop (+ 1 count)))))))) + ;; TODO: Add support for UUIDs. + (else + (error "unknown device title" title)))) + +(define* (make-disk-device-nodes base major #:optional (minor 0)) + "Make the block device nodes around BASE (something like \"/root/dev/sda\") +with the given MAJOR number, starting with MINOR." + (mknod base 'block-special #o644 (device-number major minor)) + (let loop ((i 1)) + (when (< i 6) + (mknod (string-append base (number->string i)) + 'block-special #o644 (device-number major (+ minor i))) + (loop (+ i 1))))) + +(define* (make-essential-device-nodes #:key (root "/")) + "Make essential device nodes under ROOT/dev." + ;; The hand-made udev! + + (define (scope dir) + (string-append root + (if (string-suffix? "/" root) + "" + "/") + dir)) + + (unless (file-exists? (scope "dev")) + (mkdir (scope "dev"))) + + ;; Make the device nodes for SCSI disks. + (make-disk-device-nodes (scope "dev/sda") 8) + (make-disk-device-nodes (scope "dev/sdb") 8 16) + (make-disk-device-nodes (scope "dev/sdc") 8 32) + (make-disk-device-nodes (scope "dev/sdd") 8 48) + + ;; SCSI CD-ROM devices (aka. "/dev/sr0" etc.). + (mknod (scope "dev/scd0") 'block-special #o644 (device-number 11 0)) + (mknod (scope "dev/scd1") 'block-special #o644 (device-number 11 1)) + + ;; The virtio (para-virtualized) block devices, as supported by QEMU/KVM. + (make-disk-device-nodes (scope "dev/vda") 252) + + ;; Memory (used by Xorg's VESA driver.) + (mknod (scope "dev/mem") 'char-special #o640 (device-number 1 1)) + (mknod (scope "dev/kmem") 'char-special #o640 (device-number 1 2)) + + ;; Inputs (used by Xorg.) + (unless (file-exists? (scope "dev/input")) + (mkdir (scope "dev/input"))) + (mknod (scope "dev/input/mice") 'char-special #o640 (device-number 13 63)) + (mknod (scope "dev/input/mouse0") 'char-special #o640 (device-number 13 32)) + (mknod (scope "dev/input/event0") 'char-special #o640 (device-number 13 64)) + + ;; System console. This node is magically created by the kernel on the + ;; initrd's root, so don't try to create it in that case. + (unless (string=? root "/") + (mknod (scope "dev/console") 'char-special #o600 + (device-number 5 1))) + + ;; TTYs. + (mknod (scope "dev/tty") 'char-special #o600 + (device-number 5 0)) + (chmod (scope "dev/tty") #o666) + (let loop ((n 0)) + (and (< n 50) + (let ((name (format #f "dev/tty~a" n))) + (mknod (scope name) 'char-special #o600 + (device-number 4 n)) + (loop (+ 1 n))))) + + ;; Serial line. + (mknod (scope "dev/ttyS0") 'char-special #o660 + (device-number 4 64)) + + ;; Pseudo ttys. + (mknod (scope "dev/ptmx") 'char-special #o666 + (device-number 5 2)) + (chmod (scope "dev/ptmx") #o666) + + ;; Create /dev/pts; it will be mounted later, at boot time. + (unless (file-exists? (scope "dev/pts")) + (mkdir (scope "dev/pts"))) + + ;; Rendez-vous point for syslogd. + (mknod (scope "dev/log") 'socket #o666 0) + (mknod (scope "dev/kmsg") 'char-special #o600 (device-number 1 11)) + + ;; Other useful nodes, notably relied on by guix-daemon. + (for-each (match-lambda + ((file major minor) + (mknod (scope file) 'char-special #o666 + (device-number major minor)) + (chmod (scope file) #o666))) + '(("dev/null" 1 3) + ("dev/zero" 1 5) + ("dev/full" 1 7) + ("dev/random" 1 8) + ("dev/urandom" 1 9))) + + (symlink "/proc/self/fd" (scope "dev/fd")) + (symlink "/proc/self/fd/0" (scope "dev/stdin")) + (symlink "/proc/self/fd/1" (scope "dev/stdout")) + (symlink "/proc/self/fd/2" (scope "dev/stderr")) + + ;; Loopback devices. + (let loop ((i 0)) + (when (< i 8) + (mknod (scope (string-append "dev/loop" (number->string i))) + 'block-special #o660 + (device-number 7 i)) + (loop (+ 1 i)))) + + ;; File systems in user space (FUSE). + (mknod (scope "dev/fuse") 'char-special #o666 (device-number 10 229))) + +(define %host-qemu-ipv4-address + (inet-pton AF_INET "10.0.2.10")) + +(define* (configure-qemu-networking #:optional (interface "eth0")) + "Setup the INTERFACE network interface and /etc/resolv.conf according to +QEMU's default networking settings (see net/slirp.c in QEMU for default +networking values.) Return #t if INTERFACE is up, #f otherwise." + (display "configuring QEMU networking...\n") + (let* ((sock (socket AF_INET SOCK_STREAM 0)) + (address (make-socket-address AF_INET %host-qemu-ipv4-address 0)) + (flags (network-interface-flags sock interface))) + (set-network-interface-address sock interface address) + (set-network-interface-flags sock interface (logior flags IFF_UP)) + + ;; Hello! We used to create /etc/resolv.conf here, with "nameserver + ;; 10.0.2.3\n". However, with Linux-libre 3.16, we're getting ENOSPC. + ;; And since it's actually unnecessary, it's gone. + + (logand (network-interface-flags sock interface) IFF_UP))) + +;; Linux mount flags, from libc's . +(define MS_RDONLY 1) +(define MS_NOSUID 2) +(define MS_NODEV 4) +(define MS_NOEXEC 8) +(define MS_BIND 4096) +(define MS_MOVE 8192) + +(define (bind-mount source target) + "Bind-mount SOURCE at TARGET." + (mount source target "" MS_BIND)) + +(define (load-linux-module* file) + "Load Linux module from FILE, the name of a `.ko' file." + (define (slurp module) + (call-with-input-file file get-bytevector-all)) + + (load-linux-module (slurp file))) + +(define (device-number major minor) + "Return the device number for the device with MAJOR and MINOR, for use as +the last argument of `mknod'." + (+ (* major 256) minor)) + +(define (pidof program) + "Return the PID of the first presumed instance of PROGRAM." + (let ((program (basename program))) + (find (lambda (pid) + (let ((exe (format #f "/proc/~a/exe" pid))) + (and=> (false-if-exception (readlink exe)) + (compose (cut string=? program <>) basename)))) + (filter-map string->number (scandir "/proc"))))) + +(define* (mount-root-file-system root type + #:key volatile-root? (unionfs "unionfs")) + "Mount the root file system of type TYPE at device ROOT. If VOLATILE-ROOT? +is true, mount ROOT read-only and make it a union with a writable tmpfs using +UNIONFS." + (define (mark-as-not-killable pid) + ;; Tell the 'user-processes' dmd service that PID must be kept alive when + ;; shutting down. + (mkdir-p "/root/etc/dmd") + (let ((port (open-file "/root/etc/dmd/do-not-kill" "a"))) + (chmod port #o600) + (write pid port) + (newline port) + (close-port port))) + + (catch #t + (lambda () + (if volatile-root? + (begin + (mkdir-p "/real-root") + (mount root "/real-root" type MS_RDONLY) + (mkdir-p "/rw-root") + (mount "none" "/rw-root" "tmpfs") + + ;; We want read-write /dev nodes. + (make-essential-device-nodes #:root "/rw-root") + + ;; Make /root a union of the tmpfs and the actual root. Use + ;; 'max_files' to set a high RLIMIT_NOFILE for the unionfs process + ;; itself. Failing to do that, we quickly run out of file + ;; descriptors; see . + (unless (zero? (system* unionfs "-o" + "cow,allow_other,use_ino,suid,dev,max_files=65536" + "/rw-root=RW:/real-root=RO" + "/root")) + (error "unionfs failed")) + + ;; Make sure unionfs remains alive till the end. Because + ;; 'fuse_daemonize' doesn't tell the PID of the forked daemon, we + ;; have to resort to 'pidof' here. + (mark-as-not-killable (pidof unionfs))) + (begin + (check-file-system root type) + (mount root "/root" type)))) + (lambda args + (format (current-error-port) "exception while mounting '~a': ~s~%" + root args) + (start-repl))) + + (copy-file "/proc/mounts" "/root/etc/mtab")) + +(define (check-file-system device type) + "Run a file system check of TYPE on DEVICE." + (define fsck + (string-append "fsck." type)) + + (let ((status (system* fsck "-v" "-p" device))) + (match (status:exit-val status) + (0 + #t) + (1 + (format (current-error-port) "'~a' corrected errors on ~a; continuing~%" + fsck device)) + (2 + (format (current-error-port) "'~a' corrected errors on ~a; rebooting~%" + fsck device) + (sleep 3) + (reboot)) + (code + (format (current-error-port) "'~a' exited with code ~a on ~a; spawning REPL~%" + fsck code device) + (start-repl))))) + +(define (mount-flags->bit-mask flags) + "Return the number suitable for the 'flags' argument of 'mount' that +corresponds to the symbols listed in FLAGS." + (let loop ((flags flags)) + (match flags + (('read-only rest ...) + (logior MS_RDONLY (loop rest))) + (('bind-mount rest ...) + (logior MS_BIND (loop rest))) + (('no-suid rest ...) + (logior MS_NOSUID (loop rest))) + (('no-dev rest ...) + (logior MS_NODEV (loop rest))) + (('no-exec rest ...) + (logior MS_NOEXEC (loop rest))) + (() + 0)))) + +(define* (mount-file-system spec #:key (root "/root")) + "Mount the file system described by SPEC under ROOT. SPEC must have the +form: + + (DEVICE TITLE MOUNT-POINT TYPE (FLAGS ...) OPTIONS CHECK?) + +DEVICE, MOUNT-POINT, and TYPE must be strings; OPTIONS can be a string or #f; +FLAGS must be a list of symbols. CHECK? is a Boolean indicating whether to +run a file system check." + (match spec + ((source title mount-point type (flags ...) options check?) + (let ((source (canonicalize-device-spec source title)) + (mount-point (string-append root "/" mount-point))) + (when check? + (check-file-system source type)) + (mkdir-p mount-point) + (mount source mount-point type (mount-flags->bit-mask flags) + (if options + (string->pointer options) + %null-pointer)) + + ;; Update /etc/mtab. + (mkdir-p (string-append root "/etc")) + (let ((port (open-file (string-append root "/etc/mtab") "a"))) + (format port "~a ~a ~a ~a 0 0~%" + source mount-point type (or options "")) + (close-port port)))))) + +(define (switch-root root) + "Switch to ROOT as the root file system, in a way similar to what +util-linux' switch_root(8) does." + (move-essential-file-systems root) + (chdir root) + + ;; Since we're about to 'rm -rf /', try to make sure we're on an initrd. + ;; TODO: Use 'statfs' to check the fs type, like klibc does. + (when (or (not (file-exists? "/init")) (directory-exists? "/home")) + (format (current-error-port) + "The root file system is probably not an initrd; \ +bailing out.~%root contents: ~s~%" (scandir "/")) + (force-output (current-error-port)) + (exit 1)) + + ;; Delete files from the old root, without crossing mount points (assuming + ;; there are no mount points in sub-directories.) That means we're leaving + ;; the empty ROOT directory behind us, but that's OK. + (let ((root-device (stat:dev (stat "/")))) + (for-each (lambda (file) + (unless (member file '("." "..")) + (let* ((file (string-append "/" file)) + (device (stat:dev (lstat file)))) + (when (= device root-device) + (delete-file-recursively file))))) + (scandir "/"))) + + ;; Make ROOT the new root. + (mount root "/" "" MS_MOVE) + (chroot ".") + (chdir "/") + + (when (file-exists? "/dev/console") + ;; Close the standard file descriptors since they refer to the old + ;; /dev/console, and reopen them. + (let ((console (open-file "/dev/console" "r+b0"))) + (for-each close-fdes '(0 1 2)) + + (dup2 (fileno console) 0) + (dup2 (fileno console) 1) + (dup2 (fileno console) 2) + + (close-port console)))) + + +(define* (boot-system #:key + (linux-modules '()) + qemu-guest-networking? + guile-modules-in-chroot? + volatile-root? + (mounts '())) + "This procedure is meant to be called from an initrd. Boot a system by +first loading LINUX-MODULES, then setting up QEMU guest networking if +QEMU-GUEST-NETWORKING? is true, mounting the file systems specified in MOUNTS, +and finally booting into the new root if any. The initrd supports kernel +command-line options '--load', '--root', and '--repl'. + +Mount the root file system, specified by the '--root' command-line argument, +if any. + +MOUNTS must be a list suitable for 'mount-file-system'. + +When GUILE-MODULES-IN-CHROOT? is true, make core Guile modules available in +the new root. + +When VOLATILE-ROOT? is true, the root file system is writable but any changes +to it are lost." + (define root-mount-point? + (match-lambda + ((device _ "/" _ ...) #t) + (_ #f))) + + (define root-fs-type + (or (any (match-lambda + ((device _ "/" type _ ...) type) + (_ #f)) + mounts) + "ext4")) + + (display "Welcome, this is GNU's early boot Guile.\n") + (display "Use '--repl' for an initrd REPL.\n\n") + + (call-with-error-handling + (lambda () + (mount-essential-file-systems) + (let* ((args (linux-command-line)) + (to-load (find-long-option "--load" args)) + (root (find-long-option "--root" args))) + + (when (member "--repl" args) + (start-repl)) + + (display "loading kernel modules...\n") + (for-each (compose load-linux-module* + (cut string-append "/modules/" <>)) + linux-modules) + + (when qemu-guest-networking? + (unless (configure-qemu-networking) + (display "network interface is DOWN\n"))) + + ;; Make /dev nodes. + (make-essential-device-nodes) + + ;; Prepare the real root file system under /root. + (unless (file-exists? "/root") + (mkdir "/root")) + (if root + (mount-root-file-system (canonicalize-device-spec root) + root-fs-type + #:volatile-root? volatile-root?) + (mount "none" "/root" "tmpfs")) + + (unless (file-exists? "/root/dev") + (mkdir "/root/dev") + (make-essential-device-nodes #:root "/root")) + + ;; Mount the specified file systems. + (for-each mount-file-system + (remove root-mount-point? mounts)) + + (when guile-modules-in-chroot? + ;; Copy the directories that contain .scm and .go files so that the + ;; child process in the chroot can load modules (we would bind-mount + ;; them but for some reason that fails with EINVAL -- XXX). + (mkdir-p "/root/share") + (mkdir-p "/root/lib") + (mount "none" "/root/share" "tmpfs") + (mount "none" "/root/lib" "tmpfs") + (copy-recursively "/share" "/root/share" + #:log (%make-void-port "w")) + (copy-recursively "/lib" "/root/lib" + #:log (%make-void-port "w"))) + + (if to-load + (begin + (switch-root "/root") + (format #t "loading '~a'...\n" to-load) + + ;; TODO: Remove /lib, /share, and /loader.go. + (primitive-load to-load) + + (format (current-error-port) + "boot program '~a' terminated, rebooting~%" + to-load) + (sleep 2) + (reboot)) + (begin + (display "no boot file passed via '--load'\n") + (display "entering a warm and cozy REPL\n") + (start-repl))))))) + +;;; linux-initrd.scm ends here diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm new file mode 100644 index 0000000000..d724ca3a55 --- /dev/null +++ b/gnu/build/vm.scm @@ -0,0 +1,259 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2013, 2014 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu build vm) + #:use-module (guix build utils) + #:use-module (gnu build linux-initrd) + #:use-module (gnu build install) + #:use-module (ice-9 match) + #:use-module (ice-9 regex) + #:use-module (ice-9 rdelim) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:export (qemu-command + load-in-linux-vm + format-partition + initialize-root-partition + initialize-partition-table + initialize-hard-disk)) + +;;; Commentary: +;;; +;;; This module provides supporting code to run virtual machines and build +;;; virtual machine images using QEMU. +;;; +;;; Code: + +(define* (qemu-command #:optional (system %host-type)) + "Return the default name of the QEMU command for SYSTEM." + (let ((cpu (substring %host-type 0 + (string-index %host-type #\-)))) + (string-append "qemu-system-" + (if (string-match "^i[3456]86$" cpu) + "i386" + cpu)))) + +(define* (load-in-linux-vm builder + #:key + output + (qemu (qemu-command)) (memory-size 512) + linux initrd + make-disk-image? (disk-image-size 100) + (disk-image-format "qcow2") + (references-graphs '())) + "Run BUILDER, a Scheme file, into a VM running LINUX with INITRD, and copy +the result to OUTPUT. + +When MAKE-DISK-IMAGE? is true, OUTPUT will contain a VM image of +DISK-IMAGE-SIZE MiB resulting from the execution of BUILDER, which may access +it via /dev/hda. + +REFERENCES-GRAPHS can specify a list of reference-graph files as produced by +the #:references-graphs parameter of 'derivation'." + (define image-file + (string-append "image." disk-image-format)) + + (when make-disk-image? + (unless (zero? (system* "qemu-img" "create" "-f" disk-image-format + image-file + (number->string disk-image-size))) + (error "qemu-img failed"))) + + (mkdir "xchg") + + (match references-graphs + ((graph-files ...) + ;; Copy the reference-graph files under xchg/ so EXP can access it. + (map (lambda (file) + (copy-file file (string-append "xchg/" file))) + graph-files)) + (_ #f)) + + (unless (zero? + (apply system* qemu "-enable-kvm" "-nographic" "-no-reboot" + "-m" (number->string memory-size) + "-net" "nic,model=virtio" + "-virtfs" + (string-append "local,id=store_dev,path=" + (%store-directory) + ",security_model=none,mount_tag=store") + "-virtfs" + (string-append "local,id=xchg_dev,path=xchg" + ",security_model=none,mount_tag=xchg") + "-kernel" linux + "-initrd" initrd + "-append" (string-append "console=ttyS0 --load=" + builder) + (if make-disk-image? + `("-drive" ,(string-append "file=" image-file + ",if=virtio")) + '()))) + (error "qemu failed" qemu)) + + (if make-disk-image? + (copy-file image-file output) + (begin + (mkdir output) + (copy-recursively "xchg" output)))) + +(define (read-reference-graph port) + "Return a list of store paths from the reference graph at PORT. +The data at PORT is the format produced by #:references-graphs." + (let loop ((line (read-line port)) + (result '())) + (cond ((eof-object? line) + (delete-duplicates result)) + ((string-prefix? "/" line) + (loop (read-line port) + (cons line result))) + (else + (loop (read-line port) + result))))) + +(define* (initialize-partition-table device partition-size + #:key + (label-type "msdos") + (offset (expt 2 20))) + "Create on DEVICE a partition table of type LABEL-TYPE, with a single +partition of PARTITION-SIZE bytes starting at OFFSET bytes. Return #t on +success." + (format #t "creating partition table with a ~a B partition...\n" + partition-size) + (unless (zero? (system* "parted" device "mklabel" label-type + "mkpart" "primary" "ext2" + (format #f "~aB" offset) + (format #f "~aB" partition-size))) + (error "failed to create partition table"))) + +(define* (populate-store reference-graphs target) + "Populate the store under directory TARGET with the items specified in +REFERENCE-GRAPHS, a list of reference-graph files." + (define store + (string-append target (%store-directory))) + + (define (things-to-copy) + ;; Return the list of store files to copy to the image. + (define (graph-from-file file) + (call-with-input-file file read-reference-graph)) + + (delete-duplicates (append-map graph-from-file reference-graphs))) + + (mkdir-p store) + (chmod store #o1775) + (for-each (lambda (thing) + (copy-recursively thing + (string-append target thing))) + (things-to-copy))) + +(define MS_BIND 4096) ; again! + +(define* (format-partition partition type + #:key label) + "Create a file system TYPE on PARTITION. If LABEL is true, use that as the +volume name." + (format #t "creating ~a partition...\n" type) + (unless (zero? (apply system* (string-append "mkfs." type) + "-F" partition + (if label + `("-L" ,label) + '()))) + (error "failed to create partition"))) + +(define* (initialize-root-partition target-directory + #:key copy-closures? register-closures? + closures system-directory) + "Initialize the root partition mounted at TARGET-DIRECTORY." + (define target-store + (string-append target-directory (%store-directory))) + + (when copy-closures? + ;; Populate the store. + (populate-store (map (cut string-append "/xchg/" <>) closures) + target-directory)) + + ;; Populate /dev. + (make-essential-device-nodes #:root target-directory) + + ;; Optionally, register the inputs in the image's store. + (when register-closures? + (unless copy-closures? + ;; XXX: 'guix-register' wants to palpate the things it registers, so + ;; bind-mount the store on the target. + (mkdir-p target-store) + (mount (%store-directory) target-store "" MS_BIND)) + + (display "registering closures...\n") + (for-each (lambda (closure) + (register-closure target-directory + (string-append "/xchg/" closure))) + closures) + (unless copy-closures? + (system* "umount" target-store))) + + ;; Add the non-store directories and files. + (display "populating...\n") + (populate-root-file-system system-directory target-directory)) + +(define* (initialize-hard-disk device + #:key + system-directory + grub.cfg + disk-image-size + (file-system-type "ext4") + file-system-label + (closures '()) + copy-closures? + (register-closures? #t)) + "Initialize DEVICE, a disk of DISK-IMAGE-SIZE bytes, with a FILE-SYSTEM-TYPE +partition with (optionally) FILE-SYSTEM-LABEL as its volume name, and with +GRUB installed. If REGISTER-CLOSURES? is true, register all of CLOSURES is +the partition's store. If COPY-CLOSURES? is true, copy all of CLOSURES to the +partition. SYSTEM-DIRECTORY is the name of the directory of the 'system' +derivation." + (define target-directory + "/fs") + + (define partition + (string-append device "1")) + + (initialize-partition-table device + (- disk-image-size (* 5 (expt 2 20)))) + + (format-partition partition file-system-type + #:label file-system-label) + + (display "mounting partition...\n") + (mkdir target-directory) + (mount partition target-directory file-system-type) + + (initialize-root-partition target-directory + #:system-directory system-directory + #:copy-closures? copy-closures? + #:register-closures? register-closures? + #:closures closures) + + (install-grub grub.cfg device target-directory) + + ;; 'guix-register' resets timestamps and everything, so no need to do it + ;; once more in that case. + (unless register-closures? + (reset-timestamps target-directory)) + + (zero? (system* "umount" target-directory))) + +;;; vm.scm ends here diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 578d4cba71..274b6f5b77 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -29,7 +29,7 @@ #:use-module ((gnu packages base) #:select (canonical-package glibc)) #:use-module (gnu packages package-management) - #:use-module ((guix build linux-initrd) + #:use-module ((gnu build linux-initrd) #:select (mount-flags->bit-mask)) #:use-module (guix gexp) #:use-module (guix monads) diff --git a/gnu/services/dmd.scm b/gnu/services/dmd.scm index dfda2708f5..87bd67a8da 100644 --- a/gnu/services/dmd.scm +++ b/gnu/services/dmd.scm @@ -35,7 +35,7 @@ (define modules ;; Extra modules visible to dmd.conf. '((guix build syscalls) - (guix build linux-initrd) + (gnu build linux-initrd) (guix build utils))) (mlet %store-monad ((modules (imported-modules modules)) @@ -50,7 +50,7 @@ (use-modules (ice-9 ftw) (guix build syscalls) (guix build utils) - ((guix build linux-initrd) + ((gnu build linux-initrd) #:select (check-file-system canonicalize-device-spec))) (register-services diff --git a/gnu/system.scm b/gnu/system.scm index 2469ade1f3..963f4864f8 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -362,9 +362,9 @@ alias ll='ls -l' stateful part of OS, including user accounts and groups, special directories, etc." (define %modules - '((guix build activation) - (guix build utils) - (guix build linux-initrd))) + '((gnu build activation) + (gnu build linux-initrd) + (guix build utils))) (define (service-activations services) ;; Return the activation scripts for SERVICES. @@ -399,7 +399,7 @@ etc." (set! %load-compiled-path (cons #$compiled %load-compiled-path))) - (use-modules (guix build activation)) + (use-modules (gnu build activation)) ;; Populate /etc. (activate-etc #$etc) diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm index e48b399a9d..6d9e23277f 100644 --- a/gnu/system/linux-initrd.scm +++ b/gnu/system/linux-initrd.scm @@ -75,7 +75,7 @@ initrd." (mlet* %store-monad ((source (imported-modules modules)) (compiled (compiled-modules modules))) (define builder - ;; TODO: Move most of this code to (guix build linux-initrd). + ;; TODO: Move most of this code to (gnu build linux-initrd). #~(begin (use-modules (guix build utils) (ice-9 pretty-print) @@ -277,7 +277,7 @@ exception and backtrace!)." (expression->initrd #~(begin - (use-modules (guix build linux-initrd) + (use-modules (gnu build linux-initrd) (guix build utils) (srfi srfi-26)) @@ -293,7 +293,7 @@ exception and backtrace!)." #:volatile-root? '#$volatile-root?)) #:name "base-initrd" #:modules '((guix build utils) - (guix build linux-initrd)) + (gnu build linux-initrd)) #:to-copy helper-packages #:linux linux-libre #:linux-modules linux-modules)) diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm index 42fc23ee8f..be9cf6b457 100644 --- a/gnu/system/vm.scm +++ b/gnu/system/vm.scm @@ -23,7 +23,7 @@ #:use-module (guix derivations) #:use-module (guix packages) #:use-module (guix monads) - #:use-module ((guix build vm) + #:use-module ((gnu build vm) #:select (qemu-command)) #:use-module (gnu packages base) #:use-module (gnu packages guile) @@ -112,9 +112,9 @@ input tuple. The output file name is when building for SYSTEM." (qemu qemu-headless) (env-vars '()) (modules - '((guix build vm) - (guix build install) - (guix build linux-initrd) + '((gnu build vm) + (gnu build install) + (gnu build linux-initrd) (guix build utils))) (guile-for-build (%guile-for-build)) @@ -164,7 +164,7 @@ made available under the /xchg CIFS share." ;; Code that launches the VM that evaluates EXP. #~(begin (use-modules (guix build utils) - (guix build vm)) + (gnu build vm)) (let ((inputs '#$(list qemu coreutils)) (linux (string-append #$linux "/bzImage")) @@ -222,7 +222,7 @@ the image." (expression->derivation-in-linux-vm name #~(begin - (use-modules (guix build vm) + (use-modules (gnu build vm) (guix build utils)) (let ((inputs diff --git a/guix/build/activation.scm b/guix/build/activation.scm deleted file mode 100644 index b04b017881..0000000000 --- a/guix/build/activation.scm +++ /dev/null @@ -1,226 +0,0 @@ -;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013, 2014 Ludovic Courtès -;;; -;;; This file is part of GNU Guix. -;;; -;;; GNU Guix is free software; you can redistribute it and/or modify it -;;; under the terms of the GNU General Public License as published by -;;; the Free Software Foundation; either version 3 of the License, or (at -;;; your option) any later version. -;;; -;;; GNU Guix is distributed in the hope that it will be useful, but -;;; WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;;; GNU General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with GNU Guix. If not, see . - -(define-module (guix build activation) - #:use-module (guix build utils) - #:use-module (guix build linux-initrd) - #:use-module (ice-9 ftw) - #:use-module (ice-9 match) - #:use-module (srfi srfi-1) - #:use-module (srfi srfi-26) - #:export (activate-users+groups - activate-etc - activate-setuid-programs - activate-current-system)) - -;;; Commentary: -;;; -;;; This module provides "activation" helpers. Activation is the process that -;;; consists in setting up system-wide files and directories so that an -;;; 'operating-system' configuration becomes active. -;;; -;;; Code: - -(define* (add-group name #:key gid password system? - (log-port (current-error-port))) - "Add NAME as a user group, with the given numeric GID if specified." - ;; Use 'groupadd' from the Shadow package. - (format log-port "adding group '~a'...~%" name) - (let ((args `(,@(if gid `("-g" ,(number->string gid)) '()) - ,@(if password `("-p" ,password) '()) - ,@(if system? `("--system") '()) - ,name))) - (zero? (apply system* "groupadd" args)))) - -(define* (add-user name group - #:key uid comment home shell password system? - (supplementary-groups '()) - (log-port (current-error-port))) - "Create an account for user NAME part of GROUP, with the specified -properties. Return #t on success." - (format log-port "adding user '~a'...~%" name) - - (if (and uid (zero? uid)) - - ;; 'useradd' fails with "Cannot determine your user name" if the root - ;; account doesn't exist. Thus, for bootstrapping purposes, create that - ;; one manually. - (begin - (call-with-output-file "/etc/shadow" - (cut format <> "~a::::::::~%" name)) - (call-with-output-file "/etc/passwd" - (cut format <> "~a:x:~a:~a:~a:~a:~a~%" - name "0" "0" comment home shell)) - (chmod "/etc/shadow" #o600) - #t) - - ;; Use 'useradd' from the Shadow package. - (let ((args `(,@(if uid `("-u" ,(number->string uid)) '()) - "-g" ,(if (number? group) (number->string group) group) - ,@(if (pair? supplementary-groups) - `("-G" ,(string-join supplementary-groups ",")) - '()) - ,@(if comment `("-c" ,comment) '()) - ,@(if home - (if (file-exists? home) - `("-d" ,home) ; avoid warning from 'useradd' - `("-d" ,home "--create-home")) - '()) - ,@(if shell `("-s" ,shell) '()) - ,@(if password `("-p" ,password) '()) - ,@(if system? '("--system") '()) - ,name))) - (zero? (apply system* "useradd" args))))) - -(define (activate-users+groups users groups) - "Make sure the accounts listed in USERS and the user groups listed in GROUPS -are all available. - -Each item in USERS is a list of all the characteristics of a user account; -each item in GROUPS is a tuple with the group name, group password or #f, and -numeric gid or #f." - (define (touch file) - (close-port (open-file file "a0b"))) - - (define activate-user - (match-lambda - ((name uid group supplementary-groups comment home shell password system?) - (unless (false-if-exception (getpwnam name)) - (let ((profile-dir (string-append "/var/guix/profiles/per-user/" - name))) - (add-user name group - #:uid uid - #:system? system? - #:supplementary-groups supplementary-groups - #:comment comment - #:home home - #:shell shell - #:password password) - - (unless system? - ;; Create the profile directory for the new account. - (let ((pw (getpwnam name))) - (mkdir-p profile-dir) - (chown profile-dir (passwd:uid pw) (passwd:gid pw))))))))) - - ;; 'groupadd' aborts if the file doesn't already exist. - (touch "/etc/group") - - ;; Create the root account so we can use 'useradd' and 'groupadd'. - (activate-user (find (match-lambda - ((name (? zero?) _ ...) #t) - (_ #f)) - users)) - - ;; Then create the groups. - (for-each (match-lambda - ((name password gid system?) - (unless (false-if-exception (getgrnam name)) - (add-group name - #:gid gid #:password password - #:system? system?)))) - groups) - - ;; Finally create the other user accounts. - (for-each activate-user users)) - -(define (activate-etc etc) - "Install ETC, a directory in the store, as the source of static files for -/etc." - - ;; /etc is a mixture of static and dynamic settings. Here is where we - ;; initialize it from the static part. - - (format #t "populating /etc from ~a...~%" etc) - (let ((rm-f (lambda (f) - (false-if-exception (delete-file f))))) - (rm-f "/etc/static") - (symlink etc "/etc/static") - (for-each (lambda (file) - ;; TODO: Handle 'shadow' specially so that changed - ;; password aren't lost. - (let ((target (string-append "/etc/" file)) - (source (string-append "/etc/static/" file))) - (rm-f target) - (symlink source target))) - (scandir etc - (lambda (file) - (not (member file '("." "..")))) - - ;; The default is 'string-locale)) - (scandir %setuid-directory - (lambda (file) - (not (member file '("." "..")))) - string -;;; -;;; This file is part of GNU Guix. -;;; -;;; GNU Guix is free software; you can redistribute it and/or modify it -;;; under the terms of the GNU General Public License as published by -;;; the Free Software Foundation; either version 3 of the License, or (at -;;; your option) any later version. -;;; -;;; GNU Guix is distributed in the hope that it will be useful, but -;;; WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;;; GNU General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with GNU Guix. If not, see . - -(define-module (guix build install) - #:use-module (guix build utils) - #:use-module (guix build install) - #:use-module (srfi srfi-26) - #:use-module (ice-9 match) - #:export (install-grub - populate-root-file-system - reset-timestamps - register-closure)) - -;;; Commentary: -;;; -;;; This module supports the installation of the GNU system on a hard disk. -;;; It is meant to be used both in a build environment (in derivations that -;;; build VM images), and on the bare metal (when really installing the -;;; system.) -;;; -;;; Code: - -(define* (install-grub grub.cfg device mount-point) - "Install GRUB with GRUB.CFG on DEVICE, which is assumed to be mounted on -MOUNT-POINT." - (let* ((target (string-append mount-point "/boot/grub/grub.cfg")) - (pivot (string-append target ".new"))) - (mkdir-p (dirname target)) - - ;; Copy GRUB.CFG instead of just symlinking it since it's not a GC root. - ;; Do that atomically. - (copy-file grub.cfg pivot) - (rename-file pivot target) - - (unless (zero? (system* "grub-install" "--no-floppy" - "--boot-directory" - (string-append mount-point "/boot") - device)) - (error "failed to install GRUB")))) - -(define (evaluate-populate-directive directive target) - "Evaluate DIRECTIVE, an sexp describing a file or directory to create under -directory TARGET." - (let loop ((directive directive)) - (match directive - (('directory name) - (mkdir-p (string-append target name))) - (('directory name uid gid) - (let ((dir (string-append target name))) - (mkdir-p dir) - (chown dir uid gid))) - (('directory name uid gid mode) - (loop `(directory ,name ,uid ,gid)) - (chmod (string-append target name) mode)) - ((new '-> old) - (symlink old (string-append target new)))))) - -(define (directives store) - "Return a list of directives to populate the root file system that will host -STORE." - `(;; Note: the store's GID is fixed precisely so we can set it here rather - ;; than at activation time. - (directory ,store 0 30000 #o1775) - - (directory "/etc") - (directory "/var/log") ; for dmd - (directory "/var/guix/gcroots") - (directory "/var/empty") ; for no-login accounts - (directory "/var/db") ; for dhclient, etc. - (directory "/var/run") - (directory "/run") - (directory "/mnt") - (directory "/var/guix/profiles/per-user/root" 0 0) - - ;; Link to the initial system generation. - ("/var/guix/profiles/system" -> "system-1-link") - - ("/var/guix/gcroots/booted-system" -> "/run/booted-system") - ("/var/guix/gcroots/current-system" -> "/run/current-system") - - (directory "/bin") - ("/bin/sh" -> "/run/current-system/profile/bin/bash") - (directory "/tmp" 0 0 #o1777) ; sticky bit - - (directory "/root" 0 0) ; an exception - (directory "/home" 0 0))) - -(define (populate-root-file-system system target) - "Make the essential non-store files and directories on TARGET. This -includes /etc, /var, /run, /bin/sh, etc., and all the symlinks to SYSTEM." - (for-each (cut evaluate-populate-directive <> target) - (directives (%store-directory))) - - ;; Add system generation 1. - (symlink system - (string-append target "/var/guix/profiles/system-1-link"))) - -(define (reset-timestamps directory) - "Reset the timestamps of all the files under DIRECTORY, so that they appear -as created and modified at the Epoch." - (display "clearing file timestamps...\n") - (for-each (lambda (file) - (let ((s (lstat file))) - ;; XXX: Guile uses libc's 'utime' function (not 'futime'), so - ;; the timestamp of symlinks cannot be changed, and there are - ;; symlinks here pointing to /gnu/store, which is the host, - ;; read-only store. - (unless (eq? (stat:type s) 'symlink) - (utime file 0 0 0 0)))) - (find-files directory ""))) - -(define (register-closure store closure) - "Register CLOSURE in STORE, where STORE is the directory name of the target -store and CLOSURE is the name of a file containing a reference graph as used -by 'guix-register'. As a side effect, this resets timestamps on store files." - (let ((status (system* "guix-register" "--prefix" store - closure))) - (unless (zero? status) - (error "failed to register store items" closure)))) - -;;; install.scm ends here diff --git a/guix/build/linux-initrd.scm b/guix/build/linux-initrd.scm deleted file mode 100644 index d37da9a6ff..0000000000 --- a/guix/build/linux-initrd.scm +++ /dev/null @@ -1,702 +0,0 @@ -;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013, 2014 Ludovic Courtès -;;; -;;; This file is part of GNU Guix. -;;; -;;; GNU Guix is free software; you can redistribute it and/or modify it -;;; under the terms of the GNU General Public License as published by -;;; the Free Software Foundation; either version 3 of the License, or (at -;;; your option) any later version. -;;; -;;; GNU Guix is distributed in the hope that it will be useful, but -;;; WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;;; GNU General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with GNU Guix. If not, see . - -(define-module (guix build linux-initrd) - #:use-module (rnrs io ports) - #:use-module (rnrs bytevectors) - #:use-module (system foreign) - #:use-module (system repl error-handling) - #:autoload (system repl repl) (start-repl) - #:autoload (system base compile) (compile-file) - #:use-module (srfi srfi-1) - #:use-module (srfi srfi-26) - #:use-module (ice-9 match) - #:use-module (ice-9 rdelim) - #:use-module (ice-9 ftw) - #:use-module (guix build utils) - #:export (mount-essential-file-systems - linux-command-line - find-long-option - make-essential-device-nodes - configure-qemu-networking - - disk-partitions - partition-label-predicate - find-partition-by-label - canonicalize-device-spec - - mount-flags->bit-mask - check-file-system - mount-file-system - bind-mount - - load-linux-module* - device-number - boot-system)) - -;;; Commentary: -;;; -;;; Utility procedures useful in a Linux initial RAM disk (initrd). Note that -;;; many of these use procedures not yet available in vanilla Guile (`mount', -;;; `load-linux-module', etc.); these are provided by a Guile patch used in -;;; the GNU distribution. -;;; -;;; Code: - -(define* (mount-essential-file-systems #:key (root "/")) - "Mount /proc and /sys under ROOT." - (define (scope dir) - (string-append root - (if (string-suffix? "/" root) - "" - "/") - dir)) - - (unless (file-exists? (scope "proc")) - (mkdir (scope "proc"))) - (mount "none" (scope "proc") "proc") - - (unless (file-exists? (scope "sys")) - (mkdir (scope "sys"))) - (mount "none" (scope "sys") "sysfs")) - -(define (move-essential-file-systems root) - "Move currently mounted essential file systems to ROOT." - (for-each (lambda (dir) - (let ((target (string-append root dir))) - (unless (file-exists? target) - (mkdir target)) - (mount dir target "" MS_MOVE))) - '("/proc" "/sys"))) - -(define (linux-command-line) - "Return the Linux kernel command line as a list of strings." - (string-tokenize - (call-with-input-file "/proc/cmdline" - get-string-all))) - -(define (find-long-option option arguments) - "Find OPTION among ARGUMENTS, where OPTION is something like \"--load\". -Return the value associated with OPTION, or #f on failure." - (let ((opt (string-append option "="))) - (and=> (find (cut string-prefix? opt <>) - arguments) - (lambda (arg) - (substring arg (+ 1 (string-index arg #\=))))))) - -(define-syntax %ext2-endianness - ;; Endianness of ext2 file systems. - (identifier-syntax (endianness little))) - -;; Offset in bytes of interesting parts of an ext2 superblock. See -;; . -;; TODO: Use "packed structs" from Guile-OpenGL or similar. -(define-syntax %ext2-sblock-magic (identifier-syntax 56)) -(define-syntax %ext2-sblock-creator-os (identifier-syntax 72)) -(define-syntax %ext2-sblock-uuid (identifier-syntax 104)) -(define-syntax %ext2-sblock-volume-name (identifier-syntax 120)) - -(define (read-ext2-superblock device) - "Return the raw contents of DEVICE's ext2 superblock as a bytevector, or #f -if DEVICE does not contain an ext2 file system." - (define %ext2-magic - ;; The magic bytes that identify an ext2 file system. - #xef53) - - (define superblock-size - ;; Size of the interesting part of an ext2 superblock. - 264) - - (define block - ;; The superblock contents. - (make-bytevector superblock-size)) - - (call-with-input-file device - (lambda (port) - (seek port 1024 SEEK_SET) - - ;; Note: work around . - (and (eqv? superblock-size (get-bytevector-n! port block 0 - superblock-size)) - (let ((magic (bytevector-u16-ref block %ext2-sblock-magic - %ext2-endianness))) - (and (= magic %ext2-magic) - block)))))) - -(define (ext2-superblock-uuid sblock) - "Return the UUID of ext2 superblock SBLOCK as a 16-byte bytevector." - (let ((uuid (make-bytevector 16))) - (bytevector-copy! sblock %ext2-sblock-uuid uuid 0 16) - uuid)) - -(define (ext2-superblock-volume-name sblock) - "Return the volume name of SBLOCK as a string of at most 16 characters, or -#f if SBLOCK has no volume name." - (let ((bv (make-bytevector 16))) - (bytevector-copy! sblock %ext2-sblock-volume-name bv 0 16) - - ;; This is a Latin-1, nul-terminated string. - (let ((bytes (take-while (negate zero?) (bytevector->u8-list bv)))) - (if (null? bytes) - #f - (list->string (map integer->char bytes)))))) - -(define (disk-partitions) - "Return the list of device names corresponding to valid disk partitions." - (define (partition? major minor) - (let ((marker (format #f "/sys/dev/block/~a:~a/partition" major minor))) - (catch 'system-error - (lambda () - (not (zero? (call-with-input-file marker read)))) - (lambda args - (if (= ENOENT (system-error-errno args)) - #f - (apply throw args)))))) - - (call-with-input-file "/proc/partitions" - (lambda (port) - ;; Skip the two header lines. - (read-line port) - (read-line port) - - ;; Read each subsequent line, and extract the last space-separated - ;; field. - (let loop ((parts '())) - (let ((line (read-line port))) - (if (eof-object? line) - (reverse parts) - (match (string-tokenize line) - (((= string->number major) (= string->number minor) - blocks name) - (if (partition? major minor) - (loop (cons name parts)) - (loop parts)))))))))) - -(define (partition-label-predicate label) - "Return a procedure that, when applied to a partition name such as \"sda1\", -return #t if that partition's volume name is LABEL." - (lambda (part) - (let* ((device (string-append "/dev/" part)) - (sblock (catch 'system-error - (lambda () - (read-ext2-superblock device)) - (lambda args - ;; When running on the hand-made /dev, - ;; 'disk-partitions' could return partitions for which - ;; we have no /dev node. Handle that gracefully. - (if (= ENOENT (system-error-errno args)) - (begin - (format (current-error-port) - "warning: device '~a' not found~%" - device) - #f) - (apply throw args)))))) - (and sblock - (let ((volume (ext2-superblock-volume-name sblock))) - (and volume - (string=? volume label))))))) - -(define (find-partition-by-label label) - "Return the first partition found whose volume name is LABEL, or #f if none -were found." - (and=> (find (partition-label-predicate label) - (disk-partitions)) - (cut string-append "/dev/" <>))) - -(define* (canonicalize-device-spec spec #:optional (title 'any)) - "Return the device name corresponding to SPEC. TITLE is a symbol, one of -the following: - - • 'device', in which case SPEC is known to designate a device node--e.g., - \"/dev/sda1\"; - • 'label', in which case SPEC is known to designate a partition label--e.g., - \"my-root-part\"; - • 'any', in which case SPEC can be anything. -" - (define max-trials - ;; Number of times we retry partition label resolution, 1 second per - ;; trial. Note: somebody reported a delay of 16 seconds (!) before their - ;; USB key would be detected by the kernel, so we must wait for at least - ;; this long. - 20) - - (define canonical-title - ;; The realm of canonicalization. - (if (eq? title 'any) - (if (string-prefix? "/" spec) - 'device - 'label) - title)) - - (case canonical-title - ((device) - ;; Nothing to do. - spec) - ((label) - ;; Resolve the label. - (let loop ((count 0)) - (let ((device (find-partition-by-label spec))) - (or device - ;; Some devices take a bit of time to appear, most notably USB - ;; storage devices. Thus, wait for the device to appear. - (if (> count max-trials) - (error "failed to resolve partition label" spec) - (begin - (format #t "waiting for partition '~a' to appear...~%" - spec) - (sleep 1) - (loop (+ 1 count)))))))) - ;; TODO: Add support for UUIDs. - (else - (error "unknown device title" title)))) - -(define* (make-disk-device-nodes base major #:optional (minor 0)) - "Make the block device nodes around BASE (something like \"/root/dev/sda\") -with the given MAJOR number, starting with MINOR." - (mknod base 'block-special #o644 (device-number major minor)) - (let loop ((i 1)) - (when (< i 6) - (mknod (string-append base (number->string i)) - 'block-special #o644 (device-number major (+ minor i))) - (loop (+ i 1))))) - -(define* (make-essential-device-nodes #:key (root "/")) - "Make essential device nodes under ROOT/dev." - ;; The hand-made udev! - - (define (scope dir) - (string-append root - (if (string-suffix? "/" root) - "" - "/") - dir)) - - (unless (file-exists? (scope "dev")) - (mkdir (scope "dev"))) - - ;; Make the device nodes for SCSI disks. - (make-disk-device-nodes (scope "dev/sda") 8) - (make-disk-device-nodes (scope "dev/sdb") 8 16) - (make-disk-device-nodes (scope "dev/sdc") 8 32) - (make-disk-device-nodes (scope "dev/sdd") 8 48) - - ;; SCSI CD-ROM devices (aka. "/dev/sr0" etc.). - (mknod (scope "dev/scd0") 'block-special #o644 (device-number 11 0)) - (mknod (scope "dev/scd1") 'block-special #o644 (device-number 11 1)) - - ;; The virtio (para-virtualized) block devices, as supported by QEMU/KVM. - (make-disk-device-nodes (scope "dev/vda") 252) - - ;; Memory (used by Xorg's VESA driver.) - (mknod (scope "dev/mem") 'char-special #o640 (device-number 1 1)) - (mknod (scope "dev/kmem") 'char-special #o640 (device-number 1 2)) - - ;; Inputs (used by Xorg.) - (unless (file-exists? (scope "dev/input")) - (mkdir (scope "dev/input"))) - (mknod (scope "dev/input/mice") 'char-special #o640 (device-number 13 63)) - (mknod (scope "dev/input/mouse0") 'char-special #o640 (device-number 13 32)) - (mknod (scope "dev/input/event0") 'char-special #o640 (device-number 13 64)) - - ;; System console. This node is magically created by the kernel on the - ;; initrd's root, so don't try to create it in that case. - (unless (string=? root "/") - (mknod (scope "dev/console") 'char-special #o600 - (device-number 5 1))) - - ;; TTYs. - (mknod (scope "dev/tty") 'char-special #o600 - (device-number 5 0)) - (chmod (scope "dev/tty") #o666) - (let loop ((n 0)) - (and (< n 50) - (let ((name (format #f "dev/tty~a" n))) - (mknod (scope name) 'char-special #o600 - (device-number 4 n)) - (loop (+ 1 n))))) - - ;; Serial line. - (mknod (scope "dev/ttyS0") 'char-special #o660 - (device-number 4 64)) - - ;; Pseudo ttys. - (mknod (scope "dev/ptmx") 'char-special #o666 - (device-number 5 2)) - (chmod (scope "dev/ptmx") #o666) - - ;; Create /dev/pts; it will be mounted later, at boot time. - (unless (file-exists? (scope "dev/pts")) - (mkdir (scope "dev/pts"))) - - ;; Rendez-vous point for syslogd. - (mknod (scope "dev/log") 'socket #o666 0) - (mknod (scope "dev/kmsg") 'char-special #o600 (device-number 1 11)) - - ;; Other useful nodes, notably relied on by guix-daemon. - (for-each (match-lambda - ((file major minor) - (mknod (scope file) 'char-special #o666 - (device-number major minor)) - (chmod (scope file) #o666))) - '(("dev/null" 1 3) - ("dev/zero" 1 5) - ("dev/full" 1 7) - ("dev/random" 1 8) - ("dev/urandom" 1 9))) - - (symlink "/proc/self/fd" (scope "dev/fd")) - (symlink "/proc/self/fd/0" (scope "dev/stdin")) - (symlink "/proc/self/fd/1" (scope "dev/stdout")) - (symlink "/proc/self/fd/2" (scope "dev/stderr")) - - ;; Loopback devices. - (let loop ((i 0)) - (when (< i 8) - (mknod (scope (string-append "dev/loop" (number->string i))) - 'block-special #o660 - (device-number 7 i)) - (loop (+ 1 i)))) - - ;; File systems in user space (FUSE). - (mknod (scope "dev/fuse") 'char-special #o666 (device-number 10 229))) - -(define %host-qemu-ipv4-address - (inet-pton AF_INET "10.0.2.10")) - -(define* (configure-qemu-networking #:optional (interface "eth0")) - "Setup the INTERFACE network interface and /etc/resolv.conf according to -QEMU's default networking settings (see net/slirp.c in QEMU for default -networking values.) Return #t if INTERFACE is up, #f otherwise." - (display "configuring QEMU networking...\n") - (let* ((sock (socket AF_INET SOCK_STREAM 0)) - (address (make-socket-address AF_INET %host-qemu-ipv4-address 0)) - (flags (network-interface-flags sock interface))) - (set-network-interface-address sock interface address) - (set-network-interface-flags sock interface (logior flags IFF_UP)) - - ;; Hello! We used to create /etc/resolv.conf here, with "nameserver - ;; 10.0.2.3\n". However, with Linux-libre 3.16, we're getting ENOSPC. - ;; And since it's actually unnecessary, it's gone. - - (logand (network-interface-flags sock interface) IFF_UP))) - -;; Linux mount flags, from libc's . -(define MS_RDONLY 1) -(define MS_NOSUID 2) -(define MS_NODEV 4) -(define MS_NOEXEC 8) -(define MS_BIND 4096) -(define MS_MOVE 8192) - -(define (bind-mount source target) - "Bind-mount SOURCE at TARGET." - (mount source target "" MS_BIND)) - -(define (load-linux-module* file) - "Load Linux module from FILE, the name of a `.ko' file." - (define (slurp module) - (call-with-input-file file get-bytevector-all)) - - (load-linux-module (slurp file))) - -(define (device-number major minor) - "Return the device number for the device with MAJOR and MINOR, for use as -the last argument of `mknod'." - (+ (* major 256) minor)) - -(define (pidof program) - "Return the PID of the first presumed instance of PROGRAM." - (let ((program (basename program))) - (find (lambda (pid) - (let ((exe (format #f "/proc/~a/exe" pid))) - (and=> (false-if-exception (readlink exe)) - (compose (cut string=? program <>) basename)))) - (filter-map string->number (scandir "/proc"))))) - -(define* (mount-root-file-system root type - #:key volatile-root? (unionfs "unionfs")) - "Mount the root file system of type TYPE at device ROOT. If VOLATILE-ROOT? -is true, mount ROOT read-only and make it a union with a writable tmpfs using -UNIONFS." - (define (mark-as-not-killable pid) - ;; Tell the 'user-processes' dmd service that PID must be kept alive when - ;; shutting down. - (mkdir-p "/root/etc/dmd") - (let ((port (open-file "/root/etc/dmd/do-not-kill" "a"))) - (chmod port #o600) - (write pid port) - (newline port) - (close-port port))) - - (catch #t - (lambda () - (if volatile-root? - (begin - (mkdir-p "/real-root") - (mount root "/real-root" type MS_RDONLY) - (mkdir-p "/rw-root") - (mount "none" "/rw-root" "tmpfs") - - ;; We want read-write /dev nodes. - (make-essential-device-nodes #:root "/rw-root") - - ;; Make /root a union of the tmpfs and the actual root. Use - ;; 'max_files' to set a high RLIMIT_NOFILE for the unionfs process - ;; itself. Failing to do that, we quickly run out of file - ;; descriptors; see . - (unless (zero? (system* unionfs "-o" - "cow,allow_other,use_ino,suid,dev,max_files=65536" - "/rw-root=RW:/real-root=RO" - "/root")) - (error "unionfs failed")) - - ;; Make sure unionfs remains alive till the end. Because - ;; 'fuse_daemonize' doesn't tell the PID of the forked daemon, we - ;; have to resort to 'pidof' here. - (mark-as-not-killable (pidof unionfs))) - (begin - (check-file-system root type) - (mount root "/root" type)))) - (lambda args - (format (current-error-port) "exception while mounting '~a': ~s~%" - root args) - (start-repl))) - - (copy-file "/proc/mounts" "/root/etc/mtab")) - -(define (check-file-system device type) - "Run a file system check of TYPE on DEVICE." - (define fsck - (string-append "fsck." type)) - - (let ((status (system* fsck "-v" "-p" device))) - (match (status:exit-val status) - (0 - #t) - (1 - (format (current-error-port) "'~a' corrected errors on ~a; continuing~%" - fsck device)) - (2 - (format (current-error-port) "'~a' corrected errors on ~a; rebooting~%" - fsck device) - (sleep 3) - (reboot)) - (code - (format (current-error-port) "'~a' exited with code ~a on ~a; spawning REPL~%" - fsck code device) - (start-repl))))) - -(define (mount-flags->bit-mask flags) - "Return the number suitable for the 'flags' argument of 'mount' that -corresponds to the symbols listed in FLAGS." - (let loop ((flags flags)) - (match flags - (('read-only rest ...) - (logior MS_RDONLY (loop rest))) - (('bind-mount rest ...) - (logior MS_BIND (loop rest))) - (('no-suid rest ...) - (logior MS_NOSUID (loop rest))) - (('no-dev rest ...) - (logior MS_NODEV (loop rest))) - (('no-exec rest ...) - (logior MS_NOEXEC (loop rest))) - (() - 0)))) - -(define* (mount-file-system spec #:key (root "/root")) - "Mount the file system described by SPEC under ROOT. SPEC must have the -form: - - (DEVICE TITLE MOUNT-POINT TYPE (FLAGS ...) OPTIONS CHECK?) - -DEVICE, MOUNT-POINT, and TYPE must be strings; OPTIONS can be a string or #f; -FLAGS must be a list of symbols. CHECK? is a Boolean indicating whether to -run a file system check." - (match spec - ((source title mount-point type (flags ...) options check?) - (let ((source (canonicalize-device-spec source title)) - (mount-point (string-append root "/" mount-point))) - (when check? - (check-file-system source type)) - (mkdir-p mount-point) - (mount source mount-point type (mount-flags->bit-mask flags) - (if options - (string->pointer options) - %null-pointer)) - - ;; Update /etc/mtab. - (mkdir-p (string-append root "/etc")) - (let ((port (open-file (string-append root "/etc/mtab") "a"))) - (format port "~a ~a ~a ~a 0 0~%" - source mount-point type (or options "")) - (close-port port)))))) - -(define (switch-root root) - "Switch to ROOT as the root file system, in a way similar to what -util-linux' switch_root(8) does." - (move-essential-file-systems root) - (chdir root) - - ;; Since we're about to 'rm -rf /', try to make sure we're on an initrd. - ;; TODO: Use 'statfs' to check the fs type, like klibc does. - (when (or (not (file-exists? "/init")) (directory-exists? "/home")) - (format (current-error-port) - "The root file system is probably not an initrd; \ -bailing out.~%root contents: ~s~%" (scandir "/")) - (force-output (current-error-port)) - (exit 1)) - - ;; Delete files from the old root, without crossing mount points (assuming - ;; there are no mount points in sub-directories.) That means we're leaving - ;; the empty ROOT directory behind us, but that's OK. - (let ((root-device (stat:dev (stat "/")))) - (for-each (lambda (file) - (unless (member file '("." "..")) - (let* ((file (string-append "/" file)) - (device (stat:dev (lstat file)))) - (when (= device root-device) - (delete-file-recursively file))))) - (scandir "/"))) - - ;; Make ROOT the new root. - (mount root "/" "" MS_MOVE) - (chroot ".") - (chdir "/") - - (when (file-exists? "/dev/console") - ;; Close the standard file descriptors since they refer to the old - ;; /dev/console, and reopen them. - (let ((console (open-file "/dev/console" "r+b0"))) - (for-each close-fdes '(0 1 2)) - - (dup2 (fileno console) 0) - (dup2 (fileno console) 1) - (dup2 (fileno console) 2) - - (close-port console)))) - - -(define* (boot-system #:key - (linux-modules '()) - qemu-guest-networking? - guile-modules-in-chroot? - volatile-root? - (mounts '())) - "This procedure is meant to be called from an initrd. Boot a system by -first loading LINUX-MODULES, then setting up QEMU guest networking if -QEMU-GUEST-NETWORKING? is true, mounting the file systems specified in MOUNTS, -and finally booting into the new root if any. The initrd supports kernel -command-line options '--load', '--root', and '--repl'. - -Mount the root file system, specified by the '--root' command-line argument, -if any. - -MOUNTS must be a list suitable for 'mount-file-system'. - -When GUILE-MODULES-IN-CHROOT? is true, make core Guile modules available in -the new root. - -When VOLATILE-ROOT? is true, the root file system is writable but any changes -to it are lost." - (define root-mount-point? - (match-lambda - ((device _ "/" _ ...) #t) - (_ #f))) - - (define root-fs-type - (or (any (match-lambda - ((device _ "/" type _ ...) type) - (_ #f)) - mounts) - "ext4")) - - (display "Welcome, this is GNU's early boot Guile.\n") - (display "Use '--repl' for an initrd REPL.\n\n") - - (call-with-error-handling - (lambda () - (mount-essential-file-systems) - (let* ((args (linux-command-line)) - (to-load (find-long-option "--load" args)) - (root (find-long-option "--root" args))) - - (when (member "--repl" args) - (start-repl)) - - (display "loading kernel modules...\n") - (for-each (compose load-linux-module* - (cut string-append "/modules/" <>)) - linux-modules) - - (when qemu-guest-networking? - (unless (configure-qemu-networking) - (display "network interface is DOWN\n"))) - - ;; Make /dev nodes. - (make-essential-device-nodes) - - ;; Prepare the real root file system under /root. - (unless (file-exists? "/root") - (mkdir "/root")) - (if root - (mount-root-file-system (canonicalize-device-spec root) - root-fs-type - #:volatile-root? volatile-root?) - (mount "none" "/root" "tmpfs")) - - (unless (file-exists? "/root/dev") - (mkdir "/root/dev") - (make-essential-device-nodes #:root "/root")) - - ;; Mount the specified file systems. - (for-each mount-file-system - (remove root-mount-point? mounts)) - - (when guile-modules-in-chroot? - ;; Copy the directories that contain .scm and .go files so that the - ;; child process in the chroot can load modules (we would bind-mount - ;; them but for some reason that fails with EINVAL -- XXX). - (mkdir-p "/root/share") - (mkdir-p "/root/lib") - (mount "none" "/root/share" "tmpfs") - (mount "none" "/root/lib" "tmpfs") - (copy-recursively "/share" "/root/share" - #:log (%make-void-port "w")) - (copy-recursively "/lib" "/root/lib" - #:log (%make-void-port "w"))) - - (if to-load - (begin - (switch-root "/root") - (format #t "loading '~a'...\n" to-load) - - ;; TODO: Remove /lib, /share, and /loader.go. - (primitive-load to-load) - - (format (current-error-port) - "boot program '~a' terminated, rebooting~%" - to-load) - (sleep 2) - (reboot)) - (begin - (display "no boot file passed via '--load'\n") - (display "entering a warm and cozy REPL\n") - (start-repl))))))) - -;;; linux-initrd.scm ends here diff --git a/guix/build/vm.scm b/guix/build/vm.scm deleted file mode 100644 index 11e05f70be..0000000000 --- a/guix/build/vm.scm +++ /dev/null @@ -1,259 +0,0 @@ -;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013, 2014 Ludovic Courtès -;;; -;;; This file is part of GNU Guix. -;;; -;;; GNU Guix is free software; you can redistribute it and/or modify it -;;; under the terms of the GNU General Public License as published by -;;; the Free Software Foundation; either version 3 of the License, or (at -;;; your option) any later version. -;;; -;;; GNU Guix is distributed in the hope that it will be useful, but -;;; WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;;; GNU General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with GNU Guix. If not, see . - -(define-module (guix build vm) - #:use-module (guix build utils) - #:use-module (guix build linux-initrd) - #:use-module (guix build install) - #:use-module (ice-9 match) - #:use-module (ice-9 regex) - #:use-module (ice-9 rdelim) - #:use-module (srfi srfi-1) - #:use-module (srfi srfi-26) - #:export (qemu-command - load-in-linux-vm - format-partition - initialize-root-partition - initialize-partition-table - initialize-hard-disk)) - -;;; Commentary: -;;; -;;; This module provides supporting code to run virtual machines and build -;;; virtual machine images using QEMU. -;;; -;;; Code: - -(define* (qemu-command #:optional (system %host-type)) - "Return the default name of the QEMU command for SYSTEM." - (let ((cpu (substring %host-type 0 - (string-index %host-type #\-)))) - (string-append "qemu-system-" - (if (string-match "^i[3456]86$" cpu) - "i386" - cpu)))) - -(define* (load-in-linux-vm builder - #:key - output - (qemu (qemu-command)) (memory-size 512) - linux initrd - make-disk-image? (disk-image-size 100) - (disk-image-format "qcow2") - (references-graphs '())) - "Run BUILDER, a Scheme file, into a VM running LINUX with INITRD, and copy -the result to OUTPUT. - -When MAKE-DISK-IMAGE? is true, OUTPUT will contain a VM image of -DISK-IMAGE-SIZE MiB resulting from the execution of BUILDER, which may access -it via /dev/hda. - -REFERENCES-GRAPHS can specify a list of reference-graph files as produced by -the #:references-graphs parameter of 'derivation'." - (define image-file - (string-append "image." disk-image-format)) - - (when make-disk-image? - (unless (zero? (system* "qemu-img" "create" "-f" disk-image-format - image-file - (number->string disk-image-size))) - (error "qemu-img failed"))) - - (mkdir "xchg") - - (match references-graphs - ((graph-files ...) - ;; Copy the reference-graph files under xchg/ so EXP can access it. - (map (lambda (file) - (copy-file file (string-append "xchg/" file))) - graph-files)) - (_ #f)) - - (unless (zero? - (apply system* qemu "-enable-kvm" "-nographic" "-no-reboot" - "-m" (number->string memory-size) - "-net" "nic,model=virtio" - "-virtfs" - (string-append "local,id=store_dev,path=" - (%store-directory) - ",security_model=none,mount_tag=store") - "-virtfs" - (string-append "local,id=xchg_dev,path=xchg" - ",security_model=none,mount_tag=xchg") - "-kernel" linux - "-initrd" initrd - "-append" (string-append "console=ttyS0 --load=" - builder) - (if make-disk-image? - `("-drive" ,(string-append "file=" image-file - ",if=virtio")) - '()))) - (error "qemu failed" qemu)) - - (if make-disk-image? - (copy-file image-file output) - (begin - (mkdir output) - (copy-recursively "xchg" output)))) - -(define (read-reference-graph port) - "Return a list of store paths from the reference graph at PORT. -The data at PORT is the format produced by #:references-graphs." - (let loop ((line (read-line port)) - (result '())) - (cond ((eof-object? line) - (delete-duplicates result)) - ((string-prefix? "/" line) - (loop (read-line port) - (cons line result))) - (else - (loop (read-line port) - result))))) - -(define* (initialize-partition-table device partition-size - #:key - (label-type "msdos") - (offset (expt 2 20))) - "Create on DEVICE a partition table of type LABEL-TYPE, with a single -partition of PARTITION-SIZE bytes starting at OFFSET bytes. Return #t on -success." - (format #t "creating partition table with a ~a B partition...\n" - partition-size) - (unless (zero? (system* "parted" device "mklabel" label-type - "mkpart" "primary" "ext2" - (format #f "~aB" offset) - (format #f "~aB" partition-size))) - (error "failed to create partition table"))) - -(define* (populate-store reference-graphs target) - "Populate the store under directory TARGET with the items specified in -REFERENCE-GRAPHS, a list of reference-graph files." - (define store - (string-append target (%store-directory))) - - (define (things-to-copy) - ;; Return the list of store files to copy to the image. - (define (graph-from-file file) - (call-with-input-file file read-reference-graph)) - - (delete-duplicates (append-map graph-from-file reference-graphs))) - - (mkdir-p store) - (chmod store #o1775) - (for-each (lambda (thing) - (copy-recursively thing - (string-append target thing))) - (things-to-copy))) - -(define MS_BIND 4096) ; again! - -(define* (format-partition partition type - #:key label) - "Create a file system TYPE on PARTITION. If LABEL is true, use that as the -volume name." - (format #t "creating ~a partition...\n" type) - (unless (zero? (apply system* (string-append "mkfs." type) - "-F" partition - (if label - `("-L" ,label) - '()))) - (error "failed to create partition"))) - -(define* (initialize-root-partition target-directory - #:key copy-closures? register-closures? - closures system-directory) - "Initialize the root partition mounted at TARGET-DIRECTORY." - (define target-store - (string-append target-directory (%store-directory))) - - (when copy-closures? - ;; Populate the store. - (populate-store (map (cut string-append "/xchg/" <>) closures) - target-directory)) - - ;; Populate /dev. - (make-essential-device-nodes #:root target-directory) - - ;; Optionally, register the inputs in the image's store. - (when register-closures? - (unless copy-closures? - ;; XXX: 'guix-register' wants to palpate the things it registers, so - ;; bind-mount the store on the target. - (mkdir-p target-store) - (mount (%store-directory) target-store "" MS_BIND)) - - (display "registering closures...\n") - (for-each (lambda (closure) - (register-closure target-directory - (string-append "/xchg/" closure))) - closures) - (unless copy-closures? - (system* "umount" target-store))) - - ;; Add the non-store directories and files. - (display "populating...\n") - (populate-root-file-system system-directory target-directory)) - -(define* (initialize-hard-disk device - #:key - system-directory - grub.cfg - disk-image-size - (file-system-type "ext4") - file-system-label - (closures '()) - copy-closures? - (register-closures? #t)) - "Initialize DEVICE, a disk of DISK-IMAGE-SIZE bytes, with a FILE-SYSTEM-TYPE -partition with (optionally) FILE-SYSTEM-LABEL as its volume name, and with -GRUB installed. If REGISTER-CLOSURES? is true, register all of CLOSURES is -the partition's store. If COPY-CLOSURES? is true, copy all of CLOSURES to the -partition. SYSTEM-DIRECTORY is the name of the directory of the 'system' -derivation." - (define target-directory - "/fs") - - (define partition - (string-append device "1")) - - (initialize-partition-table device - (- disk-image-size (* 5 (expt 2 20)))) - - (format-partition partition file-system-type - #:label file-system-label) - - (display "mounting partition...\n") - (mkdir target-directory) - (mount partition target-directory file-system-type) - - (initialize-root-partition target-directory - #:system-directory system-directory - #:copy-closures? copy-closures? - #:register-closures? register-closures? - #:closures closures) - - (install-grub grub.cfg device target-directory) - - ;; 'guix-register' resets timestamps and everything, so no need to do it - ;; once more in that case. - (unless register-closures? - (reset-timestamps target-directory)) - - (zero? (system* "umount" target-directory))) - -;;; vm.scm ends here diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index 4f1869af38..7c0dde9030 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -28,7 +28,7 @@ #:use-module (guix profiles) #:use-module (guix scripts build) #:use-module (guix build utils) - #:use-module (guix build install) + #:use-module (gnu build install) #:use-module (gnu system) #:use-module (gnu system vm) #:use-module (gnu system grub) -- cgit v1.2.3 From 8a9e21d1f719748213414343cd02ec113ebe90c1 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 3 Sep 2014 11:14:12 +0200 Subject: Rename (gnu build linux-initrd) to (gnu build linux-boot). * gnu/build/linux-initrd.scm: Rename to... * gnu/build/linux-boot.scm: ... this. * gnu-system.am (GNU_SYSTEM_MODULES): Adjust accordingly. * gnu/build/activation.scm, gnu/build/vm.scm, gnu/services/base.scm, gnu/services/dmd.scm, gnu/system.scm, gnu/system/linux-initrd.scm, gnu/system/vm.scm: Adjust accordingly. --- gnu-system.am | 2 +- gnu/build/activation.scm | 2 +- gnu/build/linux-boot.scm | 702 ++++++++++++++++++++++++++++++++++++++++++++ gnu/build/linux-initrd.scm | 702 -------------------------------------------- gnu/build/vm.scm | 2 +- gnu/services/base.scm | 2 +- gnu/services/dmd.scm | 4 +- gnu/system.scm | 2 +- gnu/system/linux-initrd.scm | 6 +- gnu/system/vm.scm | 2 +- 10 files changed, 713 insertions(+), 713 deletions(-) create mode 100644 gnu/build/linux-boot.scm delete mode 100644 gnu/build/linux-initrd.scm (limited to 'gnu') diff --git a/gnu-system.am b/gnu-system.am index 2c303ac109..8e7de7c622 100644 --- a/gnu-system.am +++ b/gnu-system.am @@ -281,7 +281,7 @@ GNU_SYSTEM_MODULES = \ \ gnu/build/activation.scm \ gnu/build/install.scm \ - gnu/build/linux-initrd.scm \ + gnu/build/linux-boot.scm \ gnu/build/vm.scm diff --git a/gnu/build/activation.scm b/gnu/build/activation.scm index bb1165ac47..362669cbf9 100644 --- a/gnu/build/activation.scm +++ b/gnu/build/activation.scm @@ -17,7 +17,7 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu build activation) - #:use-module (gnu build linux-initrd) + #:use-module (gnu build linux-boot) #:use-module (guix build utils) #:use-module (ice-9 ftw) #:use-module (ice-9 match) diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm new file mode 100644 index 0000000000..24000e191a --- /dev/null +++ b/gnu/build/linux-boot.scm @@ -0,0 +1,702 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2013, 2014 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu build linux-boot) + #:use-module (rnrs io ports) + #:use-module (rnrs bytevectors) + #:use-module (system foreign) + #:use-module (system repl error-handling) + #:autoload (system repl repl) (start-repl) + #:autoload (system base compile) (compile-file) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:use-module (ice-9 match) + #:use-module (ice-9 rdelim) + #:use-module (ice-9 ftw) + #:use-module (guix build utils) + #:export (mount-essential-file-systems + linux-command-line + find-long-option + make-essential-device-nodes + configure-qemu-networking + + disk-partitions + partition-label-predicate + find-partition-by-label + canonicalize-device-spec + + mount-flags->bit-mask + check-file-system + mount-file-system + bind-mount + + load-linux-module* + device-number + boot-system)) + +;;; Commentary: +;;; +;;; Utility procedures useful in a Linux initial RAM disk (initrd). Note that +;;; many of these use procedures not yet available in vanilla Guile (`mount', +;;; `load-linux-module', etc.); these are provided by a Guile patch used in +;;; the GNU distribution. +;;; +;;; Code: + +(define* (mount-essential-file-systems #:key (root "/")) + "Mount /proc and /sys under ROOT." + (define (scope dir) + (string-append root + (if (string-suffix? "/" root) + "" + "/") + dir)) + + (unless (file-exists? (scope "proc")) + (mkdir (scope "proc"))) + (mount "none" (scope "proc") "proc") + + (unless (file-exists? (scope "sys")) + (mkdir (scope "sys"))) + (mount "none" (scope "sys") "sysfs")) + +(define (move-essential-file-systems root) + "Move currently mounted essential file systems to ROOT." + (for-each (lambda (dir) + (let ((target (string-append root dir))) + (unless (file-exists? target) + (mkdir target)) + (mount dir target "" MS_MOVE))) + '("/proc" "/sys"))) + +(define (linux-command-line) + "Return the Linux kernel command line as a list of strings." + (string-tokenize + (call-with-input-file "/proc/cmdline" + get-string-all))) + +(define (find-long-option option arguments) + "Find OPTION among ARGUMENTS, where OPTION is something like \"--load\". +Return the value associated with OPTION, or #f on failure." + (let ((opt (string-append option "="))) + (and=> (find (cut string-prefix? opt <>) + arguments) + (lambda (arg) + (substring arg (+ 1 (string-index arg #\=))))))) + +(define-syntax %ext2-endianness + ;; Endianness of ext2 file systems. + (identifier-syntax (endianness little))) + +;; Offset in bytes of interesting parts of an ext2 superblock. See +;; . +;; TODO: Use "packed structs" from Guile-OpenGL or similar. +(define-syntax %ext2-sblock-magic (identifier-syntax 56)) +(define-syntax %ext2-sblock-creator-os (identifier-syntax 72)) +(define-syntax %ext2-sblock-uuid (identifier-syntax 104)) +(define-syntax %ext2-sblock-volume-name (identifier-syntax 120)) + +(define (read-ext2-superblock device) + "Return the raw contents of DEVICE's ext2 superblock as a bytevector, or #f +if DEVICE does not contain an ext2 file system." + (define %ext2-magic + ;; The magic bytes that identify an ext2 file system. + #xef53) + + (define superblock-size + ;; Size of the interesting part of an ext2 superblock. + 264) + + (define block + ;; The superblock contents. + (make-bytevector superblock-size)) + + (call-with-input-file device + (lambda (port) + (seek port 1024 SEEK_SET) + + ;; Note: work around . + (and (eqv? superblock-size (get-bytevector-n! port block 0 + superblock-size)) + (let ((magic (bytevector-u16-ref block %ext2-sblock-magic + %ext2-endianness))) + (and (= magic %ext2-magic) + block)))))) + +(define (ext2-superblock-uuid sblock) + "Return the UUID of ext2 superblock SBLOCK as a 16-byte bytevector." + (let ((uuid (make-bytevector 16))) + (bytevector-copy! sblock %ext2-sblock-uuid uuid 0 16) + uuid)) + +(define (ext2-superblock-volume-name sblock) + "Return the volume name of SBLOCK as a string of at most 16 characters, or +#f if SBLOCK has no volume name." + (let ((bv (make-bytevector 16))) + (bytevector-copy! sblock %ext2-sblock-volume-name bv 0 16) + + ;; This is a Latin-1, nul-terminated string. + (let ((bytes (take-while (negate zero?) (bytevector->u8-list bv)))) + (if (null? bytes) + #f + (list->string (map integer->char bytes)))))) + +(define (disk-partitions) + "Return the list of device names corresponding to valid disk partitions." + (define (partition? major minor) + (let ((marker (format #f "/sys/dev/block/~a:~a/partition" major minor))) + (catch 'system-error + (lambda () + (not (zero? (call-with-input-file marker read)))) + (lambda args + (if (= ENOENT (system-error-errno args)) + #f + (apply throw args)))))) + + (call-with-input-file "/proc/partitions" + (lambda (port) + ;; Skip the two header lines. + (read-line port) + (read-line port) + + ;; Read each subsequent line, and extract the last space-separated + ;; field. + (let loop ((parts '())) + (let ((line (read-line port))) + (if (eof-object? line) + (reverse parts) + (match (string-tokenize line) + (((= string->number major) (= string->number minor) + blocks name) + (if (partition? major minor) + (loop (cons name parts)) + (loop parts)))))))))) + +(define (partition-label-predicate label) + "Return a procedure that, when applied to a partition name such as \"sda1\", +return #t if that partition's volume name is LABEL." + (lambda (part) + (let* ((device (string-append "/dev/" part)) + (sblock (catch 'system-error + (lambda () + (read-ext2-superblock device)) + (lambda args + ;; When running on the hand-made /dev, + ;; 'disk-partitions' could return partitions for which + ;; we have no /dev node. Handle that gracefully. + (if (= ENOENT (system-error-errno args)) + (begin + (format (current-error-port) + "warning: device '~a' not found~%" + device) + #f) + (apply throw args)))))) + (and sblock + (let ((volume (ext2-superblock-volume-name sblock))) + (and volume + (string=? volume label))))))) + +(define (find-partition-by-label label) + "Return the first partition found whose volume name is LABEL, or #f if none +were found." + (and=> (find (partition-label-predicate label) + (disk-partitions)) + (cut string-append "/dev/" <>))) + +(define* (canonicalize-device-spec spec #:optional (title 'any)) + "Return the device name corresponding to SPEC. TITLE is a symbol, one of +the following: + + • 'device', in which case SPEC is known to designate a device node--e.g., + \"/dev/sda1\"; + • 'label', in which case SPEC is known to designate a partition label--e.g., + \"my-root-part\"; + • 'any', in which case SPEC can be anything. +" + (define max-trials + ;; Number of times we retry partition label resolution, 1 second per + ;; trial. Note: somebody reported a delay of 16 seconds (!) before their + ;; USB key would be detected by the kernel, so we must wait for at least + ;; this long. + 20) + + (define canonical-title + ;; The realm of canonicalization. + (if (eq? title 'any) + (if (string-prefix? "/" spec) + 'device + 'label) + title)) + + (case canonical-title + ((device) + ;; Nothing to do. + spec) + ((label) + ;; Resolve the label. + (let loop ((count 0)) + (let ((device (find-partition-by-label spec))) + (or device + ;; Some devices take a bit of time to appear, most notably USB + ;; storage devices. Thus, wait for the device to appear. + (if (> count max-trials) + (error "failed to resolve partition label" spec) + (begin + (format #t "waiting for partition '~a' to appear...~%" + spec) + (sleep 1) + (loop (+ 1 count)))))))) + ;; TODO: Add support for UUIDs. + (else + (error "unknown device title" title)))) + +(define* (make-disk-device-nodes base major #:optional (minor 0)) + "Make the block device nodes around BASE (something like \"/root/dev/sda\") +with the given MAJOR number, starting with MINOR." + (mknod base 'block-special #o644 (device-number major minor)) + (let loop ((i 1)) + (when (< i 6) + (mknod (string-append base (number->string i)) + 'block-special #o644 (device-number major (+ minor i))) + (loop (+ i 1))))) + +(define* (make-essential-device-nodes #:key (root "/")) + "Make essential device nodes under ROOT/dev." + ;; The hand-made udev! + + (define (scope dir) + (string-append root + (if (string-suffix? "/" root) + "" + "/") + dir)) + + (unless (file-exists? (scope "dev")) + (mkdir (scope "dev"))) + + ;; Make the device nodes for SCSI disks. + (make-disk-device-nodes (scope "dev/sda") 8) + (make-disk-device-nodes (scope "dev/sdb") 8 16) + (make-disk-device-nodes (scope "dev/sdc") 8 32) + (make-disk-device-nodes (scope "dev/sdd") 8 48) + + ;; SCSI CD-ROM devices (aka. "/dev/sr0" etc.). + (mknod (scope "dev/scd0") 'block-special #o644 (device-number 11 0)) + (mknod (scope "dev/scd1") 'block-special #o644 (device-number 11 1)) + + ;; The virtio (para-virtualized) block devices, as supported by QEMU/KVM. + (make-disk-device-nodes (scope "dev/vda") 252) + + ;; Memory (used by Xorg's VESA driver.) + (mknod (scope "dev/mem") 'char-special #o640 (device-number 1 1)) + (mknod (scope "dev/kmem") 'char-special #o640 (device-number 1 2)) + + ;; Inputs (used by Xorg.) + (unless (file-exists? (scope "dev/input")) + (mkdir (scope "dev/input"))) + (mknod (scope "dev/input/mice") 'char-special #o640 (device-number 13 63)) + (mknod (scope "dev/input/mouse0") 'char-special #o640 (device-number 13 32)) + (mknod (scope "dev/input/event0") 'char-special #o640 (device-number 13 64)) + + ;; System console. This node is magically created by the kernel on the + ;; initrd's root, so don't try to create it in that case. + (unless (string=? root "/") + (mknod (scope "dev/console") 'char-special #o600 + (device-number 5 1))) + + ;; TTYs. + (mknod (scope "dev/tty") 'char-special #o600 + (device-number 5 0)) + (chmod (scope "dev/tty") #o666) + (let loop ((n 0)) + (and (< n 50) + (let ((name (format #f "dev/tty~a" n))) + (mknod (scope name) 'char-special #o600 + (device-number 4 n)) + (loop (+ 1 n))))) + + ;; Serial line. + (mknod (scope "dev/ttyS0") 'char-special #o660 + (device-number 4 64)) + + ;; Pseudo ttys. + (mknod (scope "dev/ptmx") 'char-special #o666 + (device-number 5 2)) + (chmod (scope "dev/ptmx") #o666) + + ;; Create /dev/pts; it will be mounted later, at boot time. + (unless (file-exists? (scope "dev/pts")) + (mkdir (scope "dev/pts"))) + + ;; Rendez-vous point for syslogd. + (mknod (scope "dev/log") 'socket #o666 0) + (mknod (scope "dev/kmsg") 'char-special #o600 (device-number 1 11)) + + ;; Other useful nodes, notably relied on by guix-daemon. + (for-each (match-lambda + ((file major minor) + (mknod (scope file) 'char-special #o666 + (device-number major minor)) + (chmod (scope file) #o666))) + '(("dev/null" 1 3) + ("dev/zero" 1 5) + ("dev/full" 1 7) + ("dev/random" 1 8) + ("dev/urandom" 1 9))) + + (symlink "/proc/self/fd" (scope "dev/fd")) + (symlink "/proc/self/fd/0" (scope "dev/stdin")) + (symlink "/proc/self/fd/1" (scope "dev/stdout")) + (symlink "/proc/self/fd/2" (scope "dev/stderr")) + + ;; Loopback devices. + (let loop ((i 0)) + (when (< i 8) + (mknod (scope (string-append "dev/loop" (number->string i))) + 'block-special #o660 + (device-number 7 i)) + (loop (+ 1 i)))) + + ;; File systems in user space (FUSE). + (mknod (scope "dev/fuse") 'char-special #o666 (device-number 10 229))) + +(define %host-qemu-ipv4-address + (inet-pton AF_INET "10.0.2.10")) + +(define* (configure-qemu-networking #:optional (interface "eth0")) + "Setup the INTERFACE network interface and /etc/resolv.conf according to +QEMU's default networking settings (see net/slirp.c in QEMU for default +networking values.) Return #t if INTERFACE is up, #f otherwise." + (display "configuring QEMU networking...\n") + (let* ((sock (socket AF_INET SOCK_STREAM 0)) + (address (make-socket-address AF_INET %host-qemu-ipv4-address 0)) + (flags (network-interface-flags sock interface))) + (set-network-interface-address sock interface address) + (set-network-interface-flags sock interface (logior flags IFF_UP)) + + ;; Hello! We used to create /etc/resolv.conf here, with "nameserver + ;; 10.0.2.3\n". However, with Linux-libre 3.16, we're getting ENOSPC. + ;; And since it's actually unnecessary, it's gone. + + (logand (network-interface-flags sock interface) IFF_UP))) + +;; Linux mount flags, from libc's . +(define MS_RDONLY 1) +(define MS_NOSUID 2) +(define MS_NODEV 4) +(define MS_NOEXEC 8) +(define MS_BIND 4096) +(define MS_MOVE 8192) + +(define (bind-mount source target) + "Bind-mount SOURCE at TARGET." + (mount source target "" MS_BIND)) + +(define (load-linux-module* file) + "Load Linux module from FILE, the name of a `.ko' file." + (define (slurp module) + (call-with-input-file file get-bytevector-all)) + + (load-linux-module (slurp file))) + +(define (device-number major minor) + "Return the device number for the device with MAJOR and MINOR, for use as +the last argument of `mknod'." + (+ (* major 256) minor)) + +(define (pidof program) + "Return the PID of the first presumed instance of PROGRAM." + (let ((program (basename program))) + (find (lambda (pid) + (let ((exe (format #f "/proc/~a/exe" pid))) + (and=> (false-if-exception (readlink exe)) + (compose (cut string=? program <>) basename)))) + (filter-map string->number (scandir "/proc"))))) + +(define* (mount-root-file-system root type + #:key volatile-root? (unionfs "unionfs")) + "Mount the root file system of type TYPE at device ROOT. If VOLATILE-ROOT? +is true, mount ROOT read-only and make it a union with a writable tmpfs using +UNIONFS." + (define (mark-as-not-killable pid) + ;; Tell the 'user-processes' dmd service that PID must be kept alive when + ;; shutting down. + (mkdir-p "/root/etc/dmd") + (let ((port (open-file "/root/etc/dmd/do-not-kill" "a"))) + (chmod port #o600) + (write pid port) + (newline port) + (close-port port))) + + (catch #t + (lambda () + (if volatile-root? + (begin + (mkdir-p "/real-root") + (mount root "/real-root" type MS_RDONLY) + (mkdir-p "/rw-root") + (mount "none" "/rw-root" "tmpfs") + + ;; We want read-write /dev nodes. + (make-essential-device-nodes #:root "/rw-root") + + ;; Make /root a union of the tmpfs and the actual root. Use + ;; 'max_files' to set a high RLIMIT_NOFILE for the unionfs process + ;; itself. Failing to do that, we quickly run out of file + ;; descriptors; see . + (unless (zero? (system* unionfs "-o" + "cow,allow_other,use_ino,suid,dev,max_files=65536" + "/rw-root=RW:/real-root=RO" + "/root")) + (error "unionfs failed")) + + ;; Make sure unionfs remains alive till the end. Because + ;; 'fuse_daemonize' doesn't tell the PID of the forked daemon, we + ;; have to resort to 'pidof' here. + (mark-as-not-killable (pidof unionfs))) + (begin + (check-file-system root type) + (mount root "/root" type)))) + (lambda args + (format (current-error-port) "exception while mounting '~a': ~s~%" + root args) + (start-repl))) + + (copy-file "/proc/mounts" "/root/etc/mtab")) + +(define (check-file-system device type) + "Run a file system check of TYPE on DEVICE." + (define fsck + (string-append "fsck." type)) + + (let ((status (system* fsck "-v" "-p" device))) + (match (status:exit-val status) + (0 + #t) + (1 + (format (current-error-port) "'~a' corrected errors on ~a; continuing~%" + fsck device)) + (2 + (format (current-error-port) "'~a' corrected errors on ~a; rebooting~%" + fsck device) + (sleep 3) + (reboot)) + (code + (format (current-error-port) "'~a' exited with code ~a on ~a; spawning REPL~%" + fsck code device) + (start-repl))))) + +(define (mount-flags->bit-mask flags) + "Return the number suitable for the 'flags' argument of 'mount' that +corresponds to the symbols listed in FLAGS." + (let loop ((flags flags)) + (match flags + (('read-only rest ...) + (logior MS_RDONLY (loop rest))) + (('bind-mount rest ...) + (logior MS_BIND (loop rest))) + (('no-suid rest ...) + (logior MS_NOSUID (loop rest))) + (('no-dev rest ...) + (logior MS_NODEV (loop rest))) + (('no-exec rest ...) + (logior MS_NOEXEC (loop rest))) + (() + 0)))) + +(define* (mount-file-system spec #:key (root "/root")) + "Mount the file system described by SPEC under ROOT. SPEC must have the +form: + + (DEVICE TITLE MOUNT-POINT TYPE (FLAGS ...) OPTIONS CHECK?) + +DEVICE, MOUNT-POINT, and TYPE must be strings; OPTIONS can be a string or #f; +FLAGS must be a list of symbols. CHECK? is a Boolean indicating whether to +run a file system check." + (match spec + ((source title mount-point type (flags ...) options check?) + (let ((source (canonicalize-device-spec source title)) + (mount-point (string-append root "/" mount-point))) + (when check? + (check-file-system source type)) + (mkdir-p mount-point) + (mount source mount-point type (mount-flags->bit-mask flags) + (if options + (string->pointer options) + %null-pointer)) + + ;; Update /etc/mtab. + (mkdir-p (string-append root "/etc")) + (let ((port (open-file (string-append root "/etc/mtab") "a"))) + (format port "~a ~a ~a ~a 0 0~%" + source mount-point type (or options "")) + (close-port port)))))) + +(define (switch-root root) + "Switch to ROOT as the root file system, in a way similar to what +util-linux' switch_root(8) does." + (move-essential-file-systems root) + (chdir root) + + ;; Since we're about to 'rm -rf /', try to make sure we're on an initrd. + ;; TODO: Use 'statfs' to check the fs type, like klibc does. + (when (or (not (file-exists? "/init")) (directory-exists? "/home")) + (format (current-error-port) + "The root file system is probably not an initrd; \ +bailing out.~%root contents: ~s~%" (scandir "/")) + (force-output (current-error-port)) + (exit 1)) + + ;; Delete files from the old root, without crossing mount points (assuming + ;; there are no mount points in sub-directories.) That means we're leaving + ;; the empty ROOT directory behind us, but that's OK. + (let ((root-device (stat:dev (stat "/")))) + (for-each (lambda (file) + (unless (member file '("." "..")) + (let* ((file (string-append "/" file)) + (device (stat:dev (lstat file)))) + (when (= device root-device) + (delete-file-recursively file))))) + (scandir "/"))) + + ;; Make ROOT the new root. + (mount root "/" "" MS_MOVE) + (chroot ".") + (chdir "/") + + (when (file-exists? "/dev/console") + ;; Close the standard file descriptors since they refer to the old + ;; /dev/console, and reopen them. + (let ((console (open-file "/dev/console" "r+b0"))) + (for-each close-fdes '(0 1 2)) + + (dup2 (fileno console) 0) + (dup2 (fileno console) 1) + (dup2 (fileno console) 2) + + (close-port console)))) + + +(define* (boot-system #:key + (linux-modules '()) + qemu-guest-networking? + guile-modules-in-chroot? + volatile-root? + (mounts '())) + "This procedure is meant to be called from an initrd. Boot a system by +first loading LINUX-MODULES, then setting up QEMU guest networking if +QEMU-GUEST-NETWORKING? is true, mounting the file systems specified in MOUNTS, +and finally booting into the new root if any. The initrd supports kernel +command-line options '--load', '--root', and '--repl'. + +Mount the root file system, specified by the '--root' command-line argument, +if any. + +MOUNTS must be a list suitable for 'mount-file-system'. + +When GUILE-MODULES-IN-CHROOT? is true, make core Guile modules available in +the new root. + +When VOLATILE-ROOT? is true, the root file system is writable but any changes +to it are lost." + (define root-mount-point? + (match-lambda + ((device _ "/" _ ...) #t) + (_ #f))) + + (define root-fs-type + (or (any (match-lambda + ((device _ "/" type _ ...) type) + (_ #f)) + mounts) + "ext4")) + + (display "Welcome, this is GNU's early boot Guile.\n") + (display "Use '--repl' for an initrd REPL.\n\n") + + (call-with-error-handling + (lambda () + (mount-essential-file-systems) + (let* ((args (linux-command-line)) + (to-load (find-long-option "--load" args)) + (root (find-long-option "--root" args))) + + (when (member "--repl" args) + (start-repl)) + + (display "loading kernel modules...\n") + (for-each (compose load-linux-module* + (cut string-append "/modules/" <>)) + linux-modules) + + (when qemu-guest-networking? + (unless (configure-qemu-networking) + (display "network interface is DOWN\n"))) + + ;; Make /dev nodes. + (make-essential-device-nodes) + + ;; Prepare the real root file system under /root. + (unless (file-exists? "/root") + (mkdir "/root")) + (if root + (mount-root-file-system (canonicalize-device-spec root) + root-fs-type + #:volatile-root? volatile-root?) + (mount "none" "/root" "tmpfs")) + + (unless (file-exists? "/root/dev") + (mkdir "/root/dev") + (make-essential-device-nodes #:root "/root")) + + ;; Mount the specified file systems. + (for-each mount-file-system + (remove root-mount-point? mounts)) + + (when guile-modules-in-chroot? + ;; Copy the directories that contain .scm and .go files so that the + ;; child process in the chroot can load modules (we would bind-mount + ;; them but for some reason that fails with EINVAL -- XXX). + (mkdir-p "/root/share") + (mkdir-p "/root/lib") + (mount "none" "/root/share" "tmpfs") + (mount "none" "/root/lib" "tmpfs") + (copy-recursively "/share" "/root/share" + #:log (%make-void-port "w")) + (copy-recursively "/lib" "/root/lib" + #:log (%make-void-port "w"))) + + (if to-load + (begin + (switch-root "/root") + (format #t "loading '~a'...\n" to-load) + + ;; TODO: Remove /lib, /share, and /loader.go. + (primitive-load to-load) + + (format (current-error-port) + "boot program '~a' terminated, rebooting~%" + to-load) + (sleep 2) + (reboot)) + (begin + (display "no boot file passed via '--load'\n") + (display "entering a warm and cozy REPL\n") + (start-repl))))))) + +;;; linux-initrd.scm ends here diff --git a/gnu/build/linux-initrd.scm b/gnu/build/linux-initrd.scm deleted file mode 100644 index 60c5eec10f..0000000000 --- a/gnu/build/linux-initrd.scm +++ /dev/null @@ -1,702 +0,0 @@ -;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013, 2014 Ludovic Courtès -;;; -;;; This file is part of GNU Guix. -;;; -;;; GNU Guix is free software; you can redistribute it and/or modify it -;;; under the terms of the GNU General Public License as published by -;;; the Free Software Foundation; either version 3 of the License, or (at -;;; your option) any later version. -;;; -;;; GNU Guix is distributed in the hope that it will be useful, but -;;; WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;;; GNU General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with GNU Guix. If not, see . - -(define-module (gnu build linux-initrd) - #:use-module (rnrs io ports) - #:use-module (rnrs bytevectors) - #:use-module (system foreign) - #:use-module (system repl error-handling) - #:autoload (system repl repl) (start-repl) - #:autoload (system base compile) (compile-file) - #:use-module (srfi srfi-1) - #:use-module (srfi srfi-26) - #:use-module (ice-9 match) - #:use-module (ice-9 rdelim) - #:use-module (ice-9 ftw) - #:use-module (guix build utils) - #:export (mount-essential-file-systems - linux-command-line - find-long-option - make-essential-device-nodes - configure-qemu-networking - - disk-partitions - partition-label-predicate - find-partition-by-label - canonicalize-device-spec - - mount-flags->bit-mask - check-file-system - mount-file-system - bind-mount - - load-linux-module* - device-number - boot-system)) - -;;; Commentary: -;;; -;;; Utility procedures useful in a Linux initial RAM disk (initrd). Note that -;;; many of these use procedures not yet available in vanilla Guile (`mount', -;;; `load-linux-module', etc.); these are provided by a Guile patch used in -;;; the GNU distribution. -;;; -;;; Code: - -(define* (mount-essential-file-systems #:key (root "/")) - "Mount /proc and /sys under ROOT." - (define (scope dir) - (string-append root - (if (string-suffix? "/" root) - "" - "/") - dir)) - - (unless (file-exists? (scope "proc")) - (mkdir (scope "proc"))) - (mount "none" (scope "proc") "proc") - - (unless (file-exists? (scope "sys")) - (mkdir (scope "sys"))) - (mount "none" (scope "sys") "sysfs")) - -(define (move-essential-file-systems root) - "Move currently mounted essential file systems to ROOT." - (for-each (lambda (dir) - (let ((target (string-append root dir))) - (unless (file-exists? target) - (mkdir target)) - (mount dir target "" MS_MOVE))) - '("/proc" "/sys"))) - -(define (linux-command-line) - "Return the Linux kernel command line as a list of strings." - (string-tokenize - (call-with-input-file "/proc/cmdline" - get-string-all))) - -(define (find-long-option option arguments) - "Find OPTION among ARGUMENTS, where OPTION is something like \"--load\". -Return the value associated with OPTION, or #f on failure." - (let ((opt (string-append option "="))) - (and=> (find (cut string-prefix? opt <>) - arguments) - (lambda (arg) - (substring arg (+ 1 (string-index arg #\=))))))) - -(define-syntax %ext2-endianness - ;; Endianness of ext2 file systems. - (identifier-syntax (endianness little))) - -;; Offset in bytes of interesting parts of an ext2 superblock. See -;; . -;; TODO: Use "packed structs" from Guile-OpenGL or similar. -(define-syntax %ext2-sblock-magic (identifier-syntax 56)) -(define-syntax %ext2-sblock-creator-os (identifier-syntax 72)) -(define-syntax %ext2-sblock-uuid (identifier-syntax 104)) -(define-syntax %ext2-sblock-volume-name (identifier-syntax 120)) - -(define (read-ext2-superblock device) - "Return the raw contents of DEVICE's ext2 superblock as a bytevector, or #f -if DEVICE does not contain an ext2 file system." - (define %ext2-magic - ;; The magic bytes that identify an ext2 file system. - #xef53) - - (define superblock-size - ;; Size of the interesting part of an ext2 superblock. - 264) - - (define block - ;; The superblock contents. - (make-bytevector superblock-size)) - - (call-with-input-file device - (lambda (port) - (seek port 1024 SEEK_SET) - - ;; Note: work around . - (and (eqv? superblock-size (get-bytevector-n! port block 0 - superblock-size)) - (let ((magic (bytevector-u16-ref block %ext2-sblock-magic - %ext2-endianness))) - (and (= magic %ext2-magic) - block)))))) - -(define (ext2-superblock-uuid sblock) - "Return the UUID of ext2 superblock SBLOCK as a 16-byte bytevector." - (let ((uuid (make-bytevector 16))) - (bytevector-copy! sblock %ext2-sblock-uuid uuid 0 16) - uuid)) - -(define (ext2-superblock-volume-name sblock) - "Return the volume name of SBLOCK as a string of at most 16 characters, or -#f if SBLOCK has no volume name." - (let ((bv (make-bytevector 16))) - (bytevector-copy! sblock %ext2-sblock-volume-name bv 0 16) - - ;; This is a Latin-1, nul-terminated string. - (let ((bytes (take-while (negate zero?) (bytevector->u8-list bv)))) - (if (null? bytes) - #f - (list->string (map integer->char bytes)))))) - -(define (disk-partitions) - "Return the list of device names corresponding to valid disk partitions." - (define (partition? major minor) - (let ((marker (format #f "/sys/dev/block/~a:~a/partition" major minor))) - (catch 'system-error - (lambda () - (not (zero? (call-with-input-file marker read)))) - (lambda args - (if (= ENOENT (system-error-errno args)) - #f - (apply throw args)))))) - - (call-with-input-file "/proc/partitions" - (lambda (port) - ;; Skip the two header lines. - (read-line port) - (read-line port) - - ;; Read each subsequent line, and extract the last space-separated - ;; field. - (let loop ((parts '())) - (let ((line (read-line port))) - (if (eof-object? line) - (reverse parts) - (match (string-tokenize line) - (((= string->number major) (= string->number minor) - blocks name) - (if (partition? major minor) - (loop (cons name parts)) - (loop parts)))))))))) - -(define (partition-label-predicate label) - "Return a procedure that, when applied to a partition name such as \"sda1\", -return #t if that partition's volume name is LABEL." - (lambda (part) - (let* ((device (string-append "/dev/" part)) - (sblock (catch 'system-error - (lambda () - (read-ext2-superblock device)) - (lambda args - ;; When running on the hand-made /dev, - ;; 'disk-partitions' could return partitions for which - ;; we have no /dev node. Handle that gracefully. - (if (= ENOENT (system-error-errno args)) - (begin - (format (current-error-port) - "warning: device '~a' not found~%" - device) - #f) - (apply throw args)))))) - (and sblock - (let ((volume (ext2-superblock-volume-name sblock))) - (and volume - (string=? volume label))))))) - -(define (find-partition-by-label label) - "Return the first partition found whose volume name is LABEL, or #f if none -were found." - (and=> (find (partition-label-predicate label) - (disk-partitions)) - (cut string-append "/dev/" <>))) - -(define* (canonicalize-device-spec spec #:optional (title 'any)) - "Return the device name corresponding to SPEC. TITLE is a symbol, one of -the following: - - • 'device', in which case SPEC is known to designate a device node--e.g., - \"/dev/sda1\"; - • 'label', in which case SPEC is known to designate a partition label--e.g., - \"my-root-part\"; - • 'any', in which case SPEC can be anything. -" - (define max-trials - ;; Number of times we retry partition label resolution, 1 second per - ;; trial. Note: somebody reported a delay of 16 seconds (!) before their - ;; USB key would be detected by the kernel, so we must wait for at least - ;; this long. - 20) - - (define canonical-title - ;; The realm of canonicalization. - (if (eq? title 'any) - (if (string-prefix? "/" spec) - 'device - 'label) - title)) - - (case canonical-title - ((device) - ;; Nothing to do. - spec) - ((label) - ;; Resolve the label. - (let loop ((count 0)) - (let ((device (find-partition-by-label spec))) - (or device - ;; Some devices take a bit of time to appear, most notably USB - ;; storage devices. Thus, wait for the device to appear. - (if (> count max-trials) - (error "failed to resolve partition label" spec) - (begin - (format #t "waiting for partition '~a' to appear...~%" - spec) - (sleep 1) - (loop (+ 1 count)))))))) - ;; TODO: Add support for UUIDs. - (else - (error "unknown device title" title)))) - -(define* (make-disk-device-nodes base major #:optional (minor 0)) - "Make the block device nodes around BASE (something like \"/root/dev/sda\") -with the given MAJOR number, starting with MINOR." - (mknod base 'block-special #o644 (device-number major minor)) - (let loop ((i 1)) - (when (< i 6) - (mknod (string-append base (number->string i)) - 'block-special #o644 (device-number major (+ minor i))) - (loop (+ i 1))))) - -(define* (make-essential-device-nodes #:key (root "/")) - "Make essential device nodes under ROOT/dev." - ;; The hand-made udev! - - (define (scope dir) - (string-append root - (if (string-suffix? "/" root) - "" - "/") - dir)) - - (unless (file-exists? (scope "dev")) - (mkdir (scope "dev"))) - - ;; Make the device nodes for SCSI disks. - (make-disk-device-nodes (scope "dev/sda") 8) - (make-disk-device-nodes (scope "dev/sdb") 8 16) - (make-disk-device-nodes (scope "dev/sdc") 8 32) - (make-disk-device-nodes (scope "dev/sdd") 8 48) - - ;; SCSI CD-ROM devices (aka. "/dev/sr0" etc.). - (mknod (scope "dev/scd0") 'block-special #o644 (device-number 11 0)) - (mknod (scope "dev/scd1") 'block-special #o644 (device-number 11 1)) - - ;; The virtio (para-virtualized) block devices, as supported by QEMU/KVM. - (make-disk-device-nodes (scope "dev/vda") 252) - - ;; Memory (used by Xorg's VESA driver.) - (mknod (scope "dev/mem") 'char-special #o640 (device-number 1 1)) - (mknod (scope "dev/kmem") 'char-special #o640 (device-number 1 2)) - - ;; Inputs (used by Xorg.) - (unless (file-exists? (scope "dev/input")) - (mkdir (scope "dev/input"))) - (mknod (scope "dev/input/mice") 'char-special #o640 (device-number 13 63)) - (mknod (scope "dev/input/mouse0") 'char-special #o640 (device-number 13 32)) - (mknod (scope "dev/input/event0") 'char-special #o640 (device-number 13 64)) - - ;; System console. This node is magically created by the kernel on the - ;; initrd's root, so don't try to create it in that case. - (unless (string=? root "/") - (mknod (scope "dev/console") 'char-special #o600 - (device-number 5 1))) - - ;; TTYs. - (mknod (scope "dev/tty") 'char-special #o600 - (device-number 5 0)) - (chmod (scope "dev/tty") #o666) - (let loop ((n 0)) - (and (< n 50) - (let ((name (format #f "dev/tty~a" n))) - (mknod (scope name) 'char-special #o600 - (device-number 4 n)) - (loop (+ 1 n))))) - - ;; Serial line. - (mknod (scope "dev/ttyS0") 'char-special #o660 - (device-number 4 64)) - - ;; Pseudo ttys. - (mknod (scope "dev/ptmx") 'char-special #o666 - (device-number 5 2)) - (chmod (scope "dev/ptmx") #o666) - - ;; Create /dev/pts; it will be mounted later, at boot time. - (unless (file-exists? (scope "dev/pts")) - (mkdir (scope "dev/pts"))) - - ;; Rendez-vous point for syslogd. - (mknod (scope "dev/log") 'socket #o666 0) - (mknod (scope "dev/kmsg") 'char-special #o600 (device-number 1 11)) - - ;; Other useful nodes, notably relied on by guix-daemon. - (for-each (match-lambda - ((file major minor) - (mknod (scope file) 'char-special #o666 - (device-number major minor)) - (chmod (scope file) #o666))) - '(("dev/null" 1 3) - ("dev/zero" 1 5) - ("dev/full" 1 7) - ("dev/random" 1 8) - ("dev/urandom" 1 9))) - - (symlink "/proc/self/fd" (scope "dev/fd")) - (symlink "/proc/self/fd/0" (scope "dev/stdin")) - (symlink "/proc/self/fd/1" (scope "dev/stdout")) - (symlink "/proc/self/fd/2" (scope "dev/stderr")) - - ;; Loopback devices. - (let loop ((i 0)) - (when (< i 8) - (mknod (scope (string-append "dev/loop" (number->string i))) - 'block-special #o660 - (device-number 7 i)) - (loop (+ 1 i)))) - - ;; File systems in user space (FUSE). - (mknod (scope "dev/fuse") 'char-special #o666 (device-number 10 229))) - -(define %host-qemu-ipv4-address - (inet-pton AF_INET "10.0.2.10")) - -(define* (configure-qemu-networking #:optional (interface "eth0")) - "Setup the INTERFACE network interface and /etc/resolv.conf according to -QEMU's default networking settings (see net/slirp.c in QEMU for default -networking values.) Return #t if INTERFACE is up, #f otherwise." - (display "configuring QEMU networking...\n") - (let* ((sock (socket AF_INET SOCK_STREAM 0)) - (address (make-socket-address AF_INET %host-qemu-ipv4-address 0)) - (flags (network-interface-flags sock interface))) - (set-network-interface-address sock interface address) - (set-network-interface-flags sock interface (logior flags IFF_UP)) - - ;; Hello! We used to create /etc/resolv.conf here, with "nameserver - ;; 10.0.2.3\n". However, with Linux-libre 3.16, we're getting ENOSPC. - ;; And since it's actually unnecessary, it's gone. - - (logand (network-interface-flags sock interface) IFF_UP))) - -;; Linux mount flags, from libc's . -(define MS_RDONLY 1) -(define MS_NOSUID 2) -(define MS_NODEV 4) -(define MS_NOEXEC 8) -(define MS_BIND 4096) -(define MS_MOVE 8192) - -(define (bind-mount source target) - "Bind-mount SOURCE at TARGET." - (mount source target "" MS_BIND)) - -(define (load-linux-module* file) - "Load Linux module from FILE, the name of a `.ko' file." - (define (slurp module) - (call-with-input-file file get-bytevector-all)) - - (load-linux-module (slurp file))) - -(define (device-number major minor) - "Return the device number for the device with MAJOR and MINOR, for use as -the last argument of `mknod'." - (+ (* major 256) minor)) - -(define (pidof program) - "Return the PID of the first presumed instance of PROGRAM." - (let ((program (basename program))) - (find (lambda (pid) - (let ((exe (format #f "/proc/~a/exe" pid))) - (and=> (false-if-exception (readlink exe)) - (compose (cut string=? program <>) basename)))) - (filter-map string->number (scandir "/proc"))))) - -(define* (mount-root-file-system root type - #:key volatile-root? (unionfs "unionfs")) - "Mount the root file system of type TYPE at device ROOT. If VOLATILE-ROOT? -is true, mount ROOT read-only and make it a union with a writable tmpfs using -UNIONFS." - (define (mark-as-not-killable pid) - ;; Tell the 'user-processes' dmd service that PID must be kept alive when - ;; shutting down. - (mkdir-p "/root/etc/dmd") - (let ((port (open-file "/root/etc/dmd/do-not-kill" "a"))) - (chmod port #o600) - (write pid port) - (newline port) - (close-port port))) - - (catch #t - (lambda () - (if volatile-root? - (begin - (mkdir-p "/real-root") - (mount root "/real-root" type MS_RDONLY) - (mkdir-p "/rw-root") - (mount "none" "/rw-root" "tmpfs") - - ;; We want read-write /dev nodes. - (make-essential-device-nodes #:root "/rw-root") - - ;; Make /root a union of the tmpfs and the actual root. Use - ;; 'max_files' to set a high RLIMIT_NOFILE for the unionfs process - ;; itself. Failing to do that, we quickly run out of file - ;; descriptors; see . - (unless (zero? (system* unionfs "-o" - "cow,allow_other,use_ino,suid,dev,max_files=65536" - "/rw-root=RW:/real-root=RO" - "/root")) - (error "unionfs failed")) - - ;; Make sure unionfs remains alive till the end. Because - ;; 'fuse_daemonize' doesn't tell the PID of the forked daemon, we - ;; have to resort to 'pidof' here. - (mark-as-not-killable (pidof unionfs))) - (begin - (check-file-system root type) - (mount root "/root" type)))) - (lambda args - (format (current-error-port) "exception while mounting '~a': ~s~%" - root args) - (start-repl))) - - (copy-file "/proc/mounts" "/root/etc/mtab")) - -(define (check-file-system device type) - "Run a file system check of TYPE on DEVICE." - (define fsck - (string-append "fsck." type)) - - (let ((status (system* fsck "-v" "-p" device))) - (match (status:exit-val status) - (0 - #t) - (1 - (format (current-error-port) "'~a' corrected errors on ~a; continuing~%" - fsck device)) - (2 - (format (current-error-port) "'~a' corrected errors on ~a; rebooting~%" - fsck device) - (sleep 3) - (reboot)) - (code - (format (current-error-port) "'~a' exited with code ~a on ~a; spawning REPL~%" - fsck code device) - (start-repl))))) - -(define (mount-flags->bit-mask flags) - "Return the number suitable for the 'flags' argument of 'mount' that -corresponds to the symbols listed in FLAGS." - (let loop ((flags flags)) - (match flags - (('read-only rest ...) - (logior MS_RDONLY (loop rest))) - (('bind-mount rest ...) - (logior MS_BIND (loop rest))) - (('no-suid rest ...) - (logior MS_NOSUID (loop rest))) - (('no-dev rest ...) - (logior MS_NODEV (loop rest))) - (('no-exec rest ...) - (logior MS_NOEXEC (loop rest))) - (() - 0)))) - -(define* (mount-file-system spec #:key (root "/root")) - "Mount the file system described by SPEC under ROOT. SPEC must have the -form: - - (DEVICE TITLE MOUNT-POINT TYPE (FLAGS ...) OPTIONS CHECK?) - -DEVICE, MOUNT-POINT, and TYPE must be strings; OPTIONS can be a string or #f; -FLAGS must be a list of symbols. CHECK? is a Boolean indicating whether to -run a file system check." - (match spec - ((source title mount-point type (flags ...) options check?) - (let ((source (canonicalize-device-spec source title)) - (mount-point (string-append root "/" mount-point))) - (when check? - (check-file-system source type)) - (mkdir-p mount-point) - (mount source mount-point type (mount-flags->bit-mask flags) - (if options - (string->pointer options) - %null-pointer)) - - ;; Update /etc/mtab. - (mkdir-p (string-append root "/etc")) - (let ((port (open-file (string-append root "/etc/mtab") "a"))) - (format port "~a ~a ~a ~a 0 0~%" - source mount-point type (or options "")) - (close-port port)))))) - -(define (switch-root root) - "Switch to ROOT as the root file system, in a way similar to what -util-linux' switch_root(8) does." - (move-essential-file-systems root) - (chdir root) - - ;; Since we're about to 'rm -rf /', try to make sure we're on an initrd. - ;; TODO: Use 'statfs' to check the fs type, like klibc does. - (when (or (not (file-exists? "/init")) (directory-exists? "/home")) - (format (current-error-port) - "The root file system is probably not an initrd; \ -bailing out.~%root contents: ~s~%" (scandir "/")) - (force-output (current-error-port)) - (exit 1)) - - ;; Delete files from the old root, without crossing mount points (assuming - ;; there are no mount points in sub-directories.) That means we're leaving - ;; the empty ROOT directory behind us, but that's OK. - (let ((root-device (stat:dev (stat "/")))) - (for-each (lambda (file) - (unless (member file '("." "..")) - (let* ((file (string-append "/" file)) - (device (stat:dev (lstat file)))) - (when (= device root-device) - (delete-file-recursively file))))) - (scandir "/"))) - - ;; Make ROOT the new root. - (mount root "/" "" MS_MOVE) - (chroot ".") - (chdir "/") - - (when (file-exists? "/dev/console") - ;; Close the standard file descriptors since they refer to the old - ;; /dev/console, and reopen them. - (let ((console (open-file "/dev/console" "r+b0"))) - (for-each close-fdes '(0 1 2)) - - (dup2 (fileno console) 0) - (dup2 (fileno console) 1) - (dup2 (fileno console) 2) - - (close-port console)))) - - -(define* (boot-system #:key - (linux-modules '()) - qemu-guest-networking? - guile-modules-in-chroot? - volatile-root? - (mounts '())) - "This procedure is meant to be called from an initrd. Boot a system by -first loading LINUX-MODULES, then setting up QEMU guest networking if -QEMU-GUEST-NETWORKING? is true, mounting the file systems specified in MOUNTS, -and finally booting into the new root if any. The initrd supports kernel -command-line options '--load', '--root', and '--repl'. - -Mount the root file system, specified by the '--root' command-line argument, -if any. - -MOUNTS must be a list suitable for 'mount-file-system'. - -When GUILE-MODULES-IN-CHROOT? is true, make core Guile modules available in -the new root. - -When VOLATILE-ROOT? is true, the root file system is writable but any changes -to it are lost." - (define root-mount-point? - (match-lambda - ((device _ "/" _ ...) #t) - (_ #f))) - - (define root-fs-type - (or (any (match-lambda - ((device _ "/" type _ ...) type) - (_ #f)) - mounts) - "ext4")) - - (display "Welcome, this is GNU's early boot Guile.\n") - (display "Use '--repl' for an initrd REPL.\n\n") - - (call-with-error-handling - (lambda () - (mount-essential-file-systems) - (let* ((args (linux-command-line)) - (to-load (find-long-option "--load" args)) - (root (find-long-option "--root" args))) - - (when (member "--repl" args) - (start-repl)) - - (display "loading kernel modules...\n") - (for-each (compose load-linux-module* - (cut string-append "/modules/" <>)) - linux-modules) - - (when qemu-guest-networking? - (unless (configure-qemu-networking) - (display "network interface is DOWN\n"))) - - ;; Make /dev nodes. - (make-essential-device-nodes) - - ;; Prepare the real root file system under /root. - (unless (file-exists? "/root") - (mkdir "/root")) - (if root - (mount-root-file-system (canonicalize-device-spec root) - root-fs-type - #:volatile-root? volatile-root?) - (mount "none" "/root" "tmpfs")) - - (unless (file-exists? "/root/dev") - (mkdir "/root/dev") - (make-essential-device-nodes #:root "/root")) - - ;; Mount the specified file systems. - (for-each mount-file-system - (remove root-mount-point? mounts)) - - (when guile-modules-in-chroot? - ;; Copy the directories that contain .scm and .go files so that the - ;; child process in the chroot can load modules (we would bind-mount - ;; them but for some reason that fails with EINVAL -- XXX). - (mkdir-p "/root/share") - (mkdir-p "/root/lib") - (mount "none" "/root/share" "tmpfs") - (mount "none" "/root/lib" "tmpfs") - (copy-recursively "/share" "/root/share" - #:log (%make-void-port "w")) - (copy-recursively "/lib" "/root/lib" - #:log (%make-void-port "w"))) - - (if to-load - (begin - (switch-root "/root") - (format #t "loading '~a'...\n" to-load) - - ;; TODO: Remove /lib, /share, and /loader.go. - (primitive-load to-load) - - (format (current-error-port) - "boot program '~a' terminated, rebooting~%" - to-load) - (sleep 2) - (reboot)) - (begin - (display "no boot file passed via '--load'\n") - (display "entering a warm and cozy REPL\n") - (start-repl))))))) - -;;; linux-initrd.scm ends here diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index d724ca3a55..ad63a2240d 100644 --- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm @@ -18,7 +18,7 @@ (define-module (gnu build vm) #:use-module (guix build utils) - #:use-module (gnu build linux-initrd) + #:use-module (gnu build linux-boot) #:use-module (gnu build install) #:use-module (ice-9 match) #:use-module (ice-9 regex) diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 274b6f5b77..e9adb47ac0 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -29,7 +29,7 @@ #:use-module ((gnu packages base) #:select (canonical-package glibc)) #:use-module (gnu packages package-management) - #:use-module ((gnu build linux-initrd) + #:use-module ((gnu build linux-boot) #:select (mount-flags->bit-mask)) #:use-module (guix gexp) #:use-module (guix monads) diff --git a/gnu/services/dmd.scm b/gnu/services/dmd.scm index 87bd67a8da..d1fa58f9d7 100644 --- a/gnu/services/dmd.scm +++ b/gnu/services/dmd.scm @@ -35,7 +35,7 @@ (define modules ;; Extra modules visible to dmd.conf. '((guix build syscalls) - (gnu build linux-initrd) + (gnu build linux-boot) (guix build utils))) (mlet %store-monad ((modules (imported-modules modules)) @@ -50,7 +50,7 @@ (use-modules (ice-9 ftw) (guix build syscalls) (guix build utils) - ((gnu build linux-initrd) + ((gnu build linux-boot) #:select (check-file-system canonicalize-device-spec))) (register-services diff --git a/gnu/system.scm b/gnu/system.scm index 963f4864f8..e011a00f16 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -363,7 +363,7 @@ stateful part of OS, including user accounts and groups, special directories, etc." (define %modules '((gnu build activation) - (gnu build linux-initrd) + (gnu build linux-boot) (guix build utils))) (define (service-activations services) diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm index 6d9e23277f..93c739c99e 100644 --- a/gnu/system/linux-initrd.scm +++ b/gnu/system/linux-initrd.scm @@ -75,7 +75,7 @@ initrd." (mlet* %store-monad ((source (imported-modules modules)) (compiled (compiled-modules modules))) (define builder - ;; TODO: Move most of this code to (gnu build linux-initrd). + ;; TODO: Move most of this code to (gnu build linux-boot). #~(begin (use-modules (guix build utils) (ice-9 pretty-print) @@ -277,7 +277,7 @@ exception and backtrace!)." (expression->initrd #~(begin - (use-modules (gnu build linux-initrd) + (use-modules (gnu build linux-boot) (guix build utils) (srfi srfi-26)) @@ -293,7 +293,7 @@ exception and backtrace!)." #:volatile-root? '#$volatile-root?)) #:name "base-initrd" #:modules '((guix build utils) - (gnu build linux-initrd)) + (gnu build linux-boot)) #:to-copy helper-packages #:linux linux-libre #:linux-modules linux-modules)) diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm index be9cf6b457..3e26dfb700 100644 --- a/gnu/system/vm.scm +++ b/gnu/system/vm.scm @@ -114,7 +114,7 @@ input tuple. The output file name is when building for SYSTEM." (modules '((gnu build vm) (gnu build install) - (gnu build linux-initrd) + (gnu build linux-boot) (guix build utils))) (guile-for-build (%guile-for-build)) -- cgit v1.2.3 From e2f4b305d0b7cff1e19c7f67ea633ef8a971e712 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 3 Sep 2014 14:19:51 +0200 Subject: Move part of (gnu build linux-boot) to (gnu build file-systems). * gnu/build/linux-boot.scm (%ext2-endianness, %ext2-sblock-magic, %ext2-sblock-creator-os, %ext2-sblock-uuid, %ext2-sblock-volume-name, read-ext2-superblock, ext2-superblock-uuid, ext2-superblock-volume-name, disk-partitions, partition-label-predicate, find-partition-by-label, canonicalize-device-spec, MS_RDONLY, MS_NOSUID, MS_NODEV, MS_NOEXEC, MS_BIND, MS_MOVE, bind-mount, check-file-system, mount-flags->bit-mask, mount-file-system): Move to... * gnu/build/file-systems.scm: ... here. New file. * gnu-system.am (GNU_SYSTEM_MODULES): Add it. * gnu/services/base.scm: Use (gnu build file-systems). * gnu/services/dmd.scm (dmd-configuration-file): Likewise. * gnu/system.scm (operating-system-activation-script): Likewise. * gnu/system/linux-initrd.scm (base-initrd): Likewise. * gnu/system/vm.scm (expression->derivation-in-linux-vm): Likewise. --- gnu-system.am | 1 + gnu/build/file-systems.scm | 299 ++++++++++++++++++++++++++++++++++++++++++++ gnu/build/linux-boot.scm | 259 +------------------------------------- gnu/services/base.scm | 2 +- gnu/services/dmd.scm | 4 +- gnu/system.scm | 1 + gnu/system/linux-initrd.scm | 3 +- gnu/system/vm.scm | 1 + 8 files changed, 308 insertions(+), 262 deletions(-) create mode 100644 gnu/build/file-systems.scm (limited to 'gnu') diff --git a/gnu-system.am b/gnu-system.am index 8e7de7c622..d4f27314c2 100644 --- a/gnu-system.am +++ b/gnu-system.am @@ -280,6 +280,7 @@ GNU_SYSTEM_MODULES = \ gnu/system/vm.scm \ \ gnu/build/activation.scm \ + gnu/build/file-systems.scm \ gnu/build/install.scm \ gnu/build/linux-boot.scm \ gnu/build/vm.scm diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm new file mode 100644 index 0000000000..5c04771e19 --- /dev/null +++ b/gnu/build/file-systems.scm @@ -0,0 +1,299 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2014 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu build file-systems) + #:use-module (guix build utils) + #:use-module (rnrs io ports) + #:use-module (rnrs bytevectors) + #:use-module (ice-9 match) + #:use-module (ice-9 rdelim) + #:use-module (system foreign) + #:autoload (system repl repl) (start-repl) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:export (disk-partitions + partition-label-predicate + find-partition-by-label + canonicalize-device-spec + + MS_RDONLY + MS_NOSUID + MS_NODEV + MS_NOEXEC + MS_BIND + MS_MOVE + bind-mount + + mount-flags->bit-mask + check-file-system + mount-file-system)) + +;;; Commentary: +;;; +;;; This modules provides tools to deal with disk partitions, and to mount and +;;; check file systems. +;;; +;;; Code: + +;; Linux mount flags, from libc's . +(define MS_RDONLY 1) +(define MS_NOSUID 2) +(define MS_NODEV 4) +(define MS_NOEXEC 8) +(define MS_BIND 4096) +(define MS_MOVE 8192) + +(define (bind-mount source target) + "Bind-mount SOURCE at TARGET." + (mount source target "" MS_BIND)) + +(define-syntax %ext2-endianness + ;; Endianness of ext2 file systems. + (identifier-syntax (endianness little))) + +;; Offset in bytes of interesting parts of an ext2 superblock. See +;; . +;; TODO: Use "packed structs" from Guile-OpenGL or similar. +(define-syntax %ext2-sblock-magic (identifier-syntax 56)) +(define-syntax %ext2-sblock-creator-os (identifier-syntax 72)) +(define-syntax %ext2-sblock-uuid (identifier-syntax 104)) +(define-syntax %ext2-sblock-volume-name (identifier-syntax 120)) + +(define (read-ext2-superblock device) + "Return the raw contents of DEVICE's ext2 superblock as a bytevector, or #f +if DEVICE does not contain an ext2 file system." + (define %ext2-magic + ;; The magic bytes that identify an ext2 file system. + #xef53) + + (define superblock-size + ;; Size of the interesting part of an ext2 superblock. + 264) + + (define block + ;; The superblock contents. + (make-bytevector superblock-size)) + + (call-with-input-file device + (lambda (port) + (seek port 1024 SEEK_SET) + + ;; Note: work around . + (and (eqv? superblock-size (get-bytevector-n! port block 0 + superblock-size)) + (let ((magic (bytevector-u16-ref block %ext2-sblock-magic + %ext2-endianness))) + (and (= magic %ext2-magic) + block)))))) + +(define (ext2-superblock-uuid sblock) + "Return the UUID of ext2 superblock SBLOCK as a 16-byte bytevector." + (let ((uuid (make-bytevector 16))) + (bytevector-copy! sblock %ext2-sblock-uuid uuid 0 16) + uuid)) + +(define (ext2-superblock-volume-name sblock) + "Return the volume name of SBLOCK as a string of at most 16 characters, or +#f if SBLOCK has no volume name." + (let ((bv (make-bytevector 16))) + (bytevector-copy! sblock %ext2-sblock-volume-name bv 0 16) + + ;; This is a Latin-1, nul-terminated string. + (let ((bytes (take-while (negate zero?) (bytevector->u8-list bv)))) + (if (null? bytes) + #f + (list->string (map integer->char bytes)))))) + +(define (disk-partitions) + "Return the list of device names corresponding to valid disk partitions." + (define (partition? major minor) + (let ((marker (format #f "/sys/dev/block/~a:~a/partition" major minor))) + (catch 'system-error + (lambda () + (not (zero? (call-with-input-file marker read)))) + (lambda args + (if (= ENOENT (system-error-errno args)) + #f + (apply throw args)))))) + + (call-with-input-file "/proc/partitions" + (lambda (port) + ;; Skip the two header lines. + (read-line port) + (read-line port) + + ;; Read each subsequent line, and extract the last space-separated + ;; field. + (let loop ((parts '())) + (let ((line (read-line port))) + (if (eof-object? line) + (reverse parts) + (match (string-tokenize line) + (((= string->number major) (= string->number minor) + blocks name) + (if (partition? major minor) + (loop (cons name parts)) + (loop parts)))))))))) + +(define (partition-label-predicate label) + "Return a procedure that, when applied to a partition name such as \"sda1\", +return #t if that partition's volume name is LABEL." + (lambda (part) + (let* ((device (string-append "/dev/" part)) + (sblock (catch 'system-error + (lambda () + (read-ext2-superblock device)) + (lambda args + ;; When running on the hand-made /dev, + ;; 'disk-partitions' could return partitions for which + ;; we have no /dev node. Handle that gracefully. + (if (= ENOENT (system-error-errno args)) + (begin + (format (current-error-port) + "warning: device '~a' not found~%" + device) + #f) + (apply throw args)))))) + (and sblock + (let ((volume (ext2-superblock-volume-name sblock))) + (and volume + (string=? volume label))))))) + +(define (find-partition-by-label label) + "Return the first partition found whose volume name is LABEL, or #f if none +were found." + (and=> (find (partition-label-predicate label) + (disk-partitions)) + (cut string-append "/dev/" <>))) + +(define* (canonicalize-device-spec spec #:optional (title 'any)) + "Return the device name corresponding to SPEC. TITLE is a symbol, one of +the following: + + • 'device', in which case SPEC is known to designate a device node--e.g., + \"/dev/sda1\"; + • 'label', in which case SPEC is known to designate a partition label--e.g., + \"my-root-part\"; + • 'any', in which case SPEC can be anything. +" + (define max-trials + ;; Number of times we retry partition label resolution, 1 second per + ;; trial. Note: somebody reported a delay of 16 seconds (!) before their + ;; USB key would be detected by the kernel, so we must wait for at least + ;; this long. + 20) + + (define canonical-title + ;; The realm of canonicalization. + (if (eq? title 'any) + (if (string-prefix? "/" spec) + 'device + 'label) + title)) + + (case canonical-title + ((device) + ;; Nothing to do. + spec) + ((label) + ;; Resolve the label. + (let loop ((count 0)) + (let ((device (find-partition-by-label spec))) + (or device + ;; Some devices take a bit of time to appear, most notably USB + ;; storage devices. Thus, wait for the device to appear. + (if (> count max-trials) + (error "failed to resolve partition label" spec) + (begin + (format #t "waiting for partition '~a' to appear...~%" + spec) + (sleep 1) + (loop (+ 1 count)))))))) + ;; TODO: Add support for UUIDs. + (else + (error "unknown device title" title)))) + +(define (check-file-system device type) + "Run a file system check of TYPE on DEVICE." + (define fsck + (string-append "fsck." type)) + + (let ((status (system* fsck "-v" "-p" device))) + (match (status:exit-val status) + (0 + #t) + (1 + (format (current-error-port) "'~a' corrected errors on ~a; continuing~%" + fsck device)) + (2 + (format (current-error-port) "'~a' corrected errors on ~a; rebooting~%" + fsck device) + (sleep 3) + (reboot)) + (code + (format (current-error-port) "'~a' exited with code ~a on ~a; spawning REPL~%" + fsck code device) + (start-repl))))) + +(define (mount-flags->bit-mask flags) + "Return the number suitable for the 'flags' argument of 'mount' that +corresponds to the symbols listed in FLAGS." + (let loop ((flags flags)) + (match flags + (('read-only rest ...) + (logior MS_RDONLY (loop rest))) + (('bind-mount rest ...) + (logior MS_BIND (loop rest))) + (('no-suid rest ...) + (logior MS_NOSUID (loop rest))) + (('no-dev rest ...) + (logior MS_NODEV (loop rest))) + (('no-exec rest ...) + (logior MS_NOEXEC (loop rest))) + (() + 0)))) + +(define* (mount-file-system spec #:key (root "/root")) + "Mount the file system described by SPEC under ROOT. SPEC must have the +form: + + (DEVICE TITLE MOUNT-POINT TYPE (FLAGS ...) OPTIONS CHECK?) + +DEVICE, MOUNT-POINT, and TYPE must be strings; OPTIONS can be a string or #f; +FLAGS must be a list of symbols. CHECK? is a Boolean indicating whether to +run a file system check." + (match spec + ((source title mount-point type (flags ...) options check?) + (let ((source (canonicalize-device-spec source title)) + (mount-point (string-append root "/" mount-point))) + (when check? + (check-file-system source type)) + (mkdir-p mount-point) + (mount source mount-point type (mount-flags->bit-mask flags) + (if options + (string->pointer options) + %null-pointer)) + + ;; Update /etc/mtab. + (mkdir-p (string-append root "/etc")) + (let ((port (open-file (string-append root "/etc/mtab") "a"))) + (format port "~a ~a ~a ~a 0 0~%" + source mount-point type (or options "")) + (close-port port)))))) + +;;; file-systems.scm ends here diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm index 24000e191a..21ee58ad50 100644 --- a/gnu/build/linux-boot.scm +++ b/gnu/build/linux-boot.scm @@ -18,33 +18,22 @@ (define-module (gnu build linux-boot) #:use-module (rnrs io ports) - #:use-module (rnrs bytevectors) - #:use-module (system foreign) #:use-module (system repl error-handling) #:autoload (system repl repl) (start-repl) #:autoload (system base compile) (compile-file) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (ice-9 match) - #:use-module (ice-9 rdelim) #:use-module (ice-9 ftw) #:use-module (guix build utils) + #:use-module (gnu build file-systems) #:export (mount-essential-file-systems linux-command-line find-long-option make-essential-device-nodes configure-qemu-networking - disk-partitions - partition-label-predicate - find-partition-by-label - canonicalize-device-spec - - mount-flags->bit-mask - check-file-system - mount-file-system bind-mount - load-linux-module* device-number boot-system)) @@ -99,172 +88,6 @@ Return the value associated with OPTION, or #f on failure." (lambda (arg) (substring arg (+ 1 (string-index arg #\=))))))) -(define-syntax %ext2-endianness - ;; Endianness of ext2 file systems. - (identifier-syntax (endianness little))) - -;; Offset in bytes of interesting parts of an ext2 superblock. See -;; . -;; TODO: Use "packed structs" from Guile-OpenGL or similar. -(define-syntax %ext2-sblock-magic (identifier-syntax 56)) -(define-syntax %ext2-sblock-creator-os (identifier-syntax 72)) -(define-syntax %ext2-sblock-uuid (identifier-syntax 104)) -(define-syntax %ext2-sblock-volume-name (identifier-syntax 120)) - -(define (read-ext2-superblock device) - "Return the raw contents of DEVICE's ext2 superblock as a bytevector, or #f -if DEVICE does not contain an ext2 file system." - (define %ext2-magic - ;; The magic bytes that identify an ext2 file system. - #xef53) - - (define superblock-size - ;; Size of the interesting part of an ext2 superblock. - 264) - - (define block - ;; The superblock contents. - (make-bytevector superblock-size)) - - (call-with-input-file device - (lambda (port) - (seek port 1024 SEEK_SET) - - ;; Note: work around . - (and (eqv? superblock-size (get-bytevector-n! port block 0 - superblock-size)) - (let ((magic (bytevector-u16-ref block %ext2-sblock-magic - %ext2-endianness))) - (and (= magic %ext2-magic) - block)))))) - -(define (ext2-superblock-uuid sblock) - "Return the UUID of ext2 superblock SBLOCK as a 16-byte bytevector." - (let ((uuid (make-bytevector 16))) - (bytevector-copy! sblock %ext2-sblock-uuid uuid 0 16) - uuid)) - -(define (ext2-superblock-volume-name sblock) - "Return the volume name of SBLOCK as a string of at most 16 characters, or -#f if SBLOCK has no volume name." - (let ((bv (make-bytevector 16))) - (bytevector-copy! sblock %ext2-sblock-volume-name bv 0 16) - - ;; This is a Latin-1, nul-terminated string. - (let ((bytes (take-while (negate zero?) (bytevector->u8-list bv)))) - (if (null? bytes) - #f - (list->string (map integer->char bytes)))))) - -(define (disk-partitions) - "Return the list of device names corresponding to valid disk partitions." - (define (partition? major minor) - (let ((marker (format #f "/sys/dev/block/~a:~a/partition" major minor))) - (catch 'system-error - (lambda () - (not (zero? (call-with-input-file marker read)))) - (lambda args - (if (= ENOENT (system-error-errno args)) - #f - (apply throw args)))))) - - (call-with-input-file "/proc/partitions" - (lambda (port) - ;; Skip the two header lines. - (read-line port) - (read-line port) - - ;; Read each subsequent line, and extract the last space-separated - ;; field. - (let loop ((parts '())) - (let ((line (read-line port))) - (if (eof-object? line) - (reverse parts) - (match (string-tokenize line) - (((= string->number major) (= string->number minor) - blocks name) - (if (partition? major minor) - (loop (cons name parts)) - (loop parts)))))))))) - -(define (partition-label-predicate label) - "Return a procedure that, when applied to a partition name such as \"sda1\", -return #t if that partition's volume name is LABEL." - (lambda (part) - (let* ((device (string-append "/dev/" part)) - (sblock (catch 'system-error - (lambda () - (read-ext2-superblock device)) - (lambda args - ;; When running on the hand-made /dev, - ;; 'disk-partitions' could return partitions for which - ;; we have no /dev node. Handle that gracefully. - (if (= ENOENT (system-error-errno args)) - (begin - (format (current-error-port) - "warning: device '~a' not found~%" - device) - #f) - (apply throw args)))))) - (and sblock - (let ((volume (ext2-superblock-volume-name sblock))) - (and volume - (string=? volume label))))))) - -(define (find-partition-by-label label) - "Return the first partition found whose volume name is LABEL, or #f if none -were found." - (and=> (find (partition-label-predicate label) - (disk-partitions)) - (cut string-append "/dev/" <>))) - -(define* (canonicalize-device-spec spec #:optional (title 'any)) - "Return the device name corresponding to SPEC. TITLE is a symbol, one of -the following: - - • 'device', in which case SPEC is known to designate a device node--e.g., - \"/dev/sda1\"; - • 'label', in which case SPEC is known to designate a partition label--e.g., - \"my-root-part\"; - • 'any', in which case SPEC can be anything. -" - (define max-trials - ;; Number of times we retry partition label resolution, 1 second per - ;; trial. Note: somebody reported a delay of 16 seconds (!) before their - ;; USB key would be detected by the kernel, so we must wait for at least - ;; this long. - 20) - - (define canonical-title - ;; The realm of canonicalization. - (if (eq? title 'any) - (if (string-prefix? "/" spec) - 'device - 'label) - title)) - - (case canonical-title - ((device) - ;; Nothing to do. - spec) - ((label) - ;; Resolve the label. - (let loop ((count 0)) - (let ((device (find-partition-by-label spec))) - (or device - ;; Some devices take a bit of time to appear, most notably USB - ;; storage devices. Thus, wait for the device to appear. - (if (> count max-trials) - (error "failed to resolve partition label" spec) - (begin - (format #t "waiting for partition '~a' to appear...~%" - spec) - (sleep 1) - (loop (+ 1 count)))))))) - ;; TODO: Add support for UUIDs. - (else - (error "unknown device title" title)))) - (define* (make-disk-device-nodes base major #:optional (minor 0)) "Make the block device nodes around BASE (something like \"/root/dev/sda\") with the given MAJOR number, starting with MINOR." @@ -395,18 +218,6 @@ networking values.) Return #t if INTERFACE is up, #f otherwise." (logand (network-interface-flags sock interface) IFF_UP))) -;; Linux mount flags, from libc's . -(define MS_RDONLY 1) -(define MS_NOSUID 2) -(define MS_NODEV 4) -(define MS_NOEXEC 8) -(define MS_BIND 4096) -(define MS_MOVE 8192) - -(define (bind-mount source target) - "Bind-mount SOURCE at TARGET." - (mount source target "" MS_BIND)) - (define (load-linux-module* file) "Load Linux module from FILE, the name of a `.ko' file." (define (slurp module) @@ -479,74 +290,6 @@ UNIONFS." (copy-file "/proc/mounts" "/root/etc/mtab")) -(define (check-file-system device type) - "Run a file system check of TYPE on DEVICE." - (define fsck - (string-append "fsck." type)) - - (let ((status (system* fsck "-v" "-p" device))) - (match (status:exit-val status) - (0 - #t) - (1 - (format (current-error-port) "'~a' corrected errors on ~a; continuing~%" - fsck device)) - (2 - (format (current-error-port) "'~a' corrected errors on ~a; rebooting~%" - fsck device) - (sleep 3) - (reboot)) - (code - (format (current-error-port) "'~a' exited with code ~a on ~a; spawning REPL~%" - fsck code device) - (start-repl))))) - -(define (mount-flags->bit-mask flags) - "Return the number suitable for the 'flags' argument of 'mount' that -corresponds to the symbols listed in FLAGS." - (let loop ((flags flags)) - (match flags - (('read-only rest ...) - (logior MS_RDONLY (loop rest))) - (('bind-mount rest ...) - (logior MS_BIND (loop rest))) - (('no-suid rest ...) - (logior MS_NOSUID (loop rest))) - (('no-dev rest ...) - (logior MS_NODEV (loop rest))) - (('no-exec rest ...) - (logior MS_NOEXEC (loop rest))) - (() - 0)))) - -(define* (mount-file-system spec #:key (root "/root")) - "Mount the file system described by SPEC under ROOT. SPEC must have the -form: - - (DEVICE TITLE MOUNT-POINT TYPE (FLAGS ...) OPTIONS CHECK?) - -DEVICE, MOUNT-POINT, and TYPE must be strings; OPTIONS can be a string or #f; -FLAGS must be a list of symbols. CHECK? is a Boolean indicating whether to -run a file system check." - (match spec - ((source title mount-point type (flags ...) options check?) - (let ((source (canonicalize-device-spec source title)) - (mount-point (string-append root "/" mount-point))) - (when check? - (check-file-system source type)) - (mkdir-p mount-point) - (mount source mount-point type (mount-flags->bit-mask flags) - (if options - (string->pointer options) - %null-pointer)) - - ;; Update /etc/mtab. - (mkdir-p (string-append root "/etc")) - (let ((port (open-file (string-append root "/etc/mtab") "a"))) - (format port "~a ~a ~a ~a 0 0~%" - source mount-point type (or options "")) - (close-port port)))))) - (define (switch-root root) "Switch to ROOT as the root file system, in a way similar to what util-linux' switch_root(8) does." diff --git a/gnu/services/base.scm b/gnu/services/base.scm index e9adb47ac0..b5b49d1a01 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -29,7 +29,7 @@ #:use-module ((gnu packages base) #:select (canonical-package glibc)) #:use-module (gnu packages package-management) - #:use-module ((gnu build linux-boot) + #:use-module ((gnu build file-systems) #:select (mount-flags->bit-mask)) #:use-module (guix gexp) #:use-module (guix monads) diff --git a/gnu/services/dmd.scm b/gnu/services/dmd.scm index d1fa58f9d7..59c2373779 100644 --- a/gnu/services/dmd.scm +++ b/gnu/services/dmd.scm @@ -35,7 +35,7 @@ (define modules ;; Extra modules visible to dmd.conf. '((guix build syscalls) - (gnu build linux-boot) + (gnu build file-systems) (guix build utils))) (mlet %store-monad ((modules (imported-modules modules)) @@ -50,7 +50,7 @@ (use-modules (ice-9 ftw) (guix build syscalls) (guix build utils) - ((gnu build linux-boot) + ((gnu build file-systems) #:select (check-file-system canonicalize-device-spec))) (register-services diff --git a/gnu/system.scm b/gnu/system.scm index e011a00f16..ea7fdf1cb7 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -364,6 +364,7 @@ etc." (define %modules '((gnu build activation) (gnu build linux-boot) + (gnu build file-systems) (guix build utils))) (define (service-activations services) diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm index 93c739c99e..c4ab73ec9a 100644 --- a/gnu/system/linux-initrd.scm +++ b/gnu/system/linux-initrd.scm @@ -293,7 +293,8 @@ exception and backtrace!)." #:volatile-root? '#$volatile-root?)) #:name "base-initrd" #:modules '((guix build utils) - (gnu build linux-boot)) + (gnu build linux-boot) + (gnu build file-systems)) #:to-copy helper-packages #:linux linux-libre #:linux-modules linux-modules)) diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm index 3e26dfb700..d263edb4f1 100644 --- a/gnu/system/vm.scm +++ b/gnu/system/vm.scm @@ -115,6 +115,7 @@ input tuple. The output file name is when building for SYSTEM." '((gnu build vm) (gnu build install) (gnu build linux-boot) + (gnu build file-systems) (guix build utils))) (guile-for-build (%guile-for-build)) -- cgit v1.2.3 From fbb3555809966ee2dacfe16451fba0b963d1cdc0 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 3 Sep 2014 15:13:44 +0200 Subject: linux-initrd: Factorize cpio archive creation. * gnu/build/linux-initrd.scm: New file. * gnu-system.am (GNU_SYSTEM_MODULES): Add it. * gnu/system/linux-initrd.scm (expression->initrd): Use (gnu build linux-initrd) and 'write-cpio-archive' instead of the inlined code. --- gnu-system.am | 1 + gnu/build/linux-initrd.scm | 70 +++++++++++++++++++++++++++++++++++++++++++++ gnu/system/linux-initrd.scm | 45 ++++++----------------------- 3 files changed, 80 insertions(+), 36 deletions(-) create mode 100644 gnu/build/linux-initrd.scm (limited to 'gnu') diff --git a/gnu-system.am b/gnu-system.am index d4f27314c2..9328d13083 100644 --- a/gnu-system.am +++ b/gnu-system.am @@ -283,6 +283,7 @@ GNU_SYSTEM_MODULES = \ gnu/build/file-systems.scm \ gnu/build/install.scm \ gnu/build/linux-boot.scm \ + gnu/build/linux-initrd.scm \ gnu/build/vm.scm diff --git a/gnu/build/linux-initrd.scm b/gnu/build/linux-initrd.scm new file mode 100644 index 0000000000..8caeba8722 --- /dev/null +++ b/gnu/build/linux-initrd.scm @@ -0,0 +1,70 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2013, 2014 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu build linux-initrd) + #:use-module (ice-9 popen) + #:use-module (ice-9 ftw) + #:export (write-cpio-archive)) + +;;; Commentary: +;;; +;;; Tools to create Linux initial RAM disks ("initrds"). Initrds are +;;; essentially gzipped cpio archives, with a '/init' executable that the +;;; kernel runs at boot time. +;;; +;;; Code: + +(define* (write-cpio-archive output directory + #:key + (compress? #t) + (cpio "cpio") (gzip "gzip")) + "Write a cpio archive containing DIRECTORY to file OUTPUT, using CPIO. When +COMPRESS? is true, compress it using GZIP. On success, return OUTPUT." + (let ((pipe (open-pipe* OPEN_WRITE cpio "-o" "-O" output + "-H" "newc" "--null" + "--no-absolute-filenames"))) + (define (print0 file) + (format pipe "~a\0" file)) + + ;; Note: as per `ramfs-rootfs-initramfs.txt', always add directory entries + ;; before the files that are inside of it: "The Linux kernel cpio + ;; extractor won't create files in a directory that doesn't exist, so the + ;; directory entries must go before the files that go in those + ;; directories." + + ;; XXX: Use a deterministic order. + (file-system-fold (const #t) + (lambda (file stat result) ; leaf + (print0 file)) + (lambda (dir stat result) ; down + (unless (string=? dir directory) + (print0 dir))) + (const #f) ; up + (const #f) ; skip + (const #f) + #f + directory) + + (and (zero? (close-pipe pipe)) + (or (not compress?) + (and (zero? (system* gzip "--best" output)) + (rename-file (string-append output ".gz") + output)) + output)))) + +;;; linux-initrd.scm ends here diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm index c4ab73ec9a..bdee28c961 100644 --- a/gnu/system/linux-initrd.scm +++ b/gnu/system/linux-initrd.scm @@ -75,9 +75,10 @@ initrd." (mlet* %store-monad ((source (imported-modules modules)) (compiled (compiled-modules modules))) (define builder - ;; TODO: Move most of this code to (gnu build linux-boot). + ;; TODO: Move most of this code to (gnu build linux-initrd). #~(begin - (use-modules (guix build utils) + (use-modules (gnu build linux-initrd) + (guix build utils) (ice-9 pretty-print) (ice-9 popen) (ice-9 match) @@ -87,9 +88,7 @@ initrd." (rnrs bytevectors) ((system foreign) #:select (sizeof))) - (let ((cpio (string-append #$cpio "/bin/cpio")) - (gzip (string-append #$gzip "/bin/gzip")) - (modules #$source) + (let ((modules #$source) (gos #$compiled) (scm-dir (string-append "share/guile/" (effective-version))) (go-dir (format #f ".cache/guile/ccache/~a-~a-~a-~a" @@ -162,39 +161,13 @@ initrd." (for-each (cut utime <> 0 0 0 0) (find-files "." ".*")) - (system* cpio "--version") - (let ((pipe (open-pipe* OPEN_WRITE cpio "-o" - "-O" (string-append #$output "/initrd") - "-H" "newc" "--null"))) - (define print0 - (let ((len (string-length "./"))) - (lambda (file) - (format pipe "~a\0" (string-drop file len))))) - - ;; Note: as per `ramfs-rootfs-initramfs.txt', always add - ;; directory entries before the files that are inside of it: "The - ;; Linux kernel cpio extractor won't create files in a directory - ;; that doesn't exist, so the directory entries must go before - ;; the files that go in those directories." - (file-system-fold (const #t) - (lambda (file stat result) ; leaf - (print0 file)) - (lambda (dir stat result) ; down - (unless (string=? dir ".") - (print0 dir))) - (const #f) ; up - (const #f) ; skip - (const #f) - #f - ".") - - (and (zero? (close-pipe pipe)) - (with-directory-excursion #$output - (and (zero? (system* gzip "--best" "initrd")) - (rename-file "initrd.gz" "initrd"))))))))) + (write-cpio-archive (string-append #$output "/initrd") "." + #:cpio (string-append #$cpio "/bin/cpio") + #:gzip (string-append #$gzip "/bin/gzip")))))) (gexp->derivation name builder - #:modules '((guix build utils))))) + #:modules '((guix build utils) + (gnu build linux-initrd))))) (define (file-system->spec fs) "Return a list corresponding to file-system FS that can be passed to the -- cgit v1.2.3 From a423555d3c4314f8347d75b050d7daf6e594281f Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 3 Sep 2014 15:22:49 +0200 Subject: gnu: datamash: Fix license. * gnu/packages/datamash.scm (datamash)[license]: Change to GPL3+. --- gnu/packages/datamash.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnu') diff --git a/gnu/packages/datamash.scm b/gnu/packages/datamash.scm index f44025e2ea..ccf3729b0b 100644 --- a/gnu/packages/datamash.scm +++ b/gnu/packages/datamash.scm @@ -45,4 +45,4 @@ (description "Perform basic numeric, textual and statistical operations on plain text files. Designed to work within standard pipelines without additional code.") - (license gpl3))) + (license gpl3+))) -- cgit v1.2.3 From b21a1c5a18e2e0f564812bd8a94a587d0234c68d Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 4 Sep 2014 22:50:10 +0200 Subject: linux-initrd: Move Linux module tree flattening to another derivation. * gnu/system/linux-initrd.scm (expression->initrd)[string->regexp]: Remove. Use 'flat-linux-module-directory'. Remove the equivalent logic from 'builder'. (flat-linux-module-directory): New procedure. --- gnu/system/linux-initrd.scm | 60 ++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 23 deletions(-) (limited to 'gnu') diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm index bdee28c961..1108bec51d 100644 --- a/gnu/system/linux-initrd.scm +++ b/gnu/system/linux-initrd.scm @@ -68,12 +68,10 @@ initrd." ;; General Linux overview in `Documentation/early-userspace/README' and ;; `Documentation/filesystems/ramfs-rootfs-initramfs.txt'. - (define (string->regexp str) - ;; Return a regexp that matches STR exactly. - (string-append "^" (regexp-quote str) "$")) - - (mlet* %store-monad ((source (imported-modules modules)) - (compiled (compiled-modules modules))) + (mlet %store-monad ((source (imported-modules modules)) + (compiled (compiled-modules modules)) + (module-dir (flat-linux-module-directory linux + linux-modules))) (define builder ;; TODO: Move most of this code to (gnu build linux-initrd). #~(begin @@ -126,23 +124,8 @@ initrd." #:output-file (string-append go-dir "/init.go")) ;; Copy Linux modules. - (let* ((linux #$linux) - (module-dir (and linux - (string-append linux "/lib/modules")))) - (mkdir "modules") - #$@(map (lambda (module) - #~(match (find-files module-dir - #$(string->regexp module)) - ((file) - (format #t "copying '~a'...~%" file) - (copy-file file (string-append "modules/" - #$module))) - (() - (error "module not found" #$module module-dir)) - ((_ ...) - (error "several modules by that name" - #$module module-dir)))) - linux-modules)) + (mkdir "modules") + (copy-recursively #$module-dir "modules") (let ((store #$(string-append "." (%store-prefix))) (to-copy '#$to-copy)) @@ -169,6 +152,37 @@ initrd." #:modules '((guix build utils) (gnu build linux-initrd))))) +(define (flat-linux-module-directory linux modules) + "Return a flat directory containing the Linux kernel modules listed in +MODULES and taken from LINUX." + (define build-exp + #~(begin + (use-modules (ice-9 match) (ice-9 regex) + (guix build utils)) + + (define (string->regexp str) + ;; Return a regexp that matches STR exactly. + (string-append "^" (regexp-quote str) "$")) + + (define module-dir + (string-append #$linux "/lib/modules")) + + (mkdir #$output) + (for-each (lambda (module) + (match (find-files module-dir (string->regexp module)) + ((file) + (format #t "copying '~a'...~%" file) + (copy-file file (string-append #$output "/" module))) + (() + (error "module not found" module module-dir)) + ((_ ...) + (error "several modules by that name" + module module-dir)))) + '#$modules))) + + (gexp->derivation "linux-modules" build-exp + #:modules '((guix build utils)))) + (define (file-system->spec fs) "Return a list corresponding to file-system FS that can be passed to the initrd code." -- cgit v1.2.3 From 6fd1a7967481037560d2ab25f31da182822ef889 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 4 Sep 2014 23:05:12 +0200 Subject: vm: Move store copy handling to (guix build store-copy). * gnu/build/vm.scm (read-reference-graph, populate-store): Move to... * guix/build/store-copy.scm: ... here. New file. * Makefile.am (MODULES): Add it. * gnu/system/vm.scm (expression->derivation-in-linux-vm): Adjust default #:modules values accordingly. * tests/gexp.scm ("gexp->derivation, store copy"): New test. --- Makefile.am | 1 + gnu/build/vm.scm | 37 +------------------------ gnu/system/vm.scm | 3 ++- guix/build/store-copy.scm | 69 +++++++++++++++++++++++++++++++++++++++++++++++ tests/gexp.scm | 38 ++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 37 deletions(-) create mode 100644 guix/build/store-copy.scm (limited to 'gnu') diff --git a/Makefile.am b/Makefile.am index 156c560665..1f2c4db80d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,6 +64,7 @@ MODULES = \ guix/build/gnu-dist.scm \ guix/build/perl-build-system.scm \ guix/build/python-build-system.scm \ + guix/build/store-copy.scm \ guix/build/utils.scm \ guix/build/union.scm \ guix/build/pull.scm \ diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index ad63a2240d..27ccd047b7 100644 --- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm @@ -18,12 +18,11 @@ (define-module (gnu build vm) #:use-module (guix build utils) + #:use-module (guix build store-copy) #:use-module (gnu build linux-boot) #:use-module (gnu build install) #:use-module (ice-9 match) #:use-module (ice-9 regex) - #:use-module (ice-9 rdelim) - #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:export (qemu-command load-in-linux-vm @@ -111,20 +110,6 @@ the #:references-graphs parameter of 'derivation'." (mkdir output) (copy-recursively "xchg" output)))) -(define (read-reference-graph port) - "Return a list of store paths from the reference graph at PORT. -The data at PORT is the format produced by #:references-graphs." - (let loop ((line (read-line port)) - (result '())) - (cond ((eof-object? line) - (delete-duplicates result)) - ((string-prefix? "/" line) - (loop (read-line port) - (cons line result))) - (else - (loop (read-line port) - result))))) - (define* (initialize-partition-table device partition-size #:key (label-type "msdos") @@ -140,26 +125,6 @@ success." (format #f "~aB" partition-size))) (error "failed to create partition table"))) -(define* (populate-store reference-graphs target) - "Populate the store under directory TARGET with the items specified in -REFERENCE-GRAPHS, a list of reference-graph files." - (define store - (string-append target (%store-directory))) - - (define (things-to-copy) - ;; Return the list of store files to copy to the image. - (define (graph-from-file file) - (call-with-input-file file read-reference-graph)) - - (delete-duplicates (append-map graph-from-file reference-graphs))) - - (mkdir-p store) - (chmod store #o1775) - (for-each (lambda (thing) - (copy-recursively thing - (string-append target thing))) - (things-to-copy))) - (define MS_BIND 4096) ; again! (define* (format-partition partition type diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm index d263edb4f1..624f2a680a 100644 --- a/gnu/system/vm.scm +++ b/gnu/system/vm.scm @@ -116,7 +116,8 @@ input tuple. The output file name is when building for SYSTEM." (gnu build install) (gnu build linux-boot) (gnu build file-systems) - (guix build utils))) + (guix build utils) + (guix build store-copy))) (guile-for-build (%guile-for-build)) diff --git a/guix/build/store-copy.scm b/guix/build/store-copy.scm new file mode 100644 index 0000000000..a296bdf78f --- /dev/null +++ b/guix/build/store-copy.scm @@ -0,0 +1,69 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2013, 2014 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix build store-copy) + #:use-module (guix build utils) + #:use-module (srfi srfi-1) + #:use-module (ice-9 rdelim) + #:export (read-reference-graph + populate-store)) + +;;; Commentary: +;;; +;;; This module provides the tools to copy store items and their dependencies +;;; to another store. It relies on the availability of "reference graph" +;;; files as produced by 'gexp->derivation' et al. with the +;;; #:references-graphs parameter. +;;; +;;; Code: + +(define (read-reference-graph port) + "Return a list of store paths from the reference graph at PORT. +The data at PORT is the format produced by #:references-graphs." + (let loop ((line (read-line port)) + (result '())) + (cond ((eof-object? line) + (delete-duplicates result)) + ((string-prefix? "/" line) + (loop (read-line port) + (cons line result))) + (else + (loop (read-line port) + result))))) + +(define* (populate-store reference-graphs target) + "Populate the store under directory TARGET with the items specified in +REFERENCE-GRAPHS, a list of reference-graph files." + (define store + (string-append target (%store-directory))) + + (define (things-to-copy) + ;; Return the list of store files to copy to the image. + (define (graph-from-file file) + (call-with-input-file file read-reference-graph)) + + (delete-duplicates (append-map graph-from-file reference-graphs))) + + (mkdir-p store) + (chmod store #o1775) + (for-each (lambda (thing) + (copy-recursively thing + (string-append target thing))) + (things-to-copy))) + +;;; store-copy.scm ends here diff --git a/tests/gexp.scm b/tests/gexp.scm index bf52401c66..a08164c484 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm @@ -324,6 +324,44 @@ (return (string=? (derivation-file-name drv) (derivation-file-name xdrv))))) +(test-assertm "gexp->derivation, store copy" + (let ((build-one #~(call-with-output-file #$output + (lambda (port) + (display "This is the one." port)))) + (build-two (lambda (one) + #~(begin + (mkdir #$output) + (symlink #$one (string-append #$output "/one")) + (call-with-output-file (string-append #$output "/two") + (lambda (port) + (display "This is the second one." port)))))) + (build-drv (lambda (two) + #~(begin + (use-modules (guix build store-copy)) + + (mkdir #$output) + '#$two ;make it an input + (populate-store '("graph") #$output))))) + (mlet* %store-monad ((one (gexp->derivation "one" build-one)) + (two (gexp->derivation "two" (build-two one))) + (dir -> (derivation->output-path two)) + (drv (gexp->derivation "store-copy" (build-drv two) + #:references-graphs + `(("graph" . ,dir)) + #:modules + '((guix build store-copy) + (guix build utils)))) + (ok? (built-derivations (list drv))) + (out -> (derivation->output-path drv))) + (let ((one (derivation->output-path one)) + (two (derivation->output-path two))) + (return (and ok? + (file-exists? (string-append out "/" one)) + (file-exists? (string-append out "/" two)) + (file-exists? (string-append out "/" two "/two")) + (string=? (readlink (string-append out "/" two "/one")) + one))))))) + (define shebang (string-append "#!" (derivation->output-path (%guile-for-build)) "/bin/guile --no-auto-compile")) -- cgit v1.2.3 From c7303d3cef71dbe7fad2d082126e787a4385c765 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 2 Sep 2014 20:53:31 -0400 Subject: gnu: Add python-exif-read. * gnu/packages/python.scm (python-exif-read, python2-exif-read): New variables. --- gnu/packages/python.scm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 641a5dfc67..17147b96bc 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -968,3 +968,30 @@ technique that encourages collaboration between developers, QA and non-technical or business participants in a software project. Behave uses tests written in a natural language style, backed up by Python code.") (license x11))) + +(define-public python-exif-read + (package + (name "python-exif-read") + (version "1.4.2") + (source (origin + (method url-fetch) + (uri + (string-append + "https://pypi.python.org/packages/source/E/ExifRead/ExifRead-" + version ".tar.gz")) + (sha256 + (base32 + "17c627gcdmyc05hz4zk8qs4pjgw6rc68qzjzgz8gh1cmpsd7acf1")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (arguments `(#:tests? #f)) ; no tests + (home-page "https://github.com/ianare/exif-py") + (synopsis "Python library to extract EXIF data from image files") + (description + "ExifRead is a Python library to extract EXIF data from tiff and jpeg +files.") + (license bsd-3))) + +(define-public python2-exif-read + (package-with-python2 python-exif-read)) -- cgit v1.2.3 From d5f89b22d82fb1c7f41b784f2711d898ce81396b Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 2 Sep 2014 21:00:40 -0400 Subject: gnu: Add python-pyld. * gnu/packages/python.scm (python-pyld, python2-pyld): New variables. --- gnu/packages/python.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 17147b96bc..ad5def2a8c 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -995,3 +995,29 @@ files.") (define-public python2-exif-read (package-with-python2 python-exif-read)) + +(define-public python-pyld + (package + (name "python-pyld") + (version "0.6.0") + (source (origin + (method url-fetch) + (uri + (string-append + "https://pypi.python.org/packages/source/P/PyLD/PyLD-" + version ".tar.gz")) + (sha256 + (base32 + "1l9ymj85fsvayqplinzpk0kyiq6m74ps9xd3a9fhlxfn1rldf8x8")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (arguments `(#:tests? #f)) ; no tests + (home-page "http://github.com/digitalbazaar/pyld") + (synopsis "Python implementation of the JSON-LD specification") + (description + "PyLD is an implementation of the JSON-LD specification.") + (license bsd-3))) + +(define-public python2-pyld + (package-with-python2 python-pyld)) -- cgit v1.2.3 From 3a1f9a68e5c75097f94f193f96350db97723f027 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 2 Sep 2014 21:22:14 -0400 Subject: gnu: Add python-certifi. * gnu/packages/python.scm (python-certifi, python2-certifi): New variables. --- gnu/packages/python.scm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index ad5def2a8c..766ce16551 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1021,3 +1021,30 @@ files.") (define-public python2-pyld (package-with-python2 python-pyld)) + +(define-public python-certifi + (package + (name "python-certifi") + (version "14.05.14") + (source (origin + (method url-fetch) + (uri + (string-append + "https://pypi.python.org/packages/source/c/certifi/certifi-" + version ".tar.gz")) + (sha256 + (base32 + "0s8vxzfz6s4m6fvxc7z25k9j35w0rh6jkw3wwcd1az1mssncn6qy")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (arguments `(#:tests? #f)) ; no tests + (home-page "http://python-requests.org/") + (synopsis "Python CA certificate bundle") + (description + "Certifi is a Python library that contains a CA certificate bundle, which +is used by the Requests library to verify HTTPS requests.") + (license asl2.0))) + +(define-public python2-certifi + (package-with-python2 python-certifi)) -- cgit v1.2.3 From e6cfbd364a16e372b036cba73c0f94e9c24933c6 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 2 Sep 2014 21:22:43 -0400 Subject: gnu: Add python2-requests. * gnu/packages/python.scm (python2-requests): New variable. --- gnu/packages/python.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 766ce16551..5562ed1a28 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1048,3 +1048,29 @@ is used by the Requests library to verify HTTPS requests.") (define-public python2-certifi (package-with-python2 python-certifi)) + +(define-public python2-requests + (package + (name "python2-requests") + (version "2.4.0") + (source (origin + (method url-fetch) + (uri + (string-append + "https://pypi.python.org/packages/source/r/requests/requests-" + version ".tar.gz")) + (sha256 + (base32 + "0gknlfx1wakrrm1zi8gi03x2lzj4dsns0vjw0nsmgqvkphyf01vh")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools) + ("python-certifi" ,python-certifi))) + (arguments `(#:tests? #f ; no tests + #:python ,python-2)) + (home-page "http://python-requests.org/") + (synopsis "Python HTTP library") + (description + "Requests is a Python HTTP client library. It aims to be easier to use +than Python’s urllib2 library.") + (license asl2.0))) -- cgit v1.2.3 From 864b5211cdb4688f3be66975dba4e753e2e59241 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 3 Sep 2014 08:06:29 -0400 Subject: gnu: Add python-jsonschema. * gnu/packages/python.scm (python-jsonschema, python2-jsonschema): New variables. --- gnu/packages/python.scm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 5562ed1a28..3ef862dd63 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1074,3 +1074,28 @@ is used by the Requests library to verify HTTPS requests.") "Requests is a Python HTTP client library. It aims to be easier to use than Python’s urllib2 library.") (license asl2.0))) + +(define-public python-jsonschema + (package + (name "python-jsonschema") + (version "2.4.0") + (source (origin + (method url-fetch) + (uri + (string-append + "https://pypi.python.org/packages/source/j/jsonschema/jsonschema-" + version ".tar.gz")) + (sha256 + (base32 + "1yik3031ziygvq66rj3mzfqdgxj29sg1bkfc46wsgi7lnbqs560j")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (home-page "http://github.com/Julian/jsonschema") + (synopsis "Implementation of JSON Schema for Python") + (description + "Jsonschema is an implementation of JSON Schema for Python.") + (license expat))) + +(define-public python2-jsonschema + (package-with-python2 python-jsonschema)) -- cgit v1.2.3 From 850189b839e785bcebb2add7043fded688c61fbe Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 3 Sep 2014 23:12:11 -0400 Subject: gnu: Add python-unidecode. * gnu/packages/python.scm (python-unidecode, python2-unidecode): New variables. --- gnu/packages/python.scm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 3ef862dd63..2ff4572a5c 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1099,3 +1099,32 @@ than Python’s urllib2 library.") (define-public python2-jsonschema (package-with-python2 python-jsonschema)) + +(define-public python-unidecode + (package + (name "python-unidecode") + (version "0.04.16") + (source (origin + (method url-fetch) + (uri + (string-append + "https://pypi.python.org/packages/source/U/Unidecode/Unidecode-" + version ".tar.gz")) + (sha256 + (base32 + "0yv56vc49rvippyxgxvcyz7jklc07ky38rcspax7p00sgmriiljc")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (home-page "https://pypi.python.org/pypi/Unidecode") + (synopsis "ASCII transliterations of Unicode text") + (description + "Unidecode provides ASCII transliterations of Unicode text. Unidecode is +useful when integrating with legacy code that doesn't support Unicode, or for +ease of entry of non-Roman names on a US keyboard, or when constructing ASCII +machine identifiers from human-readable Unicode strings that should still be +somewhat intelligeble.") + (license gpl2+))) + +(define-public python2-unidecode + (package-with-python2 python-unidecode)) -- cgit v1.2.3 From 56ea0efd72b82d82f48942c30fce8d74f808513a Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 08:33:45 -0400 Subject: gnu: Add python-mimeparse. * gnu/packages/python.scm (python-mimeparse, python2-mimeparse): New variables. --- gnu/packages/python.scm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 2ff4572a5c..55e8469a63 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -939,6 +939,35 @@ In short, SCons is an easier, more reliable and faster way to build software.") (license x11))) +(define-public python-mimeparse + (package + (name "python-mimeparse") + (version "0.1.4") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/p/python-mimeparse/python-mimeparse-" + version ".tar.gz")) + (sha256 + (base32 + "1hyxg09kaj02ri0rmwjqi86wk4nd1akvv7n0dx77azz76wga4s9w")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (arguments + '(#:tests? #f)) ; no setup.py test command + (home-page + "https://github.com/dbtsai/python-mimeparse") + (synopsis "Python library for parsing MIME types.") + (description + "Mimeparse provides basic functions for parsing MIME type names and +matching them against a list of media-ranges.") + (license expat))) + +(define-public python2-mimeparse + (package-with-python2 python-mimeparse)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From c15a5c0eaca0310e54a1352da5a65cc8df76c084 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 08:37:57 -0400 Subject: gnu: Add python-extras. * gnu/packages/python.scm (python-extras, python2-extras): New variables. --- gnu/packages/python.scm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 55e8469a63..7048b5babc 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -939,6 +939,34 @@ In short, SCons is an easier, more reliable and faster way to build software.") (license x11))) +(define-public python-extras + (package + (name "python-extras") + (version "0.0.3") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/e/extras/extras-" + version ".tar.gz")) + (sha256 + (base32 + "1h7zx4dfyclalg0fqnfjijpn0f793a9mx8sy3b27gd31nr6dhq3s")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (arguments + ;; error in setup.cfg: command 'test' has no such option 'buffer' + '(#:tests? #f)) + (home-page "https://github.com/testing-cabal/extras") + (synopsis "Useful extensions to the Python standard library") + (description + "Extras is a set of extensions to the Python standard library.") + (license expat))) + +(define-public python2-extras + (package-with-python2 python-extras)) + (define-public python-mimeparse (package (name "python-mimeparse") -- cgit v1.2.3 From 4435427e6d87a2b153dffd43a34f3ab234564cc7 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 08:39:43 -0400 Subject: gnu: Add python-nose. * gnu/packages/python.scm (python-nose, python2-nose): New variables. --- gnu/packages/python.scm | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 7048b5babc..0208354205 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -23,7 +23,7 @@ (define-module (gnu packages python) #:use-module ((guix licenses) #:select (asl2.0 bsd-3 bsd-style cc0 expat x11 x11-style - gpl2 gpl2+ lgpl2.1+ + gpl2 gpl2+ lgpl2.0+ lgpl2.1+ psfl public-domain)) #:use-module ((guix licenses) #:select (zlib) #:renamer (symbol-prefix-proc 'license:)) @@ -996,6 +996,33 @@ matching them against a list of media-ranges.") (define-public python2-mimeparse (package-with-python2 python-mimeparse)) +(define-public python-nose + (package + (name "python-nose") + (version "1.3.4") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/n/nose/nose-" + version ".tar.gz")) + (sha256 + (base32 + "00qymfgwg4iam4xi0w9bnv7lcb3fypq1hzfafzgs1rfmwaj67g3n")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (arguments + '(#:tests? #f)) ; FIXME: test suite fails + (home-page "http://readthedocs.org/docs/nose/") + (synopsis "Python testing library") + (description + "Nose extends the unittest library to make testing easier.") + (license lgpl2.0+))) + +(define-public python2-nose + (package-with-python2 python-nose)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From 6cd9c356374a5af6cf4b51f6688b34933e36c982 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 08:45:24 -0400 Subject: gnu: Add python-unittest2. * gnu/packages/python.scm (python-unittest2, python2-unittest2): New variables. --- gnu/packages/python.scm | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 0208354205..fd8c6fefae 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1023,6 +1023,48 @@ matching them against a list of media-ranges.") (define-public python2-nose (package-with-python2 python-nose)) +(define-public python-unittest2 + (package + (name "python-unittest2") + (version "0.5.1") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/u/unittest2py3k/unittest2py3k-" + version ".tar.gz")) + (sha256 + (base32 + "00yl6lskygcrddx5zspkhr0ibgvpknl4678kkm6s626539grq93q")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (home-page "http://pypi.python.org/pypi/unittest2") + (synopsis "Python unit testing library") + (description + "Unittest2 is a replacement for the unittest module in the Python +standard library.") + (license psfl))) + +(define-public python2-unittest2 + (package (inherit python-unittest2) + (name "python2-unittest2") + (version "0.5.1") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/u/unittest2/unittest2-" + version ".tar.gz")) + (sha256 + (base32 + "0wbs4i4x3x7klr3v35ss6p9mcqz883i1xgcpkhvl7n2lyv6yhpda")))) + (inputs + `(("python2-setuptools" ,python-setuptools))) + (arguments + `(#:python ,python-2 + #:tests? #f)))) ; no setup.py test command + (define-public behave (package (name "behave") -- cgit v1.2.3 From 542ad60fbc7de02d86ff61e061af9aa5f6a47453 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 08:59:37 -0400 Subject: gnu: Add python-py. * gnu/packages/python.scm (python-py, python2-py): New variables. --- gnu/packages/python.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index fd8c6fefae..3edc9b1581 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1065,6 +1065,32 @@ standard library.") `(#:python ,python-2 #:tests? #f)))) ; no setup.py test command +(define-public python-py + (package + (name "python-py") + (version "1.4.23") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/p/py/py-" + version ".tar.gz")) + (sha256 + (base32 + "1jkhffpai419v5rickm2vz86p9bkg3b3kcm2k4bi5wfajhw2m3xs")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (home-page "http://pylib.readthedocs.org/") + (synopsis "Python library for parsing, I/O, instrospection, and logging") + (description + "Py is a Python library for file name parsing, .ini file parsing, I/O, +code introspection, and logging.") + (license expat))) + +(define-public python2-py + (package-with-python2 python-py)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From 855d4761a504e217accc85fcc159c70c07dbb951 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 09:16:50 -0400 Subject: gnu: Add python-pytest. * gnu/packages/python.scm (python-pytest, python2-pytest): New variables. --- gnu/packages/python.scm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 3edc9b1581..3e71b39daf 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1091,6 +1091,42 @@ code introspection, and logging.") (define-public python2-py (package-with-python2 python-py)) +(define-public python-pytest + (package + (name "python-pytest") + (version "2.6.1") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/p/pytest/pytest-" + version ".tar.gz")) + (sha256 + (base32 + "0g2w4p0n42wvz8rq4k6gnzpkakgz3g8sfanxk8jrsra9675snkcr")) + (modules '((guix build utils))) + (snippet + ;; One of the tests involves the /usr directory, so it fails. + '(substitute* "testing/test_argcomplete.py" + (("def test_remove_dir_prefix\\(self\\):") + "@pytest.mark.xfail\n def test_remove_dir_prefix(self):"))))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools) + ("python-py" ,python-py) + ("python-nose" ,python-nose) + ("python-mock" ,python-mock))) + (home-page "http://pytest.org") + (synopsis "Python testing library") + (description + "Pytest is a testing tool that provides auto-discovery of test modules +and functions, detailed info on failing assert statements, modular fixtures, +and many external plugins.") + (license expat))) + +(define-public python2-pytest + (package-with-python2 python-pytest)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From 84d240172863e293ed25f38469e9676afb3c2aa9 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 09:19:23 -0400 Subject: gnu: Add python-scripttest. * gnu/packages/python.scm (python-scriptest, python2-scripttest): New variables. --- gnu/packages/python.scm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 3e71b39daf..5235ced452 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1127,6 +1127,33 @@ and many external plugins.") (define-public python2-pytest (package-with-python2 python-pytest)) +(define-public python-scripttest + (package + (name "python-scripttest") + (version "1.3") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/s/scripttest/scripttest-" + version ".tar.gz")) + (sha256 + (base32 + "0f4w84k8ck82syys7yg9maz93mqzc8p5ymis941x034v44jzq74m")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools) + ("python-pytest" ,python-pytest))) + (home-page "http://pythonpaste.org/scripttest/") + (synopsis "Python library to test command-line scripts") + (description "Scripttest is a Python helper library for testing +interactive command-line applications. With it you can run a script in a +subprocess and see the output as well as any file modifications.") + (license expat))) + +(define-public python2-scripttest + (package-with-python2 python-scripttest)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From d8fa80e13fbe7295dd85dffd89e15bbf748f5143 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 09:22:29 -0400 Subject: gnu: Add python-testtools. * gnu/packages/python.scm (python-testtools, python2-testtools): New variables. --- gnu/packages/python.scm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 5235ced452..b02f91e464 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1154,6 +1154,36 @@ subprocess and see the output as well as any file modifications.") (define-public python2-scripttest (package-with-python2 python-scripttest)) +(define-public python-testtools + (package + (name "python-testtools") + (version "1.0.0") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/t/testtools/testtools-" + version ".tar.gz")) + (sha256 + (base32 + "1dyml28ykpl5jb9khdmcdvhy1cxqingys6qvj2k04fzlaj6z3bbx")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools) + ("python-mimeparse" ,python-mimeparse) + ("python-extras" ,python-extras))) + (home-page "https://github.com/testing-cabal/testtools") + (synopsis + "Extensions to the Python standard library unit testing framework") + (description + "Testtools extends the Python standard library unit testing framework to +provide matchers, more debugging information, and cross-Python +compatibility.") + (license psfl))) + +(define-public python2-testtools + (package-with-python2 python-testtools)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From 5bf3afea6867627be0aab25cb2eb6aad11f1620c Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 09:25:17 -0400 Subject: gnu: Add python-testscenarios. * gnu/packages/python.scm (python-testscenarios, python2-testscenarios): New variables. --- gnu/packages/python.scm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index b02f91e464..61127d8ae0 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1184,6 +1184,34 @@ compatibility.") (define-public python2-testtools (package-with-python2 python-testtools)) +(define-public python-testscenarios + (package + (name "python-testscenarios") + (version "0.4") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/t/testscenarios/testscenarios-" + version ".tar.gz")) + (sha256 + (base32 + "1671jvrvqlmbnc42j7pc5y6vc37q44aiwrq0zic652pxyy2fxvjg")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools) + ("python-testtools" ,python-testtools) + ("python-mimeparse" ,python-mimeparse))) + (home-page "https://launchpad.net/testscenarios") + (synopsis "Pyunit extension for dependency injection") + (description + "Testscenarios provides clean dependency injection for Python unittest +style tests.") + (license (list bsd-3 asl2.0)))) ; at the user's option + +(define-public python2-testscenarios + (package-with-python2 python-testscenarios)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From dac79ecc513099662c9e4b3219b77ee46e900521 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 09:27:41 -0400 Subject: gnu: Add python-testresources. * gnu/packages/python.scm (python-testresources, python2-testresources): New variables. --- gnu/packages/python.scm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 61127d8ae0..40d979009d 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1212,6 +1212,33 @@ style tests.") (define-public python2-testscenarios (package-with-python2 python-testscenarios)) +(define-public python-testresources + (package + (name "python-testresources") + (version "0.2.7") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/t/testresources/testresources-" + version ".tar.gz")) + (sha256 + (base32 + "0cbj3plbllyz42c4b5xxgwaa7mml54lakslrn4kkhinxhdri22md")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (home-page "https://launchpad.net/testresources") + (synopsis + "Pyunit extension for managing test resources") + (description + "Testresources is an extension to Python's unittest to allow declarative +use of resources by test cases.") + (license (list bsd-3 asl2.0)))) ; at the user's option + +(define-public python2-testresources + (package-with-python2 python-testresources)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From 070ab0588c163151727c6de272c8b9cdf5827469 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 09:30:31 -0400 Subject: gnu: Add python-subunit. * gnu/packages/python.scm (python-subunit, python2-subunit): New variables. --- gnu/packages/python.scm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 40d979009d..914330edcf 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1239,6 +1239,35 @@ use of resources by test cases.") (define-public python2-testresources (package-with-python2 python-testresources)) +(define-public python-subunit + (package + (name "python-subunit") + (version "0.0.21") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/p/python-subunit/python-subunit-" + version ".tar.gz")) + (sha256 + (base32 + "1nkw9wfbvizmpajbj3in8ns07g7lwkiv8hip14jjlwk3cacls6jv")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools) + ("python-testtools" ,python-testtools) + ("python-mimeparse" ,python-mimeparse) + ("python-testscenarios" ,python-testscenarios))) + (home-page "http://launchpad.net/subunit") + (synopsis "Python implementation of the subunit protocol") + (description + "Python-subunit is a Python implementation of the subunit test streaming +protocol.") + (license (list bsd-3 asl2.0)))) ; at the user's option + +(define-public python2-subunit + (package-with-python2 python-subunit)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From cd49454b7b6ec56f2ada0f818a4cdfef95431f24 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 09:33:38 -0400 Subject: gnu: Add python-fixtures. * gnu/packages/python.scm (python-fixtures, python2-fixtures): New variables. --- gnu/packages/python.scm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 914330edcf..72ca7e312a 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1268,6 +1268,34 @@ protocol.") (define-public python2-subunit (package-with-python2 python-subunit)) +(define-public python-fixtures + (package + (name "python-fixtures") + (version "0.3.16") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/f/fixtures/fixtures-" + version ".tar.gz")) + (sha256 + (base32 + "0x9r2gwilcig5g54k60bxzg96zabizq1855lrprlb4zckalp9asc")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (arguments + '(#:tests? #f)) ; no setup.py test command + (home-page "https://launchpad.net/python-fixtures") + (synopsis "Python test fixture library") + (description + "Fixtures provides a way to create reusable state, useful when writing +Python tests.") + (license (list bsd-3 asl2.0)))) ; at user's option + +(define-public python2-fixtures + (package-with-python2 python-fixtures)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From b24a0c00e40a976c908ffc2245aeb14ee87f96c0 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 09:36:45 -0400 Subject: gnu: Add python-testrepository. * gnu/packages/python.scm (python-testrepository, python2-testrepository): New variables. --- gnu/packages/python.scm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 72ca7e312a..57d8daf432 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1296,6 +1296,36 @@ Python tests.") (define-public python2-fixtures (package-with-python2 python-fixtures)) +(define-public python-testrepository + (package + (name "python-testrepository") + (version "0.0.20") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/t/testrepository/testrepository-" + version ".tar.gz")) + (sha256 + (base32 + "1ssqb07c277010i6gzzkbdd46gd9mrj0bi0i8vn560n2k2y4j93m")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools) + ("python-testtools" ,python-testtools) + ("python-subunit" ,python-subunit) + ("python-fixtures" ,python-fixtures) + ("python-mimeparse" ,python-mimeparse))) + (home-page "https://launchpad.net/testrepository") + (synopsis "Database for Python test results") + (description "Testrepository provides a database of test results which can +be used as part of a developer's workflow to check things such as what tests +have failed since the last commit or what tests are currently failing.") + (license (list bsd-3 asl2.0)))) ; at user's option + +(define-public python2-testrepository + (package-with-python2 python-testrepository)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From 243a009adacd85b6e742b754433d99624742c840 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 20:49:23 -0400 Subject: gnu: Add python-coverage. * gnu/packages/python.scm (python-coverage, python2-coverage): New variables. --- gnu/packages/python.scm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 57d8daf432..4577940946 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1326,6 +1326,34 @@ have failed since the last commit or what tests are currently failing.") (define-public python2-testrepository (package-with-python2 python-testrepository)) +(define-public python-coverage + (package + (name "python-coverage") + (version "3.7.1") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/c/coverage/coverage-" + version ".tar.gz")) + (sha256 + (base32 + "0knlbq79g2ww6xzsyknj9rirrgrgc983dpa2d9nkdf31mb2a3bni")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (home-page "http://nedbatchelder.com/code/coverage") + (synopsis "Code coverage measurement for Python") + (description + "Coverage measures code coverage, typically during test execution. It +uses the code analysis tools and tracing hooks provided in the Python standard +library to determine which lines are executable, and which have been +executed.") + (license bsd-3))) + +(define-public python2-coverage + (package-with-python2 python-coverage)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From 041358fb01ec18d8f1c6ef57952a24f189d27070 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 20:49:54 -0400 Subject: gnu: Add python-discover. * gnu/packages/python.scm (python-discover, python2-discover): New variables. --- gnu/packages/python.scm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 4577940946..dbbe794295 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1354,6 +1354,33 @@ executed.") (define-public python2-coverage (package-with-python2 python-coverage)) +(define-public python-discover + (package + (name "python-discover") + (version "0.4.0") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/d/discover/discover-" + version ".tar.gz")) + (sha256 + (base32 + "0y8d0zwiqar51kxj8lzmkvwc3b8kazb04gk5zcb4nzg5k68zmhq5")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (home-page "http://pypi.python.org/pypi/discover/") + (synopsis + "Python test discovery for unittest") + (description + "Discover provides test discovery for unittest, a feature that has been +backported from Python 2.7 for Python 2.4+") + (license bsd-3))) + +(define-public python2-discover + (package-with-python2 python-discover)) + (define-public behave (package (name "behave") -- cgit v1.2.3 From 6d45fef43ef2b5fc6e107524d0903a32dcad9999 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 09:45:52 -0400 Subject: gnu: Add python-pyjwt. * gnu/packages/python.scm (python-pyjwt, python2-pyjwt): New variables. --- gnu/packages/python.scm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index dbbe794295..3cb69d26ab 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1570,3 +1570,31 @@ somewhat intelligeble.") (define-public python2-unidecode (package-with-python2 python-unidecode)) + +(define-public python-pyjwt + (package + (name "python-pyjwt") + (version "0.2.1") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/P/PyJWT/PyJWT-" + version ".tar.gz")) + (sha256 + (base32 + "1ahqblfy2sj3xz34wsa48cn9rp0dspzq56p54i5znmws3b8gml6g")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (arguments + '(#:tests? #f)) ; test suite doesn't work + (home-page "http://github.com/progrium/pyjwt") + (synopsis "JSON Web Token implementation in Python") + (description + "PyJWT is a JSON Web Token implementation written in Python.") + (license expat))) + +(define-public python2-pyjwt + (package-with-python2 python-pyjwt)) + -- cgit v1.2.3 From 2cec1f6f56da12886d2c753ee96e74a50404e70a Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 09:52:38 -0400 Subject: gnu: Add python-oauthlib. * gnu/packages/python.scm (python-oauthlib, python2-oauthlib): New variables. --- gnu/packages/python.scm | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 3cb69d26ab..72b42e3590 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1598,3 +1598,48 @@ somewhat intelligeble.") (define-public python2-pyjwt (package-with-python2 python-pyjwt)) +(define-public python-oauthlib + (package + (name "python-oauthlib") + (version "0.6.3") + (source (origin + (method url-fetch) + (uri + (string-append + "https://pypi.python.org/packages/source/o/oauthlib/oauthlib-" + version ".tar.gz")) + (sha256 + (base32 + "1yaj3j64la4arwsbhbfmpnickzh3jpg9nlpyg409v8pp24isn48a")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools) + ("python-pyjwt" ,python-pyjwt) + ("python-pycrypto" ,python-pycrypto) + ("python-nose" ,python-nose) + ("python-mock" ,python-mock))) + (home-page "https://github.com/idan/oauthlib") + (synopsis "OAuth implementation for Python") + (description + "Oauthlib is a generic, spec-compliant, thorough implementation of the +OAuth request-signing logic.") + (license bsd-3))) + +(define-public python2-oauthlib + (let ((base (package-with-python2 python-oauthlib))) + (package + (inherit base) + (name "python2-oauthlib") + (version "0.6.3") + (source (origin + (method url-fetch) + (uri + (string-append + "https://pypi.python.org/packages/source/o/oauthlib/oauthlib-" + version ".tar.gz")) + (sha256 + (base32 + "1yaj3j64la4arwsbhbfmpnickzh3jpg9nlpyg409v8pp24isn48a")))) + (inputs + (append (package-inputs base) + `(("python2-unittest2" ,python2-unittest2))))))) -- cgit v1.2.3 From ec5dbb5c30ffbde60fb93f91c9149076e498b581 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 09:54:47 -0400 Subject: gnu: Add python-itsdangerous. * gnu/packages/python.scm (python-itsdangerous, python2-itsdangerous): New variables. --- gnu/packages/python.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 72b42e3590..6ba8c243f4 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1643,3 +1643,29 @@ OAuth request-signing logic.") (inputs (append (package-inputs base) `(("python2-unittest2" ,python2-unittest2))))))) + +(define-public python-itsdangerous + (package + (name "python-itsdangerous") + (version "0.24") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/i/itsdangerous/itsdangerous-" + version ".tar.gz")) + (sha256 + (base32 + "06856q6x675ly542ig0plbqcyab6ksfzijlyf1hzhgg3sgwgrcyb")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (home-page "http://github.com/mitsuhiko/itsdangerous") + (synopsis "Python library for passing data to/from untrusted environments") + (description + "Itsdangerous provides various helpers to pass trusted data to untrusted +environments and back.") + (license bsd-3))) + +(define-public python2-itsdangerous + (package-with-python2 python-itsdangerous)) -- cgit v1.2.3 From 5731cae394767b7f0fd60afdfe722af625083caf Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 09:57:55 -0400 Subject: gnu: Add python-virtualenv. * gnu/packages/python.scm (python-virtualenv, python2-virtualenv): New variables. --- gnu/packages/python.scm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 6ba8c243f4..a4e9014e4d 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1669,3 +1669,30 @@ environments and back.") (define-public python2-itsdangerous (package-with-python2 python-itsdangerous)) + +(define-public python-virtualenv + (package + (name "python-virtualenv") + (version "1.11.6") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/v/virtualenv/virtualenv-" + version ".tar.gz")) + (sha256 + (base32 + "1xq4prmg25n9cz5zcvbqx68lmc3kl39by582vd8pzs9f3qalqyiy")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools) + ("python-mock" ,python-mock) + ("python-nose" ,python-nose))) + (home-page "https://virtualenv.pypa.io/") + (synopsis "Virtual Python environment builder") + (description + "Virtualenv is a tool to create isolated Python environments.") + (license expat))) + +(define-public python2-virtualenv + (package-with-python2 python-virtualenv)) -- cgit v1.2.3 From 8176d4d55bb05972101373076c5ff7e4085e1c95 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 10:01:13 -0400 Subject: gnu: Add python-markupsafe. * gnu/packages/python.scm (python-markupsafe, python2-markupsafe): New variables. --- gnu/packages/python.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index a4e9014e4d..ab6e5ac275 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1696,3 +1696,29 @@ environments and back.") (define-public python2-virtualenv (package-with-python2 python-virtualenv)) + +(define-public python-markupsafe + (package + (name "python-markupsafe") + (version "0.23") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-" + version ".tar.gz")) + (sha256 + (base32 + "1hvip33wva3fnmvfp9x5klqri7hpl1hkgqmjbss18nmrb7zimv54")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (home-page "http://github.com/mitsuhiko/markupsafe") + (synopsis "XML/HTML/XHTML markup safe string implementation for Python") + (description + "Markupsafe provides an XML/HTML/XHTML markup safe string implementation +for Python.") + (license bsd-3))) + +(define-public python2-markupsafe + (package-with-python2 python-markupsafe)) -- cgit v1.2.3 From fe34f0d152e41d49d63385f12ae7b84774bf3196 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 18:21:28 -0400 Subject: gnu: Add python-jinja2. * gnu/packages/python.scm (python-jinja2, python2-jinja2): New variables. --- gnu/packages/python.scm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index ab6e5ac275..41cab408c2 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1722,3 +1722,30 @@ for Python.") (define-public python2-markupsafe (package-with-python2 python-markupsafe)) + +(define-public python-jinja2 + (package + (name "python-jinja2") + (version "2.7.3") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/J/Jinja2/Jinja2-" + version ".tar.gz")) + (sha256 + (base32 + "1nwg9yfqgy421lncnm63k1zf9xkd1klc0jm0fr4p3dad01fsq91f")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools) + ("python-markupsafe" ,python-markupsafe))) + (home-page "http://jinja.pocoo.org/") + (synopsis "Python template engine") + (description + "Jinja2 is a small but fast and easy to use stand-alone template engine +written in pure Python.") + (license bsd-3))) + +(define-public python2-jinja2 + (package-with-python2 python-jinja2)) -- cgit v1.2.3 From 3580ab8be2a8d3eaae078e31fec902150ad2fdb0 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 18:22:21 -0400 Subject: gnu: Add python-docutils. * gnu/packages/python.scm (python-docutils, python2-docutils): New variables. --- gnu/packages/python.scm | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 41cab408c2..f2d1f90b89 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -22,8 +22,8 @@ (define-module (gnu packages python) #:use-module ((guix licenses) - #:select (asl2.0 bsd-3 bsd-style cc0 expat x11 x11-style - gpl2 gpl2+ lgpl2.0+ lgpl2.1+ + #:select (asl2.0 bsd-3 bsd-2 bsd-style cc0 expat x11 x11-style + gpl2 gpl2+ gpl3+ lgpl2.0+ lgpl2.1+ psfl public-domain)) #:use-module ((guix licenses) #:select (zlib) #:renamer (symbol-prefix-proc 'license:)) @@ -1749,3 +1749,34 @@ written in pure Python.") (define-public python2-jinja2 (package-with-python2 python-jinja2)) + +(define-public python-docutils + (package + (name "python-docutils") + (version "0.12") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/d/docutils/docutils-" + version ".tar.gz")) + (sha256 + (base32 + "1ylnjnw1x4b2y7blr6x35ncdzn69k253kw4cdkv6asdb21w73ny7")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (arguments + '(#:tests? #f)) ; no setup.py test command + (home-page "http://docutils.sourceforge.net/") + (synopsis "Python Documentation Utilities") + (description + "Docutils is a modular system for processing documentation into useful +formats, such as HTML, XML, and LaTeX. For input Docutils supports +reStructuredText.") + ;; Most of the source code is public domain, but some source files are + ;; licensed under the PFSL, BSD 2-clause, and GPLv3+ licenses. + (license (list public-domain psfl bsd-2 gpl3+)))) + +(define-public python2-docutils + (package-with-python2 python-docutils)) -- cgit v1.2.3 From fb35b7c0889f6b6f19edfc2ba26b9a97572638d3 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 18:22:51 -0400 Subject: gnu: Add python-pygments. * gnu/packages/python.scm (python-pygments, python2-pygments): New variables. --- gnu/packages/python.scm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index f2d1f90b89..f012a8d801 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1780,3 +1780,28 @@ reStructuredText.") (define-public python2-docutils (package-with-python2 python-docutils)) + +(define-public python-pygments + (package + (name "python-pygments") + (version "1.6") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/P/Pygments/Pygments-" + version ".tar.gz")) + (sha256 + (base32 + "1h11r6ss8waih51vcksfvzghfxiav2f8svc0812fa5kmyz5d97kr")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools))) + (home-page "http://pygments.org/") + (synopsis "Syntax highlighting") + (description + "Pygments is a syntax highlighting package written in Python.") + (license bsd-2))) + +(define-public python2-pygments + (package-with-python2 python-pygments)) -- cgit v1.2.3 From 9dd6078d3b7f5eff2d3ddfd9a2ca981a6634da3e Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Sep 2014 18:23:22 -0400 Subject: gnu: Add python-sphinx. * gnu/packages/python.scm (python-sphinx, python2-sphinx): New variables. --- gnu/packages/python.scm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'gnu') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index f012a8d801..81b6c956a9 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -1805,3 +1805,32 @@ reStructuredText.") (define-public python2-pygments (package-with-python2 python-pygments)) + +(define-public python-sphinx + (package + (name "python-sphinx") + (version "1.2.3") + (source + (origin + (method url-fetch) + (uri (string-append + "https://pypi.python.org/packages/source/S/Sphinx/Sphinx-" + version ".tar.gz")) + (sha256 + (base32 + "011xizm3jnmf4cvs5i6kgf6c5nn046h79i8j0vd0f27yw9j3p4wl")))) + (build-system python-build-system) + (inputs + `(("python-setuptools" ,python-setuptools) + ("python-jinja2" ,python-jinja2) + ("python-docutils" ,python-docutils) + ("python-pygments" ,python-pygments))) + (home-page "http://sphinx-doc.org/") + (synopsis "Python documentation generator") + (description "Sphinx is a tool that makes it easy to create documentation +for Python projects or other documents consisting of multiple reStructuredText +sources.") + (license bsd-3))) + +(define-public python2-sphinx + (package-with-python2 python-sphinx)) -- cgit v1.2.3 From 8dd09fad528241caddc05d3b2544163235186cbf Mon Sep 17 00:00:00 2001 From: Jason Self Date: Sat, 6 Sep 2014 09:19:08 -0700 Subject: gnu: linux-libre: Update to 3.16.2. * gnu/packages/linux.scm (linux-libre): Update to version 3.16.2. --- gnu/packages/linux.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm index 02a0ae36b5..b5018ce08d 100644 --- a/gnu/packages/linux.scm +++ b/gnu/packages/linux.scm @@ -189,7 +189,7 @@ for SYSTEM, or #f if there is no configuration for SYSTEM." #f))) (define-public linux-libre - (let* ((version "3.16.1") + (let* ((version "3.16.2") (build-phase '(lambda* (#:key system inputs #:allow-other-keys #:rest args) ;; Apply the neat patch. @@ -262,7 +262,7 @@ for SYSTEM, or #f if there is no configuration for SYSTEM." (uri (linux-libre-urls version)) (sha256 (base32 - "1x4y0017l4ndcab4smky2wx0n86r3wyks2r8yyp19ia9ccnl98mf")))) + "16l5l099qv367d3gknpbycgrakli2mdklvgaifsn3hcrrjs44ybf")))) (build-system gnu-build-system) (native-inputs `(("perl" ,perl) ("bc" ,bc) -- cgit v1.2.3 From 108293c5ea65502e351cb2f6682668d5d345dd1f Mon Sep 17 00:00:00 2001 From: Jason Self Date: Sat, 6 Sep 2014 09:33:41 -0700 Subject: gnu: linux-libre: Revert to 3.16.1. * gnu/packages/linux.scm (linux-libre): Revert to version 3.16.1. --- gnu/packages/linux.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm index b5018ce08d..02a0ae36b5 100644 --- a/gnu/packages/linux.scm +++ b/gnu/packages/linux.scm @@ -189,7 +189,7 @@ for SYSTEM, or #f if there is no configuration for SYSTEM." #f))) (define-public linux-libre - (let* ((version "3.16.2") + (let* ((version "3.16.1") (build-phase '(lambda* (#:key system inputs #:allow-other-keys #:rest args) ;; Apply the neat patch. @@ -262,7 +262,7 @@ for SYSTEM, or #f if there is no configuration for SYSTEM." (uri (linux-libre-urls version)) (sha256 (base32 - "16l5l099qv367d3gknpbycgrakli2mdklvgaifsn3hcrrjs44ybf")))) + "1x4y0017l4ndcab4smky2wx0n86r3wyks2r8yyp19ia9ccnl98mf")))) (build-system gnu-build-system) (native-inputs `(("perl" ,perl) ("bc" ,bc) -- cgit v1.2.3 From b53833b2ef36cf139f65193bec688396a734b0d0 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 6 Sep 2014 15:45:32 +0200 Subject: gexp: Allow use of high-level objects in #:references-graphs. * guix/gexp.scm (lower-reference-graphs): New procedure. (gexp->derivation)[graphs-file-names]: New procedure. Use 'lower-reference-graphs', and augment #:inputs argument as a function of #:references-graphs. * doc/guix.texi (G-Expressions): Adjust 'gexp->derivation' documentation accordingly. * tests/gexp.scm ("gexp->derivation, store copy"): Remove reference to TWO in BUILD-DRV. Use TWO directly in #:references-graphs argument. ("gexp->derivation #:references-graphs"): New test. * gnu/system/vm.scm (qemu-image): Remove variable 'graph'; use INPUTS as the #:references-graphs argument to 'expression->derivation-in-linux-vm'. --- doc/guix.texi | 16 +++++++++++ gnu/system/vm.scm | 82 +++++++++++++++++++++++++++---------------------------- guix/gexp.scm | 51 ++++++++++++++++++++++++++++++++-- tests/gexp.scm | 52 +++++++++++++++++++++++++++++------ 4 files changed, 148 insertions(+), 53 deletions(-) (limited to 'gnu') diff --git a/doc/guix.texi b/doc/guix.texi index 1f192bf0a7..e0251f5ffd 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -2278,6 +2278,22 @@ search path to be copied in the store, compiled, and made available in the load path during the execution of @var{exp}---e.g., @code{((guix build utils) (guix build gnu-build-system))}. +When @var{references-graphs} is true, it must be a list of tuples of one of the +following forms: + +@example +(@var{file-name} @var{package}) +(@var{file-name} @var{package} @var{output}) +(@var{file-name} @var{derivation}) +(@var{file-name} @var{derivation} @var{output}) +(@var{file-name} @var{store-item}) +@end example + +The right-hand-side of each element of @var{references-graphs} is automatically made +an input of the build process of @var{exp}. In the build environment, each +@var{file-name} contains the reference graph of the corresponding item, in a simple +text format. + The other arguments are as for @code{derivation} (@pxref{Derivations}). @end deffn diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm index 624f2a680a..205bf2cb19 100644 --- a/gnu/system/vm.scm +++ b/gnu/system/vm.scm @@ -219,48 +219,46 @@ INPUTS is a list of inputs (as for packages). When COPY-INPUTS? is true, copy all of INPUTS into the image being built. When REGISTER-CLOSURES? is true, register INPUTS in the store database of the image so that Guix can be used in the image." - (mlet %store-monad - ((graph (sequence %store-monad (map input->name+output inputs)))) - (expression->derivation-in-linux-vm - name - #~(begin - (use-modules (gnu build vm) - (guix build utils)) - - (let ((inputs - '#$(append (list qemu parted grub e2fsprogs util-linux) - (map canonical-package - (list sed grep coreutils findutils gawk)) - (if register-closures? (list guix) '()))) - - ;; This variable is unused but allows us to add INPUTS-TO-COPY - ;; as inputs. - (to-register - '#$(map (match-lambda - ((name thing) thing) - ((name thing output) `(,thing ,output))) - inputs))) - - (set-path-environment-variable "PATH" '("bin" "sbin") inputs) - - (let ((graphs '#$(match inputs - (((names . _) ...) - names)))) - (initialize-hard-disk "/dev/vda" - #:system-directory #$os-derivation - #:grub.cfg #$grub-configuration - #:closures graphs - #:copy-closures? #$copy-inputs? - #:register-closures? #$register-closures? - #:disk-image-size #$disk-image-size - #:file-system-type #$file-system-type - #:file-system-label #$file-system-label) - (reboot)))) - #:system system - #:make-disk-image? #t - #:disk-image-size disk-image-size - #:disk-image-format disk-image-format - #:references-graphs graph))) + (expression->derivation-in-linux-vm + name + #~(begin + (use-modules (gnu build vm) + (guix build utils)) + + (let ((inputs + '#$(append (list qemu parted grub e2fsprogs util-linux) + (map canonical-package + (list sed grep coreutils findutils gawk)) + (if register-closures? (list guix) '()))) + + ;; This variable is unused but allows us to add INPUTS-TO-COPY + ;; as inputs. + (to-register + '#$(map (match-lambda + ((name thing) thing) + ((name thing output) `(,thing ,output))) + inputs))) + + (set-path-environment-variable "PATH" '("bin" "sbin") inputs) + + (let ((graphs '#$(match inputs + (((names . _) ...) + names)))) + (initialize-hard-disk "/dev/vda" + #:system-directory #$os-derivation + #:grub.cfg #$grub-configuration + #:closures graphs + #:copy-closures? #$copy-inputs? + #:register-closures? #$register-closures? + #:disk-image-size #$disk-image-size + #:file-system-type #$file-system-type + #:file-system-label #$file-system-label) + (reboot)))) + #:system system + #:make-disk-image? #t + #:disk-image-size disk-image-size + #:disk-image-format disk-image-format + #:references-graphs inputs)) ;;; diff --git a/guix/gexp.scm b/guix/gexp.scm index e31324e101..5401cbf96f 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -109,6 +109,17 @@ the cross-compilation target triplet." (return input))) inputs)))) +(define* (lower-reference-graphs graphs #:key system target) + "Given GRAPHS, a list of (FILE-NAME INPUT ...) lists for use as a +#:reference-graphs argument, lower it such that each INPUT is replaced by the +corresponding derivation." + (match graphs + (((file-names . inputs) ...) + (mlet %store-monad ((inputs (lower-inputs inputs + #:system system + #:target target))) + (return (map cons file-names inputs)))))) + (define* (gexp->derivation name exp #:key system (target 'current) @@ -127,10 +138,38 @@ names of Guile modules from the current search path to be copied in the store, compiled, and made available in the load path during the execution of EXP---e.g., '((guix build utils) (guix build gnu-build-system)). +When REFERENCES-GRAPHS is true, it must be a list of tuples of one of the +following forms: + + (FILE-NAME PACKAGE) + (FILE-NAME PACKAGE OUTPUT) + (FILE-NAME DERIVATION) + (FILE-NAME DERIVATION OUTPUT) + (FILE-NAME STORE-ITEM) + +The right-hand-side of each element of REFERENCES-GRAPHS is automatically made +an input of the build process of EXP. In the build environment, each +FILE-NAME contains the reference graph of the corresponding item, in a simple +text format. + +In that case, the reference graph of each store path is exported in +the build environment in the corresponding file, in a simple text format. + The other arguments are as for 'derivation'." (define %modules modules) (define outputs (gexp-outputs exp)) + (define (graphs-file-names graphs) + ;; Return a list of (FILE-NAME . STORE-PATH) pairs made from GRAPHS. + (map (match-lambda + ((file-name (? derivation? drv)) + (cons file-name (derivation->output-path drv))) + ((file-name (? derivation? drv) sub-drv) + (cons file-name (derivation->output-path drv sub-drv))) + ((file-name thing) + (cons file-name thing))) + graphs)) + (mlet* %store-monad (;; The following binding is here to force ;; '%current-system' and '%current-target-system' to be ;; looked up at >>= time. @@ -162,6 +201,11 @@ The other arguments are as for 'derivation'." #:system system #:guile guile-for-build) (return #f))) + (graphs (if references-graphs + (lower-reference-graphs references-graphs + #:system system + #:target target) + (return #f))) (guile (if guile-for-build (return guile-for-build) (package->derivation (default-guile) @@ -182,9 +226,12 @@ The other arguments are as for 'derivation'." (,builder) ,@(if modules `((,modules) (,compiled) ,@inputs) - inputs)) + inputs) + ,@(match graphs + (((_ . inputs) ...) inputs) + (_ '()))) #:hash hash #:hash-algo hash-algo #:recursive? recursive? - #:references-graphs references-graphs + #:references-graphs (and=> graphs graphs-file-names) #:local-build? local-build?))) (define* (gexp-inputs exp #:optional (references gexp-references)) diff --git a/tests/gexp.scm b/tests/gexp.scm index a08164c484..ea4df48403 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm @@ -335,19 +335,16 @@ (call-with-output-file (string-append #$output "/two") (lambda (port) (display "This is the second one." port)))))) - (build-drv (lambda (two) - #~(begin - (use-modules (guix build store-copy)) + (build-drv #~(begin + (use-modules (guix build store-copy)) - (mkdir #$output) - '#$two ;make it an input - (populate-store '("graph") #$output))))) + (mkdir #$output) + (populate-store '("graph") #$output)))) (mlet* %store-monad ((one (gexp->derivation "one" build-one)) (two (gexp->derivation "two" (build-two one))) - (dir -> (derivation->output-path two)) - (drv (gexp->derivation "store-copy" (build-drv two) + (drv (gexp->derivation "store-copy" build-drv #:references-graphs - `(("graph" . ,dir)) + `(("graph" ,two)) #:modules '((guix build store-copy) (guix build utils)))) @@ -362,6 +359,43 @@ (string=? (readlink (string-append out "/" two "/one")) one))))))) +(test-assertm "gexp->derivation #:references-graphs" + (mlet* %store-monad + ((one (text-file "one" "hello, world")) + (two (gexp->derivation "two" + #~(symlink #$one #$output:chbouib))) + (drv (gexp->derivation "ref-graphs" + #~(begin + (use-modules (guix build store-copy)) + (with-output-to-file #$output + (lambda () + (write (call-with-input-file "guile" + read-reference-graph)))) + (with-output-to-file #$output:one + (lambda () + (write (call-with-input-file "one" + read-reference-graph)))) + (with-output-to-file #$output:two + (lambda () + (write (call-with-input-file "two" + read-reference-graph))))) + #:references-graphs `(("one" ,one) + ("two" ,two "chbouib") + ("guile" ,%bootstrap-guile)) + #:modules '((guix build store-copy) + (guix build utils)))) + (ok? (built-derivations (list drv))) + (guile-drv (package->derivation %bootstrap-guile)) + (g-one -> (derivation->output-path drv "one")) + (g-two -> (derivation->output-path drv "two")) + (g-guile -> (derivation->output-path drv))) + (return (and ok? + (equal? (call-with-input-file g-one read) (list one)) + (equal? (call-with-input-file g-two read) + (list one (derivation->output-path two "chbouib"))) + (equal? (call-with-input-file g-guile read) + (list (derivation->output-path guile-drv))))))) + (define shebang (string-append "#!" (derivation->output-path (%guile-for-build)) "/bin/guile --no-auto-compile")) -- cgit v1.2.3 From 1456cff18fa38c57729fd3d91c200a113cbaed59 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 6 Sep 2014 23:26:00 +0200 Subject: gnu: unionfs-fuse/static: Remove store references from the executable. * gnu/packages/linux.scm (unionfs-fuse/static)[arguments]: Add #:phases. --- gnu/packages/linux.scm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'gnu') diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm index 02a0ae36b5..ecb820092a 100644 --- a/gnu/packages/linux.scm +++ b/gnu/packages/linux.scm @@ -1092,7 +1092,16 @@ UnionFS-FUSE additionally supports copy-on-write.") libs " dl)")))))) (arguments '(#:tests? #f - #:configure-flags '("-DCMAKE_EXE_LINKER_FLAGS=-static"))) + #:configure-flags '("-DCMAKE_EXE_LINKER_FLAGS=-static") + #:phases (alist-cons-after + 'install 'post-install + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (exe (string-append out "/bin/unionfs"))) + ;; By default, 'unionfs' keeps references to + ;; $glibc/share/locale and similar stuff. Remove them. + (remove-store-references exe))) + %standard-phases))) (inputs `(("fuse" ,fuse-static))))) (define-public sshfs-fuse -- cgit v1.2.3 From 49fa9381b8767c937e80d43f3d1cb0a83690ea1f Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 6 Sep 2014 23:30:28 +0200 Subject: linux-initrd: Populate the initrd's store with complete closures. * gnu/system/linux-initrd.scm (expression->initrd): Add 'graph-files'. Use (guix build store-copy) and 'populate-store' instead of local hack. Pass #:references-graphs to 'gexp->derivation'. --- gnu/system/linux-initrd.scm | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'gnu') diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm index 1108bec51d..627d17bac2 100644 --- a/gnu/system/linux-initrd.scm +++ b/gnu/system/linux-initrd.scm @@ -68,6 +68,12 @@ initrd." ;; General Linux overview in `Documentation/early-userspace/README' and ;; `Documentation/filesystems/ramfs-rootfs-initramfs.txt'. + (define graph-files + (unfold-right zero? + number->string + 1- + (length to-copy))) + (mlet %store-monad ((source (imported-modules modules)) (compiled (compiled-modules modules)) (module-dir (flat-linux-module-directory linux @@ -77,6 +83,7 @@ initrd." #~(begin (use-modules (gnu build linux-initrd) (guix build utils) + (guix build store-copy) (ice-9 pretty-print) (ice-9 popen) (ice-9 match) @@ -98,6 +105,7 @@ initrd." (effective-version)))) (mkdir #$output) (mkdir "contents") + (with-directory-excursion "contents" (copy-recursively #$guile ".") (call-with-output-file "init" @@ -127,17 +135,9 @@ initrd." (mkdir "modules") (copy-recursively #$module-dir "modules") - (let ((store #$(string-append "." (%store-prefix))) - (to-copy '#$to-copy)) - (unless (null? to-copy) - (mkdir-p store)) - ;; XXX: Should we do export-references-graph? - (for-each (lambda (input) - (let ((target - (string-append store "/" - (basename input)))) - (copy-recursively input target))) - to-copy)) + ;; Populate the initrd's store. + (with-directory-excursion ".." + (populate-store '#$graph-files "contents")) ;; Reset the timestamps of all the files that will make it in the ;; initrd. @@ -150,7 +150,9 @@ initrd." (gexp->derivation name builder #:modules '((guix build utils) - (gnu build linux-initrd))))) + (guix build store-copy) + (gnu build linux-initrd)) + #:references-graphs (zip graph-files to-copy)))) (define (flat-linux-module-directory linux modules) "Return a flat directory containing the Linux kernel modules listed in -- cgit v1.2.3 From e46db7728db1b2ba2e826fe57a8d23fed11049a1 Mon Sep 17 00:00:00 2001 From: Jason Self Date: Sat, 6 Sep 2014 19:52:38 -0700 Subject: gnu: linux-libre: Update to 3.16.2. * gnu/packages/linux.scm (linux-libre): Update to version 3.16.2. --- gnu/packages/linux.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm index ecb820092a..442f80103a 100644 --- a/gnu/packages/linux.scm +++ b/gnu/packages/linux.scm @@ -189,7 +189,7 @@ for SYSTEM, or #f if there is no configuration for SYSTEM." #f))) (define-public linux-libre - (let* ((version "3.16.1") + (let* ((version "3.16.2") (build-phase '(lambda* (#:key system inputs #:allow-other-keys #:rest args) ;; Apply the neat patch. @@ -262,7 +262,7 @@ for SYSTEM, or #f if there is no configuration for SYSTEM." (uri (linux-libre-urls version)) (sha256 (base32 - "1x4y0017l4ndcab4smky2wx0n86r3wyks2r8yyp19ia9ccnl98mf")))) + "1p08cqy6427yi808fpbwbb4zbwhnkibj2i1wbrfa5rjhd4vnnffz")))) (build-system gnu-build-system) (native-inputs `(("perl" ,perl) ("bc" ,bc) -- cgit v1.2.3 From 84da4ad4b073e472f1fff747a9fb1952f55e05f9 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 7 Sep 2014 22:57:57 +0200 Subject: linux-initrd: Build cpio archives without '--no-absolute-filenames'. * gnu/build/linux-initrd.scm (write-cpio-archive): Remove '--no-absolute-filenames'. --- gnu/build/linux-initrd.scm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/build/linux-initrd.scm b/gnu/build/linux-initrd.scm index 8caeba8722..bf60137e8f 100644 --- a/gnu/build/linux-initrd.scm +++ b/gnu/build/linux-initrd.scm @@ -35,9 +35,11 @@ (cpio "cpio") (gzip "gzip")) "Write a cpio archive containing DIRECTORY to file OUTPUT, using CPIO. When COMPRESS? is true, compress it using GZIP. On success, return OUTPUT." + + ;; Note: don't use '--no-absolute-filenames' since that strips leading + ;; slashes from symlink targets. (let ((pipe (open-pipe* OPEN_WRITE cpio "-o" "-O" output - "-H" "newc" "--null" - "--no-absolute-filenames"))) + "-H" "newc" "--null"))) (define (print0 file) (format pipe "~a\0" file)) -- cgit v1.2.3