;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2016, 2018, 2020 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2016 John Darrington <jmd@gnu.org>
;;; Copyright © 2019 Sou Bunnbu <iyzsong@member.fsf.org>
;;; Copyright © 2019 Alex Griffin <a@ajgrf.com>
;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
+;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
+;;; Copyright © 2021 Christopher Lemmer Webber <cwebber@dustycloud.org>
+;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
;;;
;;; This file is part of GNU Guix.
;;;
#:use-module (gnu packages admin)
#:use-module (gnu packages base)
#:use-module (gnu packages bash)
+ #:use-module (gnu packages cluster)
#:use-module (gnu packages connman)
#:use-module (gnu packages freedesktop)
#:use-module (gnu packages linux)
#:use-module (gnu packages ntp)
#:use-module (gnu packages wicd)
#:use-module (gnu packages gnome)
+ #:use-module (gnu packages ipfs)
+ #:use-module (gnu build linux-container)
#:use-module (guix gexp)
#:use-module (guix records)
#:use-module (guix modules)
yggdrasil-configuration-log-level
yggdrasil-configuration-log-to
yggdrasil-configuration-json-config
- yggdrasil-configuration-package))
+ yggdrasil-configuration-package
+
+ ipfs-service-type
+ ipfs-configuration
+ ipfs-configuration?
+ ipfs-configuration-package
+ ipfs-configuration-gateway
+ ipfs-configuration-api
+
+ keepalived-configuration
+ keepalived-configuration?
+ keepalived-service-type))
;;; Commentary:
;;;
(and (zero? (cdr (waitpid pid)))
(read-pid-file #$pid-file)))))
(stop #~(make-kill-destructor))))
- isc-dhcp))
+ isc-dhcp
+ (description "Run @command{dhcp}, a Dynamic Host Configuration
+Protocol (DHCP) client, on all the non-loopback network interfaces.")))
(define-deprecated (dhcp-client-service #:key (dhcp isc-dhcp))
dhcp-client-service-type
(constraint-from openntpd-constraint-from
(default '()))
(constraints-from openntpd-constraints-from
- (default '()))
- (allow-large-adjustment? openntpd-allow-large-adjustment?
- (default #f))) ; upstream default
+ (default '())))
(define (openntpd-configuration->string config)
"\n"))) ;add a trailing newline
(define (openntpd-shepherd-service config)
- (let ((openntpd (openntpd-configuration-openntpd config))
- (allow-large-adjustment? (openntpd-allow-large-adjustment? config)))
+ (let ((openntpd (openntpd-configuration-openntpd config)))
(define ntpd.conf
(plain-file "ntpd.conf" (openntpd-configuration->string config)))
(start #~(make-forkexec-constructor
(list (string-append #$openntpd "/sbin/ntpd")
"-f" #$ntpd.conf
- "-d" ;; don't daemonize
- #$@(if allow-large-adjustment?
- '("-s")
- '()))
+ "-d") ;; don't daemonize
;; When ntpd is daemonized it repeatedly tries to respawn
;; while running, leading shepherd to disable it. To
;; prevent spamming stderr, redirect output to logfile.
(hidden-services tor-configuration-hidden-services
(default '()))
(socks-socket-type tor-configuration-socks-socket-type ; 'tcp or 'unix
- (default 'tcp)))
+ (default 'tcp))
+ (control-socket? tor-control-socket-path
+ (default #f)))
(define %tor-accounts
;; User account and groups for Tor.
(define (tor-configuration->torrc config)
"Return a 'torrc' file for CONFIG."
(match config
- (($ <tor-configuration> tor config-file services socks-socket-type)
+ (($ <tor-configuration> tor config-file services
+ socks-socket-type control-socket?)
(computed-file
"torrc"
(with-imported-modules '((guix build utils))
(display "\
SocksPort unix:/var/run/tor/socks-sock
UnixSocksGroupWritable 1\n" port))
+ (when #$control-socket?
+ (display "\
+ControlSocket unix:/var/run/tor/control-sock GroupWritable RelaxDirModeCheck
+ControlSocketsGroupWritable 1\n"
+ port))
(for-each (match-lambda
((service (ports hosts) ...)
(service-extension profile-service-type
(compose list yggdrasil-configuration-package))))))
+\f
+;;;
+;;; IPFS
+;;;
+
+(define-record-type* <ipfs-configuration>
+ ipfs-configuration
+ make-ipfs-configuration
+ ipfs-configuration?
+ (package ipfs-configuration-package
+ (default go-ipfs))
+ (gateway ipfs-configuration-gateway
+ (default "/ip4/127.0.0.1/tcp/8082"))
+ (api ipfs-configuration-api
+ (default "/ip4/127.0.0.1/tcp/5001")))
+
+(define %ipfs-home "/var/lib/ipfs")
+
+(define %ipfs-accounts
+ (list (user-account
+ (name "ipfs")
+ (group "ipfs")
+ (system? #t)
+ (comment "IPFS daemon user")
+ (home-directory "/var/lib/ipfs")
+ (shell (file-append shadow "/sbin/nologin")))
+ (user-group
+ (name "ipfs")
+ (system? #t))))
+
+(define (ipfs-binary config)
+ (file-append (ipfs-configuration-package config) "/bin/ipfs"))
+
+(define %ipfs-home-mapping
+ #~(file-system-mapping
+ (source #$%ipfs-home)
+ (target #$%ipfs-home)
+ (writable? #t)))
+
+(define %ipfs-environment
+ #~(list #$(string-append "HOME=" %ipfs-home)))
+
+(define (ipfs-shepherd-service config)
+ "Return a <shepherd-service> for IPFS with CONFIG."
+ (define ipfs-daemon-command
+ #~(list #$(ipfs-binary config) "daemon"))
+ (list
+ (with-imported-modules (source-module-closure
+ '((gnu build shepherd)
+ (gnu system file-systems)))
+ (shepherd-service
+ (provision '(ipfs))
+ ;; While IPFS is most useful when the machine is connected
+ ;; to the network, only loopback is required for starting
+ ;; the service.
+ (requirement '(loopback))
+ (documentation "Connect to the IPFS network")
+ (modules '((gnu build shepherd)
+ (gnu system file-systems)))
+ (start #~(make-forkexec-constructor/container
+ #$ipfs-daemon-command
+ #:namespaces '#$(fold delq %namespaces '(user net))
+ #:mappings (list #$%ipfs-home-mapping)
+ #:log-file "/var/log/ipfs.log"
+ #:user "ipfs"
+ #:group "ipfs"
+ #:environment-variables #$%ipfs-environment))
+ (stop #~(make-kill-destructor))))))
+
+(define (%ipfs-activation config)
+ "Return an activation gexp for IPFS with CONFIG"
+ (define (ipfs-config-command setting value)
+ #~(#$(ipfs-binary config) "config" #$setting #$value))
+ (define (set-config!-gexp setting value)
+ #~(system* #$@(ipfs-config-command setting value)))
+ (define settings
+ `(("Addresses.API" ,(ipfs-configuration-api config))
+ ("Addresses.Gateway" ,(ipfs-configuration-gateway config))))
+ (define inner-gexp
+ #~(begin
+ (umask #o077)
+ ;; Create $HOME/.ipfs structure
+ (system* #$(ipfs-binary config) "init")
+ ;; Apply settings
+ #$@(map (cute apply set-config!-gexp <>) settings)))
+ (define inner-script
+ (program-file "ipfs-activation-inner" inner-gexp))
+ ;; Run ipfs init and ipfs config from a container,
+ ;; in case the IPFS daemon was compromised at some point
+ ;; and ~/.ipfs is now a symlink to somewhere outside
+ ;; %ipfs-home.
+ (define container-gexp
+ (with-extensions (list shepherd)
+ (with-imported-modules (source-module-closure
+ '((gnu build shepherd)
+ (gnu system file-systems)))
+ #~(begin
+ (use-modules (gnu build shepherd)
+ (gnu system file-systems))
+ (let* ((constructor
+ (make-forkexec-constructor/container
+ (list #$inner-script)
+ #:namespaces '#$(fold delq %namespaces '(user))
+ #:mappings (list #$%ipfs-home-mapping)
+ #:user "ipfs"
+ #:group "ipfs"
+ #:environment-variables #$%ipfs-environment))
+ (pid (constructor)))
+ (waitpid pid))))))
+ ;; The activation may happen from the initrd, which uses
+ ;; a statically-linked guile, while the guix container
+ ;; procedures require a working dynamic-link.
+ (define container-script
+ (program-file "ipfs-activation-container" container-gexp))
+ #~(system* #$container-script))
+
+(define ipfs-service-type
+ (service-type
+ (name 'ipfs)
+ (extensions
+ (list (service-extension account-service-type
+ (const %ipfs-accounts))
+ (service-extension activation-service-type
+ %ipfs-activation)
+ (service-extension shepherd-root-service-type
+ ipfs-shepherd-service)))
+ (default-value (ipfs-configuration))
+ (description
+ "Run @command{ipfs daemon}, the reference implementation
+of the IPFS p2p storage network.")))
+
+\f
+;;;
+;;; Keepalived
+;;;
+
+(define-record-type* <keepalived-configuration>
+ keepalived-configuration make-keepalived-configuration
+ keepalived-configuration?
+ (keepalived keepalived-configuration-keepalived ;<package>
+ (default keepalived))
+ (config-file keepalived-configuration-config-file ;file-like
+ (default #f)))
+
+(define keepalived-shepherd-service
+ (match-lambda
+ (($ <keepalived-configuration> keepalived config-file)
+ (list
+ (shepherd-service
+ (provision '(keepalived))
+ (documentation "Run keepalived.")
+ (requirement '(loopback))
+ (start #~(make-forkexec-constructor
+ (list (string-append #$keepalived "/sbin/keepalived")
+ "--dont-fork" "--log-console" "--log-detail"
+ "--pid=/var/run/keepalived.pid"
+ (string-append "--use-file=" #$config-file))
+ #:pid-file "/var/run/keepalived.pid"
+ #:log-file "/var/log/keepalived.log"))
+ (respawn? #f)
+ (stop #~(make-kill-destructor)))))))
+
+(define keepalived-service-type
+ (service-type (name 'keepalived)
+ (extensions (list (service-extension shepherd-root-service-type
+ keepalived-shepherd-service)))
+ (description
+ "Run @uref{https://www.keepalived.org/, Keepalived}
+routing software.")))
+
;;; networking.scm ends here