services: Add 'dhcp-client-service'.
* gnu/services/networking.scm (dhcp-client-service): New procedure. * doc/guix.texi (Networking Services): Document it.
This commit is contained in:
parent
4d54785c69
commit
a023cca8d9
|
@ -3449,6 +3449,12 @@ Run @var{udev}, which populates the @file{/dev} directory dynamically.
|
||||||
The @code{(gnu system networking)} module provides services to configure
|
The @code{(gnu system networking)} module provides services to configure
|
||||||
the network interface.
|
the network interface.
|
||||||
|
|
||||||
|
@cindex DHCP, networking service
|
||||||
|
@deffn {Monadic Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
|
||||||
|
Return a service that runs @var{dhcp}, a Dynamic Host Configuration
|
||||||
|
Protocol (DHCP) client, on all the non-loopback network interfaces.
|
||||||
|
@end deffn
|
||||||
|
|
||||||
@deffn {Monadic Procedure} static-networking-service @var{interface} @var{ip} @
|
@deffn {Monadic Procedure} static-networking-service @var{interface} @var{ip} @
|
||||||
[#:gateway #f] [#:name-services @code{'()}]
|
[#:gateway #f] [#:name-services @code{'()}]
|
||||||
Return a service that starts @var{interface} with address @var{ip}. If
|
Return a service that starts @var{interface} with address @var{ip}. If
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#:use-module (guix gexp)
|
#:use-module (guix gexp)
|
||||||
#:use-module (guix monads)
|
#:use-module (guix monads)
|
||||||
#:export (static-networking-service
|
#:export (static-networking-service
|
||||||
|
dhcp-client-service
|
||||||
tor-service))
|
tor-service))
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
@ -94,6 +95,38 @@ gateway."
|
||||||
#t)))))
|
#t)))))
|
||||||
(respawn? #f)))))
|
(respawn? #f)))))
|
||||||
|
|
||||||
|
(define* (dhcp-client-service #:key (dhcp isc-dhcp))
|
||||||
|
"Return a service that runs @var{dhcp}, a Dynamic Host Configuration
|
||||||
|
Protocol (DHCP) client, on all the non-loopback network interfaces."
|
||||||
|
|
||||||
|
(define dhclient
|
||||||
|
#~(string-append #$dhcp "/sbin/dhclient"))
|
||||||
|
|
||||||
|
(define pid-file
|
||||||
|
"/var/run/dhclient.pid")
|
||||||
|
|
||||||
|
(with-monad %store-monad
|
||||||
|
(return (service
|
||||||
|
(documentation
|
||||||
|
"Set up networking via DHCP.")
|
||||||
|
(requirement '(user-processes udev))
|
||||||
|
(provision '(networking))
|
||||||
|
(start #~(lambda _
|
||||||
|
;; When invoked without any arguments, 'dhclient'
|
||||||
|
;; discovers all non-loopback interfaces *that are
|
||||||
|
;; up*. However, the relevant interfaces are
|
||||||
|
;; typically down at this point. Thus we perform our
|
||||||
|
;; own interface discovery here.
|
||||||
|
(let* ((valid? (negate loopback-network-interface?))
|
||||||
|
(ifaces (filter valid?
|
||||||
|
(all-network-interfaces)))
|
||||||
|
(pid (fork+exec-command
|
||||||
|
(cons* #$dhclient "-pf" #$pid-file
|
||||||
|
ifaces))))
|
||||||
|
(and (zero? (cdr (waitpid pid)))
|
||||||
|
(call-with-input-file #$pid-file read)))))
|
||||||
|
(stop #~(make-kill-destructor))))))
|
||||||
|
|
||||||
(define* (tor-service #:key (tor tor))
|
(define* (tor-service #:key (tor tor))
|
||||||
"Return a service to run the @uref{https://torproject.org,Tor} daemon.
|
"Return a service to run the @uref{https://torproject.org,Tor} daemon.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue