[bug#75145,v2,1/1] services: network-manager: Add extra-configuration-files field.
Commit Message
Allow users to specify additional configuration files for
NetworkManager. These files will be added to
`/etc/NetworkManager/conf.d` (NetworkManager's default configuration
directory location).
* gnu/services/networking.scm (<network-manager-configuration>)
[extra-configuration-files]: New field.
(network-manager-configuration-directory): New procedure.
(network-manager-activation): Honor the new field.
* doc/guix.texi (Networking Setup): Document the new field.
Change-Id: I07479958e4d0aa318328c666a9630b779230b300
---
doc/guix.texi | 21 +++++++++++++++++++++
gnu/services/networking.scm | 26 ++++++++++++++++++++++++--
2 files changed, 45 insertions(+), 2 deletions(-)
@@ -21455,6 +21455,27 @@ Networking Setup
(VPNs). An example of this is the @code{network-manager-openvpn}
package, which allows NetworkManager to manage VPNs @i{via} OpenVPN.
+@item @code{extra-configuration-files} (default: @code{'()})
+An alist of file names to file-like objects, representing configuration
+files which will be added to @file{/etc/NetworkManager/conf.d}.
+NetworkManager will read additional configuration from this directory.
+For details on configuration file precedence and the configuration file
+format, see the @command{NetworkManager.conf(5)} man page.
+
+For example, to add two files @file{001-basic.conf} and
+@file{002-unmanaged.conf}:
+
+@lisp
+(service network-manager-service-type
+ (network-manager-configuration
+ (extra-configuration-files
+ `(("existing-file" ,(local-file "001-basic.conf"))
+ ("constructed-file" ,(plain-file "002-unmanaged.conf"
+ "[keyfile]
+unmanaged-devices=interface-name:wlo1_ap
+"))))))
+@end lisp
+
@end table
@end deftp
@@ -1262,18 +1262,40 @@ (define-record-type* <network-manager-configuration>
(default '()))
(iwd? network-manager-configuration-iwd? ; TODO: deprecated field, remove.
(default #f)
- (sanitize warn-iwd?-field-deprecation)))
+ (sanitize warn-iwd?-field-deprecation))
+ (extra-configuration-files network-manager-configuration-extra-configuration-files
+ (default '()))) ;alist of file names to file-like objects
+
+(define (network-manager-configuration-directory extra-configuration-files)
+ "Return a directory containing EXTRA-CONFIGURATION-FILES."
+ (with-imported-modules (source-module-closure '((guix build utils)))
+ (computed-file
+ "network-manager-configuration-directory"
+ #~(begin
+ (use-modules (guix build utils))
+ (mkdir-p #$output)
+ (for-each (lambda (pair)
+ (let* ((filename (list-ref pair 0))
+ (file (list-ref pair 1))
+ (dest (string-append #$output "/" filename)))
+ (copy-file file dest)))
+ '#$extra-configuration-files)))))
(define (network-manager-activation config)
;; Activation gexp for NetworkManager
(match-record config <network-manager-configuration>
- (network-manager dns vpn-plugins)
+ (network-manager dns vpn-plugins extra-configuration-files)
#~(begin
(use-modules (guix build utils))
(mkdir-p "/etc/NetworkManager/system-connections")
#$@(if (equal? dns "dnsmasq")
;; create directory to store dnsmasq lease file
'((mkdir-p "/var/lib/misc"))
+ '())
+ #$@(if extra-configuration-files
+ `((symlink
+ ,(network-manager-configuration-directory extra-configuration-files)
+ "/etc/NetworkManager/conf.d"))
'()))))
(define (vpn-plugin-directory plugins)