guix: scripts: Add GUIX_BUILD_OPTIONS environment handling.
* doc/guix.texi (Invoking guix build): Mention 'GUIX_BUILD_OPTIONS'. * guix/scripts/archive.scm: (append args (environment-build-options)). * guix/scripts/build.scm: Ditto. * guix/scripts/environment.scm: Ditto. * guix/scripts/package.scm: Ditto. * guix/scripts/system.scm: Ditto. * guix/ui.scm (environment-build-options): New function. * guix/utils.scm (arguments-from-environment-variable): New function. * tests/guix-build.sh: Add tests. * test-env.in: Unset GUIX_BUILD_OPTIONS. Co-authored-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
6efc160efe
commit
16eb115ef4
|
@ -2781,6 +2781,24 @@ the @code{package-derivation} procedure of the @code{(guix packages)}
|
||||||
module, and to the @code{build-derivations} procedure of the @code{(guix
|
module, and to the @code{build-derivations} procedure of the @code{(guix
|
||||||
store)} module.
|
store)} module.
|
||||||
|
|
||||||
|
In addition to options explicitly passed on the command line,
|
||||||
|
@command{guix build} and other @command{guix} commands that support
|
||||||
|
building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
|
||||||
|
|
||||||
|
@defvr {Environment Variable} GUIX_BUILD_OPTIONS
|
||||||
|
Users can define this variable to a list of command line options that
|
||||||
|
will automatically be used by @command{guix build} and other
|
||||||
|
@command{guix} commands that can perform builds, as in the example
|
||||||
|
below:
|
||||||
|
|
||||||
|
@example
|
||||||
|
$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
|
||||||
|
@end example
|
||||||
|
|
||||||
|
These options are appended to the ones passed on the command line.
|
||||||
|
@end defvr
|
||||||
|
|
||||||
|
|
||||||
@node Invoking guix download
|
@node Invoking guix download
|
||||||
@section Invoking @command{guix download}
|
@section Invoking @command{guix download}
|
||||||
|
|
||||||
|
|
|
@ -293,7 +293,8 @@ the input port."
|
||||||
(define (guix-archive . args)
|
(define (guix-archive . args)
|
||||||
(define (parse-options)
|
(define (parse-options)
|
||||||
;; Return the alist of option values.
|
;; Return the alist of option values.
|
||||||
(args-fold* args %options
|
(args-fold* (append args (environment-build-options))
|
||||||
|
%options
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result)
|
||||||
(leave (_ "~A: unrecognized option~%") name))
|
(leave (_ "~A: unrecognized option~%") name))
|
||||||
(lambda (arg result)
|
(lambda (arg result)
|
||||||
|
|
|
@ -401,7 +401,8 @@ arguments with packages that use the specified source."
|
||||||
(define (guix-build . args)
|
(define (guix-build . args)
|
||||||
(define (parse-options)
|
(define (parse-options)
|
||||||
;; Return the alist of option values.
|
;; Return the alist of option values.
|
||||||
(args-fold* args %options
|
(args-fold* (append args (environment-build-options))
|
||||||
|
%options
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result)
|
||||||
(leave (_ "~A: unrecognized option~%") name))
|
(leave (_ "~A: unrecognized option~%") name))
|
||||||
(lambda (arg result)
|
(lambda (arg result)
|
||||||
|
|
|
@ -213,7 +213,8 @@ packages."
|
||||||
;; Entry point.
|
;; Entry point.
|
||||||
(define (guix-environment . args)
|
(define (guix-environment . args)
|
||||||
(define (parse-options)
|
(define (parse-options)
|
||||||
(args-fold* args %options
|
(args-fold* (append args (environment-build-options))
|
||||||
|
%options
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result)
|
||||||
(leave (_ "~A: unrecognized option~%") name))
|
(leave (_ "~A: unrecognized option~%") name))
|
||||||
(lambda (arg result)
|
(lambda (arg result)
|
||||||
|
|
|
@ -668,7 +668,8 @@ removed from MANIFEST."
|
||||||
(define (guix-package . args)
|
(define (guix-package . args)
|
||||||
(define (parse-options)
|
(define (parse-options)
|
||||||
;; Return the alist of option values.
|
;; Return the alist of option values.
|
||||||
(args-fold* args %options
|
(args-fold* (append args (environment-build-options))
|
||||||
|
%options
|
||||||
(lambda (opt name arg result arg-handler)
|
(lambda (opt name arg result arg-handler)
|
||||||
(leave (_ "~A: unrecognized option~%") name))
|
(leave (_ "~A: unrecognized option~%") name))
|
||||||
(lambda (arg result arg-handler)
|
(lambda (arg result arg-handler)
|
||||||
|
|
|
@ -467,7 +467,8 @@ Build the operating system declared in FILE according to ACTION.\n"))
|
||||||
(define (guix-system . args)
|
(define (guix-system . args)
|
||||||
(define (parse-options)
|
(define (parse-options)
|
||||||
;; Return the alist of option values.
|
;; Return the alist of option values.
|
||||||
(args-fold* args %options
|
(args-fold* (append args (environment-build-options))
|
||||||
|
%options
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result)
|
||||||
(leave (_ "~A: unrecognized option~%") name))
|
(leave (_ "~A: unrecognized option~%") name))
|
||||||
(lambda (arg result)
|
(lambda (arg result)
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
string->generations
|
string->generations
|
||||||
string->duration
|
string->duration
|
||||||
args-fold*
|
args-fold*
|
||||||
|
environment-build-options
|
||||||
run-guix-command
|
run-guix-command
|
||||||
program-name
|
program-name
|
||||||
guix-warning-port
|
guix-warning-port
|
||||||
|
@ -712,6 +713,10 @@ reporting."
|
||||||
(leave (_ "invalid argument: ~a~%")
|
(leave (_ "invalid argument: ~a~%")
|
||||||
(apply format #f msg args)))))
|
(apply format #f msg args)))))
|
||||||
|
|
||||||
|
(define (environment-build-options)
|
||||||
|
"Return additional build options passed as environment variables."
|
||||||
|
(arguments-from-environment-variable "GUIX_BUILD_OPTIONS"))
|
||||||
|
|
||||||
(define (show-guix-usage)
|
(define (show-guix-usage)
|
||||||
(format (current-error-port)
|
(format (current-error-port)
|
||||||
(_ "Try `guix --help' for more information.~%"))
|
(_ "Try `guix --help' for more information.~%"))
|
||||||
|
|
|
@ -72,6 +72,7 @@
|
||||||
package-name->name+version
|
package-name->name+version
|
||||||
string-tokenize*
|
string-tokenize*
|
||||||
string-replace-substring
|
string-replace-substring
|
||||||
|
arguments-from-environment-variable
|
||||||
file-extension
|
file-extension
|
||||||
file-sans-extension
|
file-sans-extension
|
||||||
call-with-temporary-output-file
|
call-with-temporary-output-file
|
||||||
|
@ -627,6 +628,15 @@ REPLACEMENT."
|
||||||
(substring str start index)
|
(substring str start index)
|
||||||
pieces))))))))
|
pieces))))))))
|
||||||
|
|
||||||
|
(define (arguments-from-environment-variable variable)
|
||||||
|
"Retrieve value of environment variable denoted by string VARIABLE in the
|
||||||
|
form of a list of strings (`char-set:graphic' tokens) suitable for consumption
|
||||||
|
by `args-fold', if VARIABLE is defined, otherwise return an empty list."
|
||||||
|
(let ((env (getenv variable)))
|
||||||
|
(if env
|
||||||
|
(string-tokenize env char-set:graphic)
|
||||||
|
'())))
|
||||||
|
|
||||||
(define (call-with-temporary-output-file proc)
|
(define (call-with-temporary-output-file proc)
|
||||||
"Call PROC with a name of a temporary file and open output port to that
|
"Call PROC with a name of a temporary file and open output port to that
|
||||||
file; close the file and delete it when leaving the dynamic extent of this
|
file; close the file and delete it when leaving the dynamic extent of this
|
||||||
|
|
|
@ -99,8 +99,8 @@ unset LANGUAGE
|
||||||
LC_MESSAGES=C
|
LC_MESSAGES=C
|
||||||
export LC_MESSAGES
|
export LC_MESSAGES
|
||||||
|
|
||||||
# Ignore user modules.
|
# Ignore user settings.
|
||||||
unset GUIX_PACKAGE_PATH
|
unset GUIX_PACKAGE_PATH GUIX_BUILD_OPTIONS
|
||||||
|
|
||||||
storedir="@storedir@"
|
storedir="@storedir@"
|
||||||
prefix="@prefix@"
|
prefix="@prefix@"
|
||||||
|
|
|
@ -84,3 +84,13 @@ guix build -e "(begin
|
||||||
# Running a gexp.
|
# Running a gexp.
|
||||||
guix build -e '#~(mkdir #$output)' -d
|
guix build -e '#~(mkdir #$output)' -d
|
||||||
guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
|
guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
|
||||||
|
|
||||||
|
# Using 'GUIX_BUILD_OPTIONS'.
|
||||||
|
GUIX_BUILD_OPTIONS="--dry-run"
|
||||||
|
export GUIX_BUILD_OPTIONS
|
||||||
|
|
||||||
|
guix build emacs
|
||||||
|
|
||||||
|
GUIX_BUILD_OPTIONS="--something-completely-crazy"
|
||||||
|
if guix build emacs;
|
||||||
|
then false; else true; fi
|
||||||
|
|
Loading…
Reference in New Issue