system-configuration/modules/config/network.scm

network.scm

1
;;; Tyreunom's system administration and configuration tools.
2
;;;
3
;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu>
4
;;;
5
;;; This program is free software: you can redistribute it and/or modify
6
;;; it under the terms of the GNU General Public License as published by
7
;;; the Free Software Foundation, either version 3 of the License, or
8
;;; (at your option) any later version.
9
;;;
10
;;; This program is distributed in the hope that it will be useful,
11
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;;; GNU General Public License for more details.
14
;;;
15
;;; You should have received a copy of the GNU General Public License
16
;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
;;
19
;; Network configuration tools
20
;;
21
22
(define-module (config network)
23
  #:use-module (data dns)
24
  #:use-module (gnu packages linux)
25
  #:use-module (gnu services)
26
  #:use-module (gnu services shepherd)
27
  #:use-module (guix gexp)
28
  #:export (hermes-network-service))
29
30
(define (iproute2-shepherd-service config)
31
  (list (shepherd-service
32
	  (documentation "Run the iproute2 network service")
33
	  (provision '(networking))
34
	  (requirement '())
35
	  (start #~(lambda _
36
		     (let ((ip (string-append #$iproute "/sbin/ip"))
37
			   (dev "ens18"))
38
		       (invoke ip "a" "add" (string-append #$hermes-ip4 "/27") "dev" dev)
39
		       (invoke ip "l" "set" dev "up")
40
		       (invoke ip "-6" "a" "add" (string-append #$hermes-ip6 "/48")
41
			       "dev" dev)
42
		       (invoke ip "r" "add" "default" "via" "89.234.186.97" "dev" dev)
43
		       (invoke ip "-6" "r" "add" "default" "via"
44
			       "fe80::204:92:100:1" "dev" dev))))
45
	  (stop #~(lambda _
46
		    (display "Cannot stop iproute2 service.\n"))))))
47
48
(define iproute2-service-type
49
  (service-type (name 'static-networking)
50
		(extensions
51
		  (list
52
		    (service-extension shepherd-root-service-type
53
				       iproute2-shepherd-service)))
54
		(description "")))
55
56
(define hermes-network-service
57
  (service iproute2-service-type #t))
58