1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (gnu services networking)
20 #:use-module (gnu services)
21 #:use-module (gnu packages admin)
22 #:use-module (gnu packages linux)
23 #:use-module (guix gexp)
24 #:use-module (guix monads)
25 #:export (static-networking-service))
29 ;;; Networking services.
33 (define* (static-networking-service interface ip
38 (net-tools net-tools))
39 "Return a service that starts INTERFACE with address IP. If GATEWAY is
40 true, it must be a string specifying the default network gateway."
42 ;; TODO: Eventually we should do this using Guile's networking procedures,
43 ;; like 'configure-qemu-networking' does, but the patch that does this is
44 ;; not yet in stock Guile.
45 (with-monad %store-monad
49 (string-append "Set up networking on the '" interface
50 "' interface using a static IP address."))
51 (provision '(networking))
53 ;; Return #t if successfully started.
54 (and (zero? (system* (string-append #$inetutils
56 #$interface #$ip "up"))
58 #~(zero? (system* (string-append #$net-tools
60 "add" "-net" "default"
63 #$(if (pair? name-servers)
64 #~(call-with-output-file "/etc/resolv.conf"
67 "# Generated by 'static-networking-service'.\n"
69 (for-each (lambda (server)
70 (format port "nameserver ~a~%"
75 ;; Return #f is successfully stopped.
76 (not (and (system* (string-append #$inetutils "/bin/ifconfig")
78 (system* (string-append #$net-tools "/sbin/route")
79 "del" "-net" "default")))))
82 ;;; networking.scm ends here