Paste number 339545: | use-modules in #~(lamda gexp seems to cause "definition in expression context not allowed" |
Pasted by: | Apteryx |
When: | 5 years, 5 months ago |
Share: | Tweet this! | http://paste.lisp.org/+79ZT |
Channel: | None |
Paste contents: |
;;; This fails when running the service with message:
;;; definition in expression context , where definitions
;;; are not allowed, in form
;;; (define all-interfaces-minus-loopback
;;; (remove loopback-network-interface? (all-network-interface-names)))
(define dhcp-client-service-type
(shepherd-service-type
'dhcp-client
(lambda (config)
(shepherd-service
(documentation "Set up networking via DHCP.")
(provision '(networking))
(start
(with-imported-modules '((srfi srfi-1) (ice-9 regex))
#~(lambda _
;; When invoked without any interface argument, '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.
(use-modules (srfi srfi-1)
(ice-9 regex))
(define all-interfaces-minus-loopback
(remove loopback-network-interface? (all-network-interface-names)))
;; Select the interfaces based on the interfaces field of the
;; configuration record.
(define selected-interfaces
(delete-duplicates
(map (lambda (iface-pattern)
(filter (lambda (iface)
(string-match iface-pattern iface))
all-interfaces-minus-loop-loopback))
#$(dhcp-client-configuration-interfaces config))))
;; Validate that at least one interface was selected.
(when all-interfaces-minus-loopback
(unless selected-interfaces
(error "No interface selected! Available interfaces: "
all-interfaces-minus-loopback
" Interface regexps: "
#$(dhcp-client-configuration-interfaces config))))
;; Make sure the selected interfaces are up so that 'dhclient' can
;; actually send/receive over them.
(for-each set-network-interface-up selected-interfaces)
(let ((pid (fork+exec-command
(append
(quote
#$(dhcp-client-configuration->dhclient-command config))
selected-interfaces))))
(zero? (cdr (waitpid pid)))))))
(stop #~(make-kill-destructor))))))
This paste has no annotations.