Subject: [bug#76688] [PATCH] services: network-manager: Handle existing configuration directory.

From: Vagrant Cascadian <[email-masked]>
Date: Fri, 21 Mar 2025 23:38:49 -0700

On 2025-03-02, 45mg wrote:
> * gnu/services/networking.scm (network-manager-activation):
> Handle the case where /etc/NetworkManager/conf.d already exists.
>
> Change-Id: I7af4f4ad226eef28bd8667f0708525e77a6a50c8
> ---
> Follow-up to 0caba8f5db48c15a2c3edae37e816654246fa986.
>
> This issue only became apparent after pulling the above commit, changing my
> system config to use the new extra-files field, and reconfiguring /twice/. This
> sort of thing is why I now pull from a local fork and apply patches to it before
> submitting them ;)
>
>  gnu/services/networking.scm | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
> index 53840c2764..45efea330b 100644
> --- a/gnu/services/networking.scm
> +++ b/gnu/services/networking.scm
> @@ -1271,7 +1271,18 @@ (define (network-manager-activation config)
>                 '((mkdir-p "/var/lib/misc"))
>                 '())
>          #$@(if (pair? extra-configuration-files)  ;if non-empty
> -               `((symlink
> +               ;; If /etc/NetworkManager/conf.d is a symlink to a store file,
> +               ;; delete it.
> +               `((if (and (file-exists? "/etc/NetworkManager/conf.d")
> +                          (store-file-name?
> +                           (canonicalize-path "/etc/NetworkManager/conf.d")))
> +                     (delete-file-recursively
> +                      "/etc/NetworkManager/conf.d"))
> +                 ;; If it exists but is not a symlink to a store file, then
> +                 ;; this will fail with EEXIST; we leave this for the user to
> +                 ;; handle, since they probably created the directory
> +                 ;; themselves.
> +                 (symlink
>                    ,(file-union "network-manager-configuration-directory"
>                                 extra-configuration-files)
>                    "/etc/NetworkManager/conf.d"))

I hit this bug as well, and it actually caused a boot failure, had to
boot to an older generation to get things working again!

Have not yet tried the patch, though it looks like it should fix this
exact problem...

But... I am wondering if it wouldn't be more elegant to avoid using
/etc/NetworkManager/conf.d entirely, instead call NetworkManager
pointing the --config-dir arguments directly at the relevent store
directory, much like the configuration is passed using the --config
argument. That way there would be no leftovers between different system
generations...

Alternately, /run/NetworkManager/conf.d/*.conf should also be a possibly
better option than /etc/, although you still will have to clean up when
switching generations...

live well,
  vagrant