From b714395a39fffc60f75408504a23dfe27ad13fc2 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 13 Sep 2017 16:01:36 +0200 Subject: services: Add a description and location for each service type. * gnu/services.scm ()[description, location]: New field. * doc/guix.texi (Service Types and Services): Document 'description'. --- gnu/services.scm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'gnu/services.scm') diff --git a/gnu/services.scm b/gnu/services.scm index 8ef1ae7c77..83a163b766 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -49,6 +49,9 @@ service-type-compose service-type-extend service-type-default-value + service-type-description + service-type-location + service service? @@ -145,7 +148,15 @@ ;; Optional default value for instances of this type. (default-value service-type-default-value ;Any - (default &no-default-value))) + (default &no-default-value)) + + ;; Meta-data. + (description service-type-description ;string + (default #f)) + (location service-type-location ; + (default (and=> (current-source-location) + source-properties->location)) + (innate))) (define (write-service-type type port) (format port "#" -- cgit 1.4.1 From 0c0c1b21d959a9761a247309428c64a92c599fb3 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 13 Sep 2017 16:02:22 +0200 Subject: services: Add 'fold-service-types'. * gnu/services.scm (%distro-root-directory, %service-type-path): New variables. (fold-service-types): New procedure. --- gnu/services.scm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'gnu/services.scm') diff --git a/gnu/services.scm b/gnu/services.scm index 83a163b766..2ebd701a59 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -23,6 +23,7 @@ #:use-module (guix store) #:use-module (guix records) #:use-module (guix profiles) + #:use-module (guix discovery) #:use-module (guix sets) #:use-module (guix ui) #:use-module ((guix utils) #:select (source-properties->location)) @@ -52,6 +53,8 @@ service-type-description service-type-location + %service-type-path + fold-service-types service service? @@ -165,6 +168,27 @@ (set-record-type-printer! write-service-type) +(define %distro-root-directory + ;; Absolute file name of the module hierarchy. + (dirname (search-path %load-path "guix.scm"))) + +(define %service-type-path + ;; Search path for service types. + (make-parameter `((,%distro-root-directory . "gnu/services") + (,%distro-root-directory . "gnu/system")))) + +(define* (fold-service-types proc seed + #:optional + (modules (all-modules (%service-type-path)))) + "For each service type exported by one of MODULES, call (PROC RESULT). SEED +is used as the initial value of RESULT." + (fold-module-public-variables (lambda (object result) + (if (service-type? object) + (proc object result) + result)) + '() + modules)) + ;; Services of a given type. (define-record-type (make-service type value) -- cgit 1.4.1 From 94d2a25091dc4bcaec319c46da96d588e3e63476 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 22 Sep 2017 00:00:41 +0200 Subject: services: network-manager: Add support for VPN plug-ins. * gnu/services.scm (directory-union): Export. * gnu/services/networking.scm ()[vpn-plugins]: New field. (vpn-plugin-directory, network-manager-environment): New procedure. (network-manager-shepherd-service): Pass #:environment-variables to 'make-forkexec-constructor'. (network-manager-service-type): Add SESSION-ENVIRONMENT-SERVICE-TYPE extension. * doc/guix.texi (Networking Services): Document it. --- doc/guix.texi | 5 +++++ gnu/services.scm | 3 ++- gnu/services/networking.scm | 54 ++++++++++++++++++++++++++++++--------------- 3 files changed, 43 insertions(+), 19 deletions(-) (limited to 'gnu/services.scm') diff --git a/doc/guix.texi b/doc/guix.texi index 601cf51b37..0369a150f7 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -10125,6 +10125,11 @@ then update @code{resolv.conf} to point to the local nameserver. NetworkManager will not modify @code{resolv.conf}. @end table +@item @code{vpn-plugins} (default: @code{'()}) +This is the list of available plugins for virtual private networks +(VPNs). An example of this is the @code{network-manager-openvpn} +package, which allows NetworkManager to manage VPNs @i{via} OpenVPN. + @end table @end deftp diff --git a/gnu/services.scm b/gnu/services.scm index 2ebd701a59..329b7b1513 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -97,7 +97,8 @@ %activation-service etc-service - file-union)) ;XXX: for lack of a better place + file-union ;XXX: for lack of a better place + directory-union)) ;;; Comment: ;;; diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index fbedaa5b35..42b96b417e 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -25,6 +25,7 @@ #:use-module (gnu services) #:use-module (gnu services shepherd) #:use-module (gnu services dbus) + #:use-module (gnu services base) #:use-module (gnu system shadow) #:use-module (gnu system pam) #:use-module (gnu packages admin) @@ -909,7 +910,9 @@ and @command{wicd-curses} user interfaces." (network-manager network-manager-configuration-network-manager (default network-manager)) (dns network-manager-configuration-dns - (default "default"))) + (default "default")) + (vpn-plugins network-manager-vpn-plugins ;list of + (default '()))) (define %network-manager-activation ;; Activation gexp for NetworkManager. @@ -917,25 +920,38 @@ and @command{wicd-curses} user interfaces." (use-modules (guix build utils)) (mkdir-p "/etc/NetworkManager/system-connections"))) +(define (vpn-plugin-directory plugins) + "Return a directory containing PLUGINS, the NM VPN plugins." + (directory-union "network-manager-vpn-plugins" plugins)) + +(define network-manager-environment + (match-lambda + (($ network-manager dns vpn-plugins) + ;; Define this variable in the global environment such that + ;; "nmcli connection import type openvpn file foo.ovpn" works. + `(("NM_VPN_PLUGIN_DIR" + . ,(file-append (vpn-plugin-directory vpn-plugins) + "/lib/NetworkManager/VPN")))))) + (define network-manager-shepherd-service (match-lambda - (($ network-manager dns) - (let - ((conf (plain-file "NetworkManager.conf" - (string-append " -[main] -dns=" dns " -")))) - (list (shepherd-service - (documentation "Run the NetworkManager.") - (provision '(networking)) - (requirement '(user-processes dbus-system wpa-supplicant loopback)) - (start #~(make-forkexec-constructor - (list (string-append #$network-manager - "/sbin/NetworkManager") - (string-append "--config=" #$conf) - "--no-daemon"))) - (stop #~(make-kill-destructor)))))))) + (($ network-manager dns vpn-plugins) + (let ((conf (plain-file "NetworkManager.conf" + (string-append "[main]\ndns=" dns "\n"))) + (vpn (vpn-plugin-directory vpn-plugins))) + (list (shepherd-service + (documentation "Run the NetworkManager.") + (provision '(networking)) + (requirement '(user-processes dbus-system wpa-supplicant loopback)) + (start #~(make-forkexec-constructor + (list (string-append #$network-manager + "/sbin/NetworkManager") + (string-append "--config=" #$conf) + "--no-daemon") + #:environment-variables + (list (string-append "NM_VPN_PLUGIN_DIR=" #$vpn + "/lib/NetworkManager/VPN")))) + (stop #~(make-kill-destructor)))))))) (define network-manager-service-type (let @@ -953,6 +969,8 @@ dns=" dns " (service-extension polkit-service-type config->package) (service-extension activation-service-type (const %network-manager-activation)) + (service-extension session-environment-service-type + network-manager-environment) ;; Add network-manager to the system profile. (service-extension profile-service-type config->package))) (default-value (network-manager-configuration)) -- cgit 1.4.1