diff options
| author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2020-08-24 16:26:14 -0400 |
|---|---|---|
| committer | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2020-08-25 13:45:27 -0400 |
| commit | 4b5a6fbc9b754c0ca70d033dd99f17c4f028733a (patch) | |
| tree | 7e1267a5ab1edc10d1b4dd71e51a80f17c8fba36 | |
| parent | a5ccf1b522b443fa2aab79a4833810bdede4a9ff (diff) | |
offload: Modify the build-machine record to accept multiple systems.
* guix/scripts/offload.scm (<build-machine>)[systems]: New field.
[system]: Accessor changed to %build-machine-system. Default to #f.
* guix/scripts/offload.scm (build-machine-system): Wrap %build-machine-system
with a deprecation warning.
(build-machine-systems): Access the new systems field or fallback to use
build-machine-system, for backward compatibility.
(machine-matches?): Adjust.
* tests/offload.scm: Add tests...
* Makefile.am (SCM_TESTS): ...and register them.
* doc/guix.texi (Daemon Offload Setup): Update doc.
| -rw-r--r-- | Makefile.am | 1 | ||||
| -rw-r--r-- | doc/guix.texi | 35 | ||||
| -rw-r--r-- | guix/scripts/offload.scm | 24 | ||||
| -rw-r--r-- | tests/offload.scm | 71 |
4 files changed, 111 insertions, 20 deletions
diff --git a/Makefile.am b/Makefile.am index 4e50a33f82e..9c38c2f83cf 100644 --- a/Makefile.am +++ b/Makefile.am | |||
| @@ -433,6 +433,7 @@ SCM_TESTS = \ | |||
| 433 | tests/monads.scm \ | 433 | tests/monads.scm \ |
| 434 | tests/nar.scm \ | 434 | tests/nar.scm \ |
| 435 | tests/networking.scm \ | 435 | tests/networking.scm \ |
| 436 | tests/offload.scm \ | ||
| 436 | tests/opam.scm \ | 437 | tests/opam.scm \ |
| 437 | tests/openpgp.scm \ | 438 | tests/openpgp.scm \ |
| 438 | tests/packages.scm \ | 439 | tests/packages.scm \ |
diff --git a/doc/guix.texi b/doc/guix.texi index 91d3860978b..0b79a498140 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -1043,29 +1043,31 @@ When desired, the build daemon can @dfn{offload} derivation builds to | |||
| 1043 | other machines running Guix, using the @code{offload} @dfn{build | 1043 | other machines running Guix, using the @code{offload} @dfn{build |
| 1044 | hook}@footnote{This feature is available only when | 1044 | hook}@footnote{This feature is available only when |
| 1045 | @uref{https://github.com/artyom-poptsov/guile-ssh, Guile-SSH} is | 1045 | @uref{https://github.com/artyom-poptsov/guile-ssh, Guile-SSH} is |
| 1046 | present.}. When that | 1046 | present.}. When that feature is enabled, a list of user-specified build |
| 1047 | feature is enabled, a list of user-specified build machines is read from | 1047 | machines is read from @file{/etc/guix/machines.scm}; every time a build |
| 1048 | @file{/etc/guix/machines.scm}; every time a build is requested, for | 1048 | is requested, for instance via @code{guix build}, the daemon attempts to |
| 1049 | instance via @code{guix build}, the daemon attempts to offload it to one | 1049 | offload it to one of the machines that satisfy the constraints of the |
| 1050 | of the machines that satisfy the constraints of the derivation, in | 1050 | derivation, in particular its system types---e.g., @code{x86_64-linux}. |
| 1051 | particular its system type---e.g., @file{x86_64-linux}. Missing | 1051 | A single machine can have multiple system types, either because its |
| 1052 | prerequisites for the build are copied over SSH to the target machine, | 1052 | architecture natively supports it, via emulation (@pxref{Transparent |
| 1053 | which then proceeds with the build; upon success the output(s) of the | 1053 | Emulation with QEMU}), or both. Missing prerequisites for the build are |
| 1054 | build are copied back to the initial machine. | 1054 | copied over SSH to the target machine, which then proceeds with the |
| 1055 | build; upon success the output(s) of the build are copied back to the | ||
| 1056 | initial machine. | ||
| 1055 | 1057 | ||
| 1056 | The @file{/etc/guix/machines.scm} file typically looks like this: | 1058 | The @file{/etc/guix/machines.scm} file typically looks like this: |
| 1057 | 1059 | ||
| 1058 | @lisp | 1060 | @lisp |
| 1059 | (list (build-machine | 1061 | (list (build-machine |
| 1060 | (name "eightysix.example.org") | 1062 | (name "eightysix.example.org") |
| 1061 | (system "x86_64-linux") | 1063 | (systems (list "x86_64-linux" "i686-linux")) |
| 1062 | (host-key "ssh-ed25519 AAAAC3Nza@dots{}") | 1064 | (host-key "ssh-ed25519 AAAAC3Nza@dots{}") |
| 1063 | (user "bob") | 1065 | (user "bob") |
| 1064 | (speed 2.)) ;incredibly fast! | 1066 | (speed 2.)) ;incredibly fast! |
| 1065 | 1067 | ||
| 1066 | (build-machine | 1068 | (build-machine |
| 1067 | (name "armeight.example.org") | 1069 | (name "armeight.example.org") |
| 1068 | (system "aarch64-linux") | 1070 | (systems (list "aarch64-linux")) |
| 1069 | (host-key "ssh-rsa AAAAB3Nza@dots{}") | 1071 | (host-key "ssh-rsa AAAAB3Nza@dots{}") |
| 1070 | (user "alice") | 1072 | (user "alice") |
| 1071 | (private-key | 1073 | (private-key |
| @@ -1075,8 +1077,8 @@ The @file{/etc/guix/machines.scm} file typically looks like this: | |||
| 1075 | 1077 | ||
| 1076 | @noindent | 1078 | @noindent |
| 1077 | In the example above we specify a list of two build machines, one for | 1079 | In the example above we specify a list of two build machines, one for |
| 1078 | the @code{x86_64} architecture and one for the @code{aarch64} | 1080 | the @code{x86_64} and @code{i686} architectures and one for the |
| 1079 | architecture. | 1081 | @code{aarch64} architecture. |
| 1080 | 1082 | ||
| 1081 | In fact, this file is---not surprisingly!---a Scheme file that is | 1083 | In fact, this file is---not surprisingly!---a Scheme file that is |
| 1082 | evaluated when the @code{offload} hook is started. Its return value | 1084 | evaluated when the @code{offload} hook is started. Its return value |
| @@ -1096,8 +1098,9 @@ builds. The important fields are: | |||
| 1096 | @item name | 1098 | @item name |
| 1097 | The host name of the remote machine. | 1099 | The host name of the remote machine. |
| 1098 | 1100 | ||
| 1099 | @item system | 1101 | @item systems |
| 1100 | The system type of the remote machine---e.g., @code{"x86_64-linux"}. | 1102 | The system types the remote machine supports---e.g., @code{(list |
| 1103 | "x86_64-linux" "i686-linux")}. | ||
| 1101 | 1104 | ||
| 1102 | @item user | 1105 | @item user |
| 1103 | The user account to use when connecting to the remote machine over SSH. | 1106 | The user account to use when connecting to the remote machine over SSH. |
| @@ -25025,7 +25028,7 @@ Maximum number of backup files to keep. | |||
| 25025 | Defaults to @samp{3} | 25028 | Defaults to @samp{3} |
| 25026 | 25029 | ||
| 25027 | @end deftypevr | 25030 | @end deftypevr |
| 25028 | 25031 | @node Transparent Emulation with QEMU | |
| 25029 | @subsubheading Transparent Emulation with QEMU | 25032 | @subsubheading Transparent Emulation with QEMU |
| 25030 | 25033 | ||
| 25031 | @cindex emulation | 25034 | @cindex emulation |
diff --git a/guix/scripts/offload.scm b/guix/scripts/offload.scm index 20ae7a94698..a56701f07a0 100644 --- a/guix/scripts/offload.scm +++ b/guix/scripts/offload.scm | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net> | 3 | ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net> |
| 4 | ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com> | ||
| 4 | ;;; | 5 | ;;; |
| 5 | ;;; This file is part of GNU Guix. | 6 | ;;; This file is part of GNU Guix. |
| 6 | ;;; | 7 | ;;; |
| @@ -66,14 +67,16 @@ | |||
| 66 | ;;; | 67 | ;;; |
| 67 | ;;; Code: | 68 | ;;; Code: |
| 68 | 69 | ||
| 69 | |||
| 70 | (define-record-type* <build-machine> | 70 | (define-record-type* <build-machine> |
| 71 | build-machine make-build-machine | 71 | build-machine make-build-machine |
| 72 | build-machine? | 72 | build-machine? |
| 73 | (name build-machine-name) ; string | 73 | (name build-machine-name) ; string |
| 74 | (port build-machine-port ; number | 74 | (port build-machine-port ; number |
| 75 | (default 22)) | 75 | (default 22)) |
| 76 | (system build-machine-system) ; string | 76 | (systems %build-machine-systems ; list of strings |
| 77 | (default #f)) ; drop default after system is removed | ||
| 78 | (system %build-machine-system ; deprecated | ||
| 79 | (default #f)) | ||
| 77 | (user build-machine-user) ; string | 80 | (user build-machine-user) ; string |
| 78 | (private-key build-machine-private-key ; file name | 81 | (private-key build-machine-private-key ; file name |
| 79 | (default (user-openssh-private-key))) | 82 | (default (user-openssh-private-key))) |
| @@ -91,6 +94,19 @@ | |||
| 91 | (features build-machine-features ; list of strings | 94 | (features build-machine-features ; list of strings |
| 92 | (default '()))) | 95 | (default '()))) |
| 93 | 96 | ||
| 97 | ;;; Deprecated. | ||
| 98 | (define (build-machine-system machine) | ||
| 99 | (warning (G_ "The 'system' field is deprecated, \ | ||
| 100 | please use 'systems' instead.~%")) | ||
| 101 | (%build-machine-system machine)) | ||
| 102 | |||
| 103 | ;;; TODO: Remove after the deprecated 'system' field is removed. | ||
| 104 | (define (build-machine-systems machine) | ||
| 105 | (or (%build-machine-systems machine) | ||
| 106 | (list (build-machine-system machine)) | ||
| 107 | (leave (G_ "The build-machine object lacks a value for its 'systems' | ||
| 108 | field.")))) | ||
| 109 | |||
| 94 | (define-record-type* <build-requirements> | 110 | (define-record-type* <build-requirements> |
| 95 | build-requirements make-build-requirements | 111 | build-requirements make-build-requirements |
| 96 | build-requirements? | 112 | build-requirements? |
| @@ -359,8 +375,8 @@ of free disk space on '~a'~%") | |||
| 359 | 375 | ||
| 360 | (define (machine-matches? machine requirements) | 376 | (define (machine-matches? machine requirements) |
| 361 | "Return #t if MACHINE matches REQUIREMENTS." | 377 | "Return #t if MACHINE matches REQUIREMENTS." |
| 362 | (and (string=? (build-requirements-system requirements) | 378 | (and (member (build-requirements-system requirements) |
| 363 | (build-machine-system machine)) | 379 | (build-machine-systems machine)) |
| 364 | (lset<= string=? | 380 | (lset<= string=? |
| 365 | (build-requirements-features requirements) | 381 | (build-requirements-features requirements) |
| 366 | (build-machine-features machine)))) | 382 | (build-machine-features machine)))) |
diff --git a/tests/offload.scm b/tests/offload.scm new file mode 100644 index 00000000000..5a5de4e8b92 --- /dev/null +++ b/tests/offload.scm | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com> | ||
| 3 | ;;; | ||
| 4 | ;;; This file is part of GNU Guix. | ||
| 5 | ;;; | ||
| 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | ;;; under the terms of the GNU General Public License as published by | ||
| 8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | ;;; your option) any later version. | ||
| 10 | ;;; | ||
| 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | ;;; GNU General Public License for more details. | ||
| 15 | ;;; | ||
| 16 | ;;; You should have received a copy of the GNU General Public License | ||
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | (define-module (tests offload) | ||
| 20 | #:use-module (guix scripts offload) | ||
| 21 | #:use-module (srfi srfi-64)) | ||
| 22 | |||
| 23 | |||
| 24 | (test-begin "offload") | ||
| 25 | |||
| 26 | (define-syntax-rule (expose-internal-definitions s1 s2 ...) | ||
| 27 | (begin | ||
| 28 | (define s1 (@@ (guix scripts offload) s1)) | ||
| 29 | (define s2 (@@ (guix scripts offload) s2)) ...)) | ||
| 30 | |||
| 31 | (expose-internal-definitions machine-matches? | ||
| 32 | build-requirements-system | ||
| 33 | build-requirements-features | ||
| 34 | build-machine-system | ||
| 35 | build-machine-systems | ||
| 36 | %build-machine-system | ||
| 37 | %build-machine-systems | ||
| 38 | build-machine-features) | ||
| 39 | |||
| 40 | (define (deprecated-build-machine system) | ||
| 41 | (build-machine | ||
| 42 | (name "m1") | ||
| 43 | (user "dummy") | ||
| 44 | (host-key "some-key") | ||
| 45 | (system system))) | ||
| 46 | |||
| 47 | (define (new-build-machine systems) | ||
| 48 | (build-machine | ||
| 49 | (name "m1") | ||
| 50 | (user "dummy") | ||
| 51 | (host-key "some-key") | ||
| 52 | (systems systems))) | ||
| 53 | |||
| 54 | ;;; Test that deprecated build-machine definitions still work. | ||
| 55 | (test-assert (machine-matches? (deprecated-build-machine "i686-linux") | ||
| 56 | (build-requirements | ||
| 57 | (system "i686-linux")))) | ||
| 58 | |||
| 59 | |||
| 60 | (test-assert (machine-matches? (new-build-machine '("i686-linux")) | ||
| 61 | (build-requirements | ||
| 62 | (system "i686-linux")))) | ||
| 63 | |||
| 64 | ;;; A build machine can act as more than one system type, thanks to QEMU | ||
| 65 | ;;; emulation. | ||
| 66 | (test-assert (machine-matches? (new-build-machine '("armhf-linux" | ||
| 67 | "aarch64-linux" | ||
| 68 | "i686-linux" | ||
| 69 | "x86_64-linux")) | ||
| 70 | (build-requirements | ||
| 71 | (system "armhf-linux")))) | ||
