all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: 45mg <45mg.writes@gmail.com>
To: 75145@debbugs.gnu.org
Cc: guix-devel@gnu.org, 45mg <45mg.writes@gmail.com>
Subject: [PATCH v2 1/1] services: network-manager: Add extra-configuration-files field.
Date: Thu,  9 Jan 2025 12:24:31 +0000	[thread overview]
Message-ID: <6c5c3ce265d159c862de73a77e985cf30a1f30a8.1736423822.git.45mg.writes@gmail.com> (raw)
In-Reply-To: <7743f403ebf1693fc386a397e9aed1975b43f900.1735323486.git.45mg.writes@gmail.com>

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(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index caebe3b03c..279fdb838b 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -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
 
diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
index 48a86b3694..4355158225 100644
--- a/gnu/services/networking.scm
+++ b/gnu/services/networking.scm
@@ -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)
-- 
2.47.1



      parent reply	other threads:[~2025-01-09 12:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-27 18:18 [bug#75145] [PATCH] services: NetworkManager: configuration-directory 45mg
2025-01-09 12:24 ` [PATCH v2 0/1] services: network-manager: Add extra-configuration-files field 45mg
2025-01-09 14:44   ` [bug#75145] " Arnaud Daby-Seesaram
2025-01-09 17:03     ` 45mg
2025-01-09 19:34   ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
2025-01-09 12:24 ` 45mg [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6c5c3ce265d159c862de73a77e985cf30a1f30a8.1736423822.git.45mg.writes@gmail.com \
    --to=45mg.writes@gmail.com \
    --cc=75145@debbugs.gnu.org \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.