From 523e48969bd87d26ebbe0a3f4de27257b6d6cb77 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 18 Feb 2014 23:45:58 +0100 Subject: Add 'guix system'. * guix/scripts/system.scm: New file. * Makefile.am (MODULES): Add it. * po/POTFILES.in: Likewise. * doc/guix.texi (Using the Configuration System): Link to "Invoking guix system". (Invoking guix system): New node. --- Makefile.am | 1 + doc/guix.texi | 43 +++++++++++--- guix/scripts/system.scm | 148 ++++++++++++++++++++++++++++++++++++++++++++++++ po/POTFILES.in | 1 + 4 files changed, 185 insertions(+), 8 deletions(-) create mode 100644 guix/scripts/system.scm diff --git a/Makefile.am b/Makefile.am index 16b28eb181..6ad8eb9914 100644 --- a/Makefile.am +++ b/Makefile.am @@ -77,6 +77,7 @@ MODULES = \ guix/scripts/substitute-binary.scm \ guix/scripts/authenticate.scm \ guix/scripts/refresh.scm \ + guix/scripts/system.scm \ guix.scm \ $(GNU_SYSTEM_MODULES) diff --git a/doc/guix.texi b/doc/guix.texi index af84b75108..e6636dc71f 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -2547,8 +2547,9 @@ instantiated. Then we show how this mechanism can be extended, for instance to support new system services. @menu -* Using the Configuration System:: Customizing your GNU system. -* Defining Services:: Adding new service definitions. +* Using the Configuration System:: Customizing your GNU system. +* Invoking guix system:: Instantiating a system configuration. +* Defining Services:: Adding new service definitions. @end menu @node Using the Configuration System @@ -2614,13 +2615,12 @@ daemon listening on port 2222, and allowing remote @code{root} logins right command-line options, possibly with supporting configuration files generated as needed (@pxref{Defining Services}). -@c TODO: update when that command exists Assuming the above snippet is stored in the @file{my-system-config.scm} -file, the (yet unwritten!) @command{guix system --boot -my-system-config.scm} command instantiates that configuration, and makes -it the default GRUB boot entry. The normal way to change the system's -configuration is by updating this file and re-running the @command{guix -system} command. +file, the @command{guix system boot my-system-config.scm} command +instantiates that configuration, and makes it the default GRUB boot +entry (@pxref{Invoking guix system}). The normal way to change the +system's configuration is by updating this file and re-running the +@command{guix system} command. At the Scheme level, the bulk of an @code{operating-system} declaration is instantiated with the following monadic procedure (@pxref{The Store @@ -2635,6 +2635,33 @@ the packages, configuration files, and other supporting files needed to instantiate @var{os}. @end deffn +@node Invoking guix system +@subsection Invoking @code{guix system} + +Once you have written an operating system declaration, as seen in the +previous section, it can be @dfn{instantiated} using the @command{guix +system} command. The synopsis is: + +@example +guix system @var{options}@dots{} @var{action} @var{file} +@end example + +@var{file} must be the name of a file containing an +@code{operating-system} declaration. @var{action} specifies how the +operating system is instantiate. Currently only one value is supported: + +@table @code +@item vm +@cindex virtual machine +Build a virtual machine that contain the operating system declared in +@var{file}, and return a script to run that virtual machine (VM). + +The VM shares its store with the host system. +@end table + +@var{options} can contain any of the common build options provided by +@command{guix build} (@pxref{Invoking guix build}). + @node Defining Services @subsection Defining Services diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm new file mode 100644 index 0000000000..5bb14c4383 --- /dev/null +++ b/guix/scripts/system.scm @@ -0,0 +1,148 @@ +;;; 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 (guix scripts system) + #:use-module (guix ui) + #:use-module (guix store) + #:use-module (guix derivations) + #:use-module (guix packages) + #:use-module (guix utils) + #:use-module (guix monads) + #:use-module (guix scripts build) + #:use-module (gnu system vm) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-37) + #:use-module (ice-9 match) + #:export (guix-system)) + +(define %user-module + ;; Module in which the machine description file is loaded. + (let ((module (make-fresh-user-module))) + (for-each (lambda (iface) + (module-use! module (resolve-interface iface))) + '((gnu system) + (gnu system dmd) + (gnu system shadow))) + module)) + +(define (read-operating-system file) + "Read the operating-system declaration from FILE and return it." + ;; TODO: Factorize. + (catch #t + (lambda () + ;; Avoid ABI incompatibility with the record. + (set! %fresh-auto-compile #t) + + (save-module-excursion + (lambda () + (set-current-module %user-module) + (primitive-load file)))) + (lambda args + (match args + (('system-error . _) + (let ((err (system-error-errno args))) + (leave (_ "failed to open operating system file '~a': ~a~%") + file (strerror err)))) + (_ + (leave (_ "failed to load machine file '~a': ~s~%") + file args)))))) + + +;;; +;;; Options. +;;; + +(define (show-help) + (display (_ "Usage: guix system [OPTION] ACTION FILE +Build the operating system declared in FILE according to ACTION.\n")) + (display (_ "Currently the only valid value for ACTION is 'vm', which builds +a virtual machine of the given operating system.\n")) + (show-build-options-help) + (newline) + (display (_ " + -h, --help display this help and exit")) + (display (_ " + -V, --version display version information and exit")) + (newline) + (show-bug-report-information)) + +(define %options + ;; Specifications of the command-line options. + (cons* (option '(#\h "help") #f #f + (lambda args + (show-help) + (exit 0))) + (option '(#\V "version") #f #f + (lambda args + (show-version-and-exit "guix system"))) + (option '(#\n "dry-run") #f #f + (lambda (opt name arg result) + (alist-cons 'dry-run? #t result))) + %standard-build-options)) + +(define %default-options + ;; Alist of default option values. + `((system . ,(%current-system)) + (substitutes? . #t) + (build-hook? . #t) + (max-silent-time . 3600) + (verbosity . 0))) + + +;;; +;;; Entry point. +;;; + +(define (guix-system . args) + (define (parse-options) + ;; Return the alist of option values. + (args-fold* args %options + (lambda (opt name arg result) + (leave (_ "~A: unrecognized option~%") name)) + (lambda (arg result) + (if (assoc-ref result 'action) + (let ((previous (assoc-ref result 'argument))) + (if previous + (leave (_ "~a: extraneous argument~%") previous) + (alist-cons 'argument arg result))) + (let ((action (string->symbol arg))) + (case action + ((vm) (alist-cons 'action action result)) + (else (leave (_ "~a: unknown action~%") + action)))))) + %default-options)) + + (with-error-handling + (let* ((opts (parse-options)) + (file (assoc-ref opts 'argument)) + (os (if file + (read-operating-system file) + (leave (_ "no configuration file specified~%")))) + (mdrv (system-qemu-image/shared-store-script os)) + (store (open-connection)) + (dry? (assoc-ref opts 'dry-run?)) + (drv (run-with-store store mdrv))) + (set-build-options-from-command-line store opts) + (show-what-to-build store (list drv) + #:dry-run? dry? + #:use-substitutes? (assoc-ref opts 'substitutes?)) + + (unless dry? + (build-derivations store (list drv)) + (display (derivation->output-path drv)) + (newline))))) diff --git a/po/POTFILES.in b/po/POTFILES.in index b329f21e92..ef864fe817 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -12,6 +12,7 @@ guix/scripts/hash.scm guix/scripts/pull.scm guix/scripts/substitute-binary.scm guix/scripts/authenticate.scm +guix/scripts/system.scm guix/gnu-maintenance.scm guix/ui.scm guix/http-client.scm -- cgit v1.2.3