Skip to content
Snippets Groups Projects
Unverified Commit 5a72ddf1 authored by Mathieu Othacehe's avatar Mathieu Othacehe
Browse files

scripts: system: Add --expression option.

* guix/scripts/system.scm (show-help): Add expression option.
(%options): Ditto.
(guix-system): Allow commands taking a file as an argument to use an
expression instead.
(process-action): Read operating-system from expression or file.
* doc/guix.texi (Invoking guix system): Introduce the expression option.
parent d65854bd
No related branches found
No related tags found
No related merge requests found
...@@ -18744,6 +18744,14 @@ Build Options}). In addition, @var{options} can contain one of the ...@@ -18744,6 +18744,14 @@ Build Options}). In addition, @var{options} can contain one of the
following: following:
   
@table @option @table @option
@item --expression=@var{expr}
@itemx -e @var{expr}
Consider the operating-system @var{expr} evaluates to.
This is an alternative to specifying a file which evaluates to an
operating system.
This is used to generate the GuixSD installer @pxref{Building the
Installation Image}).
@item --system=@var{system} @item --system=@var{system}
@itemx -s @var{system} @itemx -s @var{system}
Attempt to build for @var{system} instead of the host system type. Attempt to build for @var{system} instead of the host system type.
......
...@@ -857,6 +857,9 @@ (define (show-help) ...@@ -857,6 +857,9 @@ (define (show-help)
(show-build-options-help) (show-build-options-help)
(display (G_ " (display (G_ "
-d, --derivation return the derivation of the given system")) -d, --derivation return the derivation of the given system"))
(display (G_ "
-e, --expression=EXPR consider the operating-system EXPR evaluates to
instead of reading FILE, when applicable"))
(display (G_ " (display (G_ "
--on-error=STRATEGY --on-error=STRATEGY
apply STRATEGY when an error occurs while reading FILE")) apply STRATEGY when an error occurs while reading FILE"))
...@@ -895,6 +898,9 @@ (define %options ...@@ -895,6 +898,9 @@ (define %options
(option '(#\V "version") #f #f (option '(#\V "version") #f #f
(lambda args (lambda args
(show-version-and-exit "guix system"))) (show-version-and-exit "guix system")))
(option '(#\e "expression") #t #f
(lambda (opt name arg result)
(alist-cons 'expression arg result)))
(option '(#\d "derivation") #f #f (option '(#\d "derivation") #f #f
(lambda (opt name arg result) (lambda (opt name arg result)
(alist-cons 'derivations-only? #t result))) (alist-cons 'derivations-only? #t result)))
...@@ -964,11 +970,19 @@ (define (process-action action args opts) ...@@ -964,11 +970,19 @@ (define (process-action action args opts)
(let* ((file (match args (let* ((file (match args
(() #f) (() #f)
((x . _) x))) ((x . _) x)))
(expr (assoc-ref opts 'expression))
(system (assoc-ref opts 'system)) (system (assoc-ref opts 'system))
(os (if file (os (cond
(load* file %user-module ((and expr file)
#:on-error (assoc-ref opts 'on-error)) (leave
(leave (G_ "no configuration file specified~%")))) (G_ "both file and expression cannot be specified~%")))
(expr
(read/eval expr))
(file
(load* file %user-module
#:on-error (assoc-ref opts 'on-error)))
(else
(leave (G_ "no configuration specified~%")))))
(dry? (assoc-ref opts 'dry-run?)) (dry? (assoc-ref opts 'dry-run?))
(bootloader? (assoc-ref opts 'install-bootloader?)) (bootloader? (assoc-ref opts 'install-bootloader?))
...@@ -1079,7 +1093,8 @@ (define (option-arguments opts) ...@@ -1079,7 +1093,8 @@ (define (option-arguments opts)
;; Extract the plain arguments from OPTS. ;; Extract the plain arguments from OPTS.
(let* ((args (reverse (filter-map (match-pair 'argument) opts))) (let* ((args (reverse (filter-map (match-pair 'argument) opts)))
(count (length args)) (count (length args))
(action (assoc-ref opts 'action))) (action (assoc-ref opts 'action))
(expr (assoc-ref opts 'expression)))
(define (fail) (define (fail)
(leave (G_ "wrong number of arguments for action '~a'~%") (leave (G_ "wrong number of arguments for action '~a'~%")
action)) action))
...@@ -1093,7 +1108,8 @@ (define (fail) ...@@ -1093,7 +1108,8 @@ (define (fail)
(case action (case action
((build container vm vm-image disk-image reconfigure) ((build container vm vm-image disk-image reconfigure)
(unless (= count 1) (unless (or (= count 1)
(and expr (= count 0)))
(fail))) (fail)))
((init) ((init)
(unless (= count 2) (unless (= count 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment