Putting wifi ssid in networkmanager secrets

I have already put wifi password in secrets with networking.networkmanager.ensureProfiles.secrets.entries. But if I do the same thing for wifi ssid, it doesn’t seem to work.

I got this warning keyfile: load: "/var/run/NetworkManager/system-connections/home-wifi.nmconnection": failed to load connection: invalid connection: 802-11-wireless.ssid: property is missing from NetworkManager.service.

Does anyone have any idea?

Here is my config

networking.networkmanager = {
  enable = true;

  ensureProfiles.profiles = {
    home-wifi = {
      connection = {
        id = "home-wifi";
        type = "wifi";
        uuid = "xxxx-xxxx-xxxx-xxxx-xxxx";
      };

      wifi = {
        mode = "infrastructure";
      };

      wifi-security = {
        auth-alg = "open";
        key-mgmt = "wpa-psk";
      };

      ipv4 = {
        method = "auto";
      };

      ipv6 = {
        addr-gen-mode = "default";
        method = "auto";
      };

      proxy = {};
    };
  };

  ensureProfiles.secrets.entries = [
    {
      matchId = "home-wifi";
      matchType = "802-11-wireless";
      matchSetting = "802-11-wireless-security";
      key = "psk";
      file = config.sops.secrets.wifi-password.path;
    }
    {
      matchId = "home-wifi";
      matchType = "802-11-wireless";
      matchSetting = "802-11-wireless";
      key = "ssid";
      file = config.sops.secrets.wifi-name.path;
    }
  ];
};

Could you try changing it to

{
      matchId = "home-wifi";
      matchType = "wifi"; # connection.type
      matchSetting = "wifi-security";
      key = "psk";
      file = config.sops.secrets.wifi-password.path;
    }
    {
      matchId = "home-wifi";
      matchType = "wifi";
      matchSetting = "wifi";
      key = "ssid";
      file = config.sops.secrets.wifi-name.path;
    }

?

I still use environmentFiles and my config looks like this

{ config, ... }:
{
  sops = {
    secrets =
      let
        secretConf = {
          sopsFile = ../common-secrets/wifi.yaml;
        };
      in
      {
        "wifi/home/ssid" = secretConf;
        "wifi/home/bssid" = secretConf;
        "wifi/home/password" = secretConf;
      };
    templates."wifi.env".content = ''
      HOME_SSID="${config.sops.placeholder."wifi/home/ssid"}"
      HOME_BSSID="${config.sops.placeholder."wifi/home/bssid"}"
      HOME_PASSWORD="${config.sops.placeholder."wifi/home/password"}"
    '';
  };
  networking.networkmanager.ensureProfiles = {
    environmentFiles = [ config.sops.templates."wifi.env".path ];
    profiles = {
      "Home Wifi" = {
        connection = {
          autoconnect-priority = "98";
          id = "Greitas 5GHz";
          timestamp = "1770138378";
          type = "wifi";
          uuid = "af842002-436e-4893-9314-ed7d6e0bae2f";
        };
        ipv4 = {
          address1 = "192.168.1.184/24";
          dns = "192.168.1.150;9.9.9.9;";
          dns-search = "lan;";
          gateway = "192.168.1.254";
          method = "manual";
          route1 = "10.6.0.6/32,192.168.1.150";
        };
        ipv6 = {
          addr-gen-mode = "stable-privacy";
          method = "auto";
        };
        proxy = { };
        wifi = {
          band = "a";
          bssid = "$HOME_BSSID";
          mac-address = "C8:94:02:DD:EE:B3";
          mode = "infrastructure";
          ssid = "$HOME_SSID";
        };
        wifi-security = {
          key-mgmt = "wpa-psk";
          psk = "$HOME_PASSWORD";
        };
      };
    };
  };
}

Could you try changing it to

{
      matchId = "home-wifi";
      matchType = "wifi"; # connection.type
      matchSetting = "wifi-security";
      key = "psk";
      file = config.sops.secrets.wifi-password.path;
    }
    {
      matchId = "home-wifi";
      matchType = "wifi";
      matchSetting = "wifi";
      key = "ssid";
      file = config.sops.secrets.wifi-name.path;
    }

?

Thanks for your reply. Unfortunately, this doesn’t work either with the same warning.

I’ve changed my config to

{ config, ... }:
{
  sops = {
    secrets =
      let
        secretConf = {
          sopsFile = ../common-secrets/wifi.yaml;
        };
      in
      {
        "wifi/home/ssid" = secretConf;
        "wifi/home/bssid" = secretConf;
        "wifi/home/password" = secretConf;
      };
  };
  networking.networkmanager.ensureProfiles = {
    secrets.entries =
      let
        matchType = "wifi";
        matchUuid = "af842002-436e-4893-9314-ed7d6e0bae2f";
      in
      [
        {
          inherit matchUuid matchType;
          file = config.sops.secrets."wifi/home/ssid".path;
          key = "ssid";
          matchSetting = "wifi";
        }
        {
          inherit matchUuid matchType;
          file = config.sops.secrets."wifi/home/bssid".path;
          key = "bssid";
          matchSetting = "wifi";
        }
        {
          inherit matchUuid matchType;
          file = config.sops.secrets."wifi/home/password".path;
          key = "psk";
          matchSetting = "wifi-security";
        }
      ];
    profiles = {
      "Home Wifi" = {
        connection = {
          autoconnect-priority = "98";
          id = "Greitas 5GHz";
          timestamp = "1770138378";
          type = "wifi";
          uuid = "af842002-436e-4893-9314-ed7d6e0bae2f";
        };
        ipv4 = {
          address1 = "192.168.1.184/24";
          dns = "192.168.1.150;9.9.9.9;";
          dns-search = "lan;";
          gateway = "192.168.1.254";
          method = "manual";
          route1 = "10.6.0.6/32,192.168.1.150";
        };
        ipv6 = {
          addr-gen-mode = "stable-privacy";
          method = "auto";
        };
        proxy = { };
        wifi = {
          band = "a";
          mac-address = "C8:94:02:DD:EE:B3";
          mode = "infrastructure";
        };
        wifi-security = {
          key-mgmt = "wpa-psk";
        };
      };
    };
  };
}

The connection works but I also get similar warnings

spal. 09 17:39:43 adomo-t14 systemd[1]: Starting Network Manager...
spal. 09 17:39:43 adomo-t14 NetworkManager[54744]: <warn>  [1791556783.5793] keyfile: load: "/var/run/NetworkManager/system-connections/Home Wifi.nmconnection": failed to load connection: invalid connection: 802-11-wireless.ssid: property is missing
spal. 09 17:39:43 adomo-t14 systemd[1]: Started Network Manager.
spal. 09 17:39:43 adomo-t14 NetworkManager[54744]: <warn>  [1791556783.6922] device (0C:02:BD:18:2C:15): error setting IPv4 forwarding to '1': Resource temporarily unavailable
spal. 09 17:39:43 adomo-t14 NetworkManager[54744]: <warn>  [1791556783.7312] device (p2p-dev-wlp3s0): error setting IPv4 forwarding to '1': Success
spal. 09 17:47:49 adomo-t14 NetworkManager[54744]: <warn>  [1791557269.8173] keyfile: load: "/var/run/NetworkManager/system-connections/Home Wifi.nmconnection": failed to load connection: invalid connection: 802-11-wireless.ssid: property is missing

I just want to confirm that you have Internet connection despite the warning?

Yes. I even tried to restart NetworkManager. But maybe there is some state remaining from the previous config.

I see. I think I have to further investigate into it. Thanks again!