gnu: vm: Set the default networking route.
* gnu/system/dmd.scm (static-networking-service): Add #:gateway parameter and honor it. * gnu/system/vm.scm (system-qemu-image): Pass #:gateway to 'static-networking-service'.
This commit is contained in:
parent
85e0dc6a6b
commit
59c5c4dee1
|
@ -27,6 +27,8 @@
|
||||||
#:select (mingetty inetutils))
|
#:select (mingetty inetutils))
|
||||||
#:use-module ((gnu packages package-management)
|
#:use-module ((gnu packages package-management)
|
||||||
#:select (guix))
|
#:select (guix))
|
||||||
|
#:use-module ((gnu packages linux)
|
||||||
|
#:select (net-tools))
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (srfi srfi-1)
|
#:use-module (srfi srfi-1)
|
||||||
#:export (service?
|
#:export (service?
|
||||||
|
@ -155,20 +157,34 @@
|
||||||
(inputs `(("guix" ,guix))))))
|
(inputs `(("guix" ,guix))))))
|
||||||
|
|
||||||
(define* (static-networking-service store interface ip
|
(define* (static-networking-service store interface ip
|
||||||
#:key (inetutils inetutils))
|
#:key
|
||||||
"Return a service that starts INTERFACE with address IP."
|
gateway
|
||||||
|
(inetutils inetutils)
|
||||||
|
(net-tools net-tools))
|
||||||
|
"Return a service that starts INTERFACE with address IP. If GATEWAY is
|
||||||
|
true, it must be a string specifying the default network gateway."
|
||||||
|
|
||||||
;; TODO: Eventually we should do this using Guile's networking procedures,
|
;; TODO: Eventually we should do this using Guile's networking procedures,
|
||||||
;; like 'configure-qemu-networking' does, but the patch that does this is
|
;; like 'configure-qemu-networking' does, but the patch that does this is
|
||||||
;; not yet in stock Guile.
|
;; not yet in stock Guile.
|
||||||
(let ((ifconfig (string-append (package-output store inetutils)
|
(let ((ifconfig (string-append (package-output store inetutils)
|
||||||
"/bin/ifconfig")))
|
"/bin/ifconfig"))
|
||||||
|
(route (string-append (package-output store net-tools)
|
||||||
|
"/sbin/route")))
|
||||||
(service
|
(service
|
||||||
(provision '(networking))
|
(provision '(networking))
|
||||||
(start `(make-forkexec-constructor ,ifconfig ,interface ,ip "up"))
|
(start `(lambda _
|
||||||
|
(and (zero? (system* ,ifconfig ,interface ,ip "up"))
|
||||||
|
,(if gateway
|
||||||
|
`(zero? (system* ,route "add" "-net" "default"
|
||||||
|
"gw" ,gateway))
|
||||||
|
#t))))
|
||||||
(stop `(make-forkexec-constructor ,ifconfig ,interface "down"))
|
(stop `(make-forkexec-constructor ,ifconfig ,interface "down"))
|
||||||
(respawn? #f)
|
(respawn? #f)
|
||||||
(inputs `(("inetutils" ,inetutils))))))
|
(inputs `(("inetutils" ,inetutils)
|
||||||
|
,@(if gateway
|
||||||
|
`(("net-tools" ,net-tools))
|
||||||
|
'()))))))
|
||||||
|
|
||||||
|
|
||||||
(define (dmd-configuration-file store services)
|
(define (dmd-configuration-file store services)
|
||||||
|
|
|
@ -459,7 +459,8 @@ Happy birthday, GNU! http://www.gnu.org/gnu30
|
||||||
(nscd-service store)
|
(nscd-service store)
|
||||||
|
|
||||||
;; QEMU networking settings.
|
;; QEMU networking settings.
|
||||||
(static-networking-service store "eth0" "10.0.2.10")))
|
(static-networking-service store "eth0" "10.0.2.10"
|
||||||
|
#:gateway "10.0.2.2")))
|
||||||
|
|
||||||
(define resolv.conf
|
(define resolv.conf
|
||||||
;; Name resolution for default QEMU settings.
|
;; Name resolution for default QEMU settings.
|
||||||
|
|
Loading…
Reference in New Issue