diff options
Diffstat (limited to 'guix/scripts')
-rw-r--r-- | guix/scripts/archive.scm | 147 | ||||
-rw-r--r-- | guix/scripts/build.scm | 198 | ||||
-rw-r--r-- | guix/scripts/hash.scm | 33 | ||||
-rw-r--r-- | guix/scripts/offload.scm | 51 | ||||
-rw-r--r-- | guix/scripts/system.scm | 148 |
5 files changed, 370 insertions, 207 deletions
diff --git a/guix/scripts/archive.scm b/guix/scripts/archive.scm index 32690c6b45..4788468584 100644 --- a/guix/scripts/archive.scm +++ b/guix/scripts/archive.scm @@ -71,17 +71,10 @@ Export/import one or more packages from/to the store.\n")) -s, --system=SYSTEM attempt to build for SYSTEM--e.g., \"i686-linux\"")) (display (_ " --target=TRIPLET cross-build for TRIPLET--e.g., \"armel-linux-gnu\"")) - (display (_ " - -n, --dry-run do not build the derivations")) - (display (_ " - --fallback fall back to building when the substituter fails")) - (display (_ " - --no-substitutes build instead of resorting to pre-built substitutes")) - (display (_ " - --max-silent-time=SECONDS - mark the build as failed after SECONDS of silence")) - (display (_ " - -c, --cores=N allow the use of up to N CPU cores for the build")) + + (newline) + (show-build-options-help) + (newline) (display (_ " -h, --help display this help and exit")) @@ -92,81 +85,60 @@ Export/import one or more packages from/to the store.\n")) (define %options ;; Specifications of the command-line options. - (list (option '(#\h "help") #f #f - (lambda args - (show-help) - (exit 0))) - (option '(#\V "version") #f #f - (lambda args - (show-version-and-exit "guix build"))) + (cons* (option '(#\h "help") #f #f + (lambda args + (show-help) + (exit 0))) + (option '(#\V "version") #f #f + (lambda args + (show-version-and-exit "guix build"))) - (option '("export") #f #f - (lambda (opt name arg result) - (alist-cons 'export #t result))) - (option '("import") #f #f - (lambda (opt name arg result) - (alist-cons 'import #t result))) - (option '("missing") #f #f - (lambda (opt name arg result) - (alist-cons 'missing #t result))) - (option '("generate-key") #f #t - (lambda (opt name arg result) - (catch 'gcry-error - (lambda () - (let ((params - (string->canonical-sexp - (or arg "(genkey (rsa (nbits 4:4096)))")))) - (alist-cons 'generate-key params result))) - (lambda args - (leave (_ "invalid key generation parameters: ~s~%") - arg))))) - (option '("authorize") #f #f - (lambda (opt name arg result) - (alist-cons 'authorize #t result))) + (option '("export") #f #f + (lambda (opt name arg result) + (alist-cons 'export #t result))) + (option '("import") #f #f + (lambda (opt name arg result) + (alist-cons 'import #t result))) + (option '("missing") #f #f + (lambda (opt name arg result) + (alist-cons 'missing #t result))) + (option '("generate-key") #f #t + (lambda (opt name arg result) + (catch 'gcry-error + (lambda () + (let ((params + (string->canonical-sexp + (or arg "(genkey (rsa (nbits 4:4096)))")))) + (alist-cons 'generate-key params result))) + (lambda args + (leave (_ "invalid key generation parameters: ~s~%") + arg))))) + (option '("authorize") #f #f + (lambda (opt name arg result) + (alist-cons 'authorize #t result))) - (option '(#\S "source") #f #f - (lambda (opt name arg result) - (alist-cons 'source? #t result))) - (option '(#\s "system") #t #f - (lambda (opt name arg result) - (alist-cons 'system arg - (alist-delete 'system result eq?)))) - (option '("target") #t #f - (lambda (opt name arg result) - (alist-cons 'target arg - (alist-delete 'target result eq?)))) - (option '(#\e "expression") #t #f - (lambda (opt name arg result) - (alist-cons 'expression arg result))) - (option '(#\c "cores") #t #f - (lambda (opt name arg result) - (let ((c (false-if-exception (string->number arg)))) - (if c - (alist-cons 'cores c result) - (leave (_ "~a: not a number~%") arg))))) - (option '(#\n "dry-run") #f #f - (lambda (opt name arg result) - (alist-cons 'dry-run? #t result))) - (option '("fallback") #f #f - (lambda (opt name arg result) - (alist-cons 'fallback? #t - (alist-delete 'fallback? result)))) - (option '("no-substitutes") #f #f - (lambda (opt name arg result) - (alist-cons 'substitutes? #f - (alist-delete 'substitutes? result)))) - (option '("max-silent-time") #t #f - (lambda (opt name arg result) - (alist-cons 'max-silent-time (string->number* arg) - result))) - (option '(#\r "root") #t #f - (lambda (opt name arg result) - (alist-cons 'gc-root arg result))) - (option '("verbosity") #t #f - (lambda (opt name arg result) - (let ((level (string->number arg))) - (alist-cons 'verbosity level - (alist-delete 'verbosity result))))))) + (option '(#\S "source") #f #f + (lambda (opt name arg result) + (alist-cons 'source? #t result))) + (option '(#\s "system") #t #f + (lambda (opt name arg result) + (alist-cons 'system arg + (alist-delete 'system result eq?)))) + (option '("target") #t #f + (lambda (opt name arg result) + (alist-cons 'target arg + (alist-delete 'target result eq?)))) + (option '(#\e "expression") #t #f + (lambda (opt name arg result) + (alist-cons 'expression arg result))) + (option '(#\n "dry-run") #f #f + (lambda (opt name arg result) + (alist-cons 'dry-run? #t result))) + (option '(#\r "root") #t #f + (lambda (opt name arg result) + (alist-cons 'gc-root arg result))) + + %standard-build-options)) (define (options->derivations+files store opts) "Given OPTS, the result of 'args-fold', return a list of derivations to @@ -219,16 +191,11 @@ build and a list of store files to transfer." resulting archive to the standard output port." (let-values (((drv files) (options->derivations+files store opts))) + (set-build-options-from-command-line store opts) (show-what-to-build store drv #:use-substitutes? (assoc-ref opts 'substitutes?) #:dry-run? (assoc-ref opts 'dry-run?)) - (set-build-options store - #:build-cores (or (assoc-ref opts 'cores) 0) - #:fallback? (assoc-ref opts 'fallback?) - #:use-substitutes? (assoc-ref opts 'substitutes?) - #:max-silent-time (assoc-ref opts 'max-silent-time)) - (if (or (assoc-ref opts 'dry-run?) (build-derivations store drv)) (export-paths store files (current-output-port)) diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm index 7cb3710853..4a00505022 100644 --- a/guix/scripts/build.scm +++ b/guix/scripts/build.scm @@ -34,6 +34,11 @@ #:use-module (srfi srfi-37) #:autoload (gnu packages) (find-best-packages-by-name) #:export (derivation-from-expression + + %standard-build-options + set-build-options-from-command-line + show-build-options-help + guix-build)) (define (derivation-from-expression store str package-derivation @@ -101,30 +106,13 @@ present, return the preferred newest version." ;;; -;;; Command-line options. +;;; Standard command-line build options. ;;; -(define %default-options - ;; Alist of default option values. - `((system . ,(%current-system)) - (substitutes? . #t) - (build-hook? . #t) - (max-silent-time . 3600) - (verbosity . 0))) - -(define (show-help) - (display (_ "Usage: guix build [OPTION]... PACKAGE-OR-DERIVATION... -Build the given PACKAGE-OR-DERIVATION and return their output paths.\n")) - (display (_ " - -e, --expression=EXPR build the package or derivation EXPR evaluates to")) - (display (_ " - -S, --source build the packages' source derivations")) - (display (_ " - -s, --system=SYSTEM attempt to build for SYSTEM--e.g., \"i686-linux\"")) - (display (_ " - --target=TRIPLET cross-build for TRIPLET--e.g., \"armel-linux-gnu\"")) - (display (_ " - -d, --derivations return the derivation paths of the given packages")) +(define (show-build-options-help) + "Display on the current output port help about the standard command-line +options handled by 'set-build-options-from-command-line', and listed in +'%standard-build-options'." (display (_ " -K, --keep-failed keep build tree of failed builds")) (display (_ " @@ -139,61 +127,28 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n")) --max-silent-time=SECONDS mark the build as failed after SECONDS of silence")) (display (_ " - -c, --cores=N allow the use of up to N CPU cores for the build")) - (display (_ " - -r, --root=FILE make FILE a symlink to the result, and register it - as a garbage collector root")) - (display (_ " --verbosity=LEVEL use the given verbosity LEVEL")) (display (_ " - --log-file return the log file names for the given derivations")) - (newline) - (display (_ " - -h, --help display this help and exit")) - (display (_ " - -V, --version display version information and exit")) - (newline) - (show-bug-report-information)) + -c, --cores=N allow the use of up to N CPU cores for the build"))) -(define %options - ;; Specifications of the command-line options. - (list (option '(#\h "help") #f #f - (lambda args - (show-help) - (exit 0))) - (option '(#\V "version") #f #f - (lambda args - (show-version-and-exit "guix build"))) +(define (set-build-options-from-command-line store opts) + "Given OPTS, an alist as returned by 'args-fold' given +'%standard-build-options', set the corresponding build options on STORE." + ;; TODO: Add more options. + (set-build-options store + #:keep-failed? (assoc-ref opts 'keep-failed?) + #:build-cores (or (assoc-ref opts 'cores) 0) + #:fallback? (assoc-ref opts 'fallback?) + #:use-substitutes? (assoc-ref opts 'substitutes?) + #:use-build-hook? (assoc-ref opts 'build-hook?) + #:max-silent-time (assoc-ref opts 'max-silent-time) + #:verbosity (assoc-ref opts 'verbosity))) - (option '(#\S "source") #f #f - (lambda (opt name arg result) - (alist-cons 'source? #t result))) - (option '(#\s "system") #t #f - (lambda (opt name arg result) - (alist-cons 'system arg - (alist-delete 'system result eq?)))) - (option '("target") #t #f - (lambda (opt name arg result) - (alist-cons 'target arg - (alist-delete 'target result eq?)))) - (option '(#\d "derivations") #f #f - (lambda (opt name arg result) - (alist-cons 'derivations-only? #t result))) - (option '(#\e "expression") #t #f - (lambda (opt name arg result) - (alist-cons 'expression arg result))) - (option '(#\K "keep-failed") #f #f +(define %standard-build-options + ;; List of standard command-line options for tools that build something. + (list (option '(#\K "keep-failed") #f #f (lambda (opt name arg result) (alist-cons 'keep-failed? #t result))) - (option '(#\c "cores") #t #f - (lambda (opt name arg result) - (let ((c (false-if-exception (string->number arg)))) - (if c - (alist-cons 'cores c result) - (leave (_ "~a: not a number~%") arg))))) - (option '(#\n "dry-run") #f #f - (lambda (opt name arg result) - (alist-cons 'dry-run? #t result))) (option '("fallback") #f #f (lambda (opt name arg result) (alist-cons 'fallback? #t @@ -210,17 +165,97 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n")) (lambda (opt name arg result) (alist-cons 'max-silent-time (string->number* arg) result))) - (option '(#\r "root") #t #f - (lambda (opt name arg result) - (alist-cons 'gc-root arg result))) (option '("verbosity") #t #f (lambda (opt name arg result) (let ((level (string->number arg))) (alist-cons 'verbosity level (alist-delete 'verbosity result))))) - (option '("log-file") #f #f + (option '(#\c "cores") #t #f (lambda (opt name arg result) - (alist-cons 'log-file? #t result))))) + (let ((c (false-if-exception (string->number arg)))) + (if c + (alist-cons 'cores c result) + (leave (_ "~a: not a number~%") arg))))))) + + +;;; +;;; Command-line options. +;;; + +(define %default-options + ;; Alist of default option values. + `((system . ,(%current-system)) + (substitutes? . #t) + (build-hook? . #t) + (max-silent-time . 3600) + (verbosity . 0))) + +(define (show-help) + (display (_ "Usage: guix build [OPTION]... PACKAGE-OR-DERIVATION... +Build the given PACKAGE-OR-DERIVATION and return their output paths.\n")) + (display (_ " + -e, --expression=EXPR build the package or derivation EXPR evaluates to")) + (display (_ " + -S, --source build the packages' source derivations")) + (display (_ " + -s, --system=SYSTEM attempt to build for SYSTEM--e.g., \"i686-linux\"")) + (display (_ " + --target=TRIPLET cross-build for TRIPLET--e.g., \"armel-linux-gnu\"")) + (display (_ " + -d, --derivations return the derivation paths of the given packages")) + (display (_ " + -r, --root=FILE make FILE a symlink to the result, and register it + as a garbage collector root")) + (display (_ " + --log-file return the log file names for the given derivations")) + (newline) + (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 build"))) + + (option '(#\S "source") #f #f + (lambda (opt name arg result) + (alist-cons 'source? #t result))) + (option '(#\s "system") #t #f + (lambda (opt name arg result) + (alist-cons 'system arg + (alist-delete 'system result eq?)))) + (option '("target") #t #f + (lambda (opt name arg result) + (alist-cons 'target arg + (alist-delete 'target result eq?)))) + (option '(#\d "derivations") #f #f + (lambda (opt name arg result) + (alist-cons 'derivations-only? #t result))) + (option '(#\e "expression") #t #f + (lambda (opt name arg result) + (alist-cons 'expression arg result))) + (option '(#\n "dry-run") #f #f + (lambda (opt name arg result) + (alist-cons 'dry-run? #t result))) + (option '(#\r "root") #t #f + (lambda (opt name arg result) + (alist-cons 'gc-root arg result))) + (option '("log-file") #f #f + (lambda (opt name arg result) + (alist-cons 'log-file? #t result))) + + %standard-build-options)) (define (options->derivations store opts) "Given OPTS, the result of 'args-fold', return a list of derivations to @@ -279,21 +314,12 @@ build." (_ #f)) opts))) + (set-build-options-from-command-line store opts) (unless (assoc-ref opts 'log-file?) (show-what-to-build store drv #:use-substitutes? (assoc-ref opts 'substitutes?) #:dry-run? (assoc-ref opts 'dry-run?))) - ;; TODO: Add more options. - (set-build-options store - #:keep-failed? (assoc-ref opts 'keep-failed?) - #:build-cores (or (assoc-ref opts 'cores) 0) - #:fallback? (assoc-ref opts 'fallback?) - #:use-substitutes? (assoc-ref opts 'substitutes?) - #:use-build-hook? (assoc-ref opts 'build-hook?) - #:max-silent-time (assoc-ref opts 'max-silent-time) - #:verbosity (assoc-ref opts 'verbosity)) - (cond ((assoc-ref opts 'log-file?) (for-each (lambda (file) (let ((log (log-file store file))) diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm index ca3928b8e3..ea8c2ada6b 100644 --- a/guix/scripts/hash.scm +++ b/guix/scripts/hash.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org> +;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org> ;;; ;;; This file is part of GNU Guix. @@ -20,12 +20,14 @@ (define-module (guix scripts hash) #:use-module (guix base32) #:use-module (guix hash) + #:use-module (guix nar) #:use-module (guix ui) #:use-module (guix utils) #:use-module (rnrs io ports) #:use-module (rnrs files) #:use-module (ice-9 match) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) #:use-module (srfi srfi-37) #:export (guix-hash)) @@ -43,10 +45,12 @@ (display (_ "Usage: guix hash [OPTION] FILE Return the cryptographic hash of FILE. -Supported formats: 'nix-base32' (default), 'base32', and 'base16' -('hex' and 'hexadecimal' can be used as well).\n")) +Supported formats: 'nix-base32' (default), 'base32', and 'base16' ('hex' +and 'hexadecimal' can be used as well).\n")) (format #t (_ " -f, --format=FMT write the hash in the given format")) + (format #t (_ " + -r, --recursive compute the hash on FILE recursively")) (newline) (display (_ " -h, --help display this help and exit")) @@ -73,6 +77,9 @@ Supported formats: 'nix-base32' (default), 'base32', and 'base16' (alist-cons 'format fmt-proc (alist-delete 'format result)))) + (option '(#\r "recursive") #f #f + (lambda (opt name arg result) + (alist-cons 'recursive? #t result))) (option '(#\h "help") #f #f (lambda args @@ -99,11 +106,6 @@ Supported formats: 'nix-base32' (default), 'base32', and 'base16' (alist-cons 'argument arg result)) %default-options)) - (define (eof->null x) - (if (eof-object? x) - #vu8() - x)) - (let* ((opts (parse-options)) (args (filter-map (match-lambda (('argument . value) @@ -112,13 +114,22 @@ Supported formats: 'nix-base32' (default), 'base32', and 'base16' (reverse opts))) (fmt (assq-ref opts 'format))) + (define (file-hash file) + ;; Compute the hash of FILE. + ;; Catch and gracefully report possible '&nar-error' conditions. + (with-error-handling + (if (assoc-ref opts 'recursive?) + (let-values (((port get-hash) (open-sha256-port))) + (write-file file port) + (flush-output-port port) + (get-hash)) + (call-with-input-file file port-sha256)))) + (match args ((file) (catch 'system-error (lambda () - (format #t "~a~%" - (call-with-input-file file - (compose fmt sha256 eof->null get-bytevector-all)))) + (format #t "~a~%" (fmt (file-hash file)))) (lambda args (leave (_ "~a~%") (strerror (system-error-errno args)))))) diff --git a/guix/scripts/offload.scm b/guix/scripts/offload.scm index d919ede3c7..00a145e5e9 100644 --- a/guix/scripts/offload.scm +++ b/guix/scripts/offload.scm @@ -108,7 +108,7 @@ determined." (save-module-excursion (lambda () (set-current-module %user-module) - (primitive-load %machine-file)))) + (primitive-load file)))) (lambda args (match args (('system-error . _) @@ -117,10 +117,10 @@ determined." (if (= ENOENT err) '() (leave (_ "failed to open machine file '~a': ~a~%") - %machine-file (strerror err))))) + file (strerror err))))) (_ (leave (_ "failed to load machine file '~a': ~s~%") - %machine-file args)))))) + file args)))))) (define (open-ssh-gateway machine) "Initiate an SSH connection gateway to MACHINE, and return the PID of the @@ -170,9 +170,9 @@ running lsh gateway upon success, or #f on failure." (define* (offload drv machine #:key print-build-trace? (max-silent-time 3600) - (build-timeout 7200)) + (build-timeout 7200) (log-port (current-output-port))) "Perform DRV on MACHINE, assuming DRV and its prerequisites are available -there. Return a read pipe from where to read the build log." +there, and write the build log to LOG-PORT. Return the exit status." (format (current-error-port) "offloading '~a' to '~a'...~%" (derivation-file-name drv) (build-machine-name machine)) (format (current-error-port) "@ build-remote ~a ~a~%" @@ -185,7 +185,13 @@ there. Return a read pipe from where to read the build log." ,(format #f "--max-silent-time=~a" max-silent-time) ,(derivation-file-name drv))))) - pipe)) + (let loop ((line (read-line pipe))) + (unless (eof-object? line) + (display line log-port) + (newline log-port) + (loop (read-line pipe)))) + + (close-pipe pipe))) (define (send-files files machine) "Send the subset of FILES that's missing to MACHINE's store. Return #t on @@ -291,20 +297,25 @@ success, #f otherwise." (outputs (string-tokenize (read-line)))) (when (send-files (cons (derivation-file-name drv) inputs) machine) - (let ((log (offload drv machine - #:print-build-trace? print-build-trace? - #:max-silent-time max-silent-time - #:build-timeout build-timeout))) - (let loop ((line (read-line log))) - (if (eof-object? line) - (close-pipe log) - (begin - (display line) (newline) - (loop (read-line log)))))) - (retrieve-files outputs machine))) - (format (current-error-port) "done with offloaded '~a'~%" - (derivation-file-name drv)) - (kill pid SIGTERM)) + (let ((status (offload drv machine + #:print-build-trace? print-build-trace? + #:max-silent-time max-silent-time + #:build-timeout build-timeout))) + (kill pid SIGTERM) + (if (zero? status) + (begin + (retrieve-files outputs machine) + (format (current-error-port) + "done with offloaded '~a'~%" + (derivation-file-name drv))) + (begin + (format (current-error-port) + "derivation '~a' offloaded to '~a' failed \ +with exit code ~a~%" + (derivation-file-name drv) + (build-machine-name machine) + (status:exit-val status)) + (primitive-exit (status:exit-val status)))))))) (#f (display "# decline\n"))) (display "# decline\n")))) diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm new file mode 100644 index 0000000000..7799ccbc47 --- /dev/null +++ b/guix/scripts/system.scm @@ -0,0 +1,148 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org> +;;; +;;; 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 <http://www.gnu.org/licenses/>. + +(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 services) + (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 <operating-system> 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))))) |