Network Manager can't import openvpn

I’m new in NixOS. I want to set up openvpn with network manager. Here is part of my config:

{ pkgs, ... }:
{
  networking.networkmanager = {
    enable = true;
    plugins = with pkgs; [
      networkmanager-openvpn
      networkmanager-strongswan
      networkmanager-openconnect
    ];
  };
}

After sudo nixos-rebuild boot --flake .#my-device and reboot, I’m trying to import openvpn file:

nmcli connection import type openvpn file ./lab.ovpn

But it shows:

Error: failed to load VPN plugin: unknown VPN plugin "org.freedesktop.NetworkManager.openvpn".

I’m wondering why this happened and how I can set up openvpn correctly.

Is your user in the networkmanager group? Usually, this is required.

Of course the user is in networkmanager group:

> id zeauw
uid=1000(zeauw) gid=986(zeauw) groups=986(zeauw),1(wheel),57(networkmanager),67(libvirtd),301(qemu-libvirtd),302(kvm)

I also tried import it with sudo. But it still failed.

And I can confirm that the plugins were installed well:

> ls /run/current-system/sw/lib/NetworkManager/VPN/
nm-openconnect-service.name  nm-openvpn-service.name  nm-strongswan-service.name

I’ve solved the problem. The actual problem is I configured the following preservation:

# NetworkManager
"/etc/NetworkManager"
"/var/lib/NetworkManager"

But it prevents the system creating /etc/NetworkManager/VPN due to this will be created before persistent volume was mounted. So I modify the preservation configuration:

# NetworkManager
"/etc/NetworkManager/system-connections"
"/var/lib/NetworkManager"

And it works well now.