NetworkManager and configuration.nix: managing system-connections using "environment.etc" a good idea?

Hi all,

I found no good summary on this, so if this has been asked before please excuse my missing search skills…

I found that I can configure NetworkManager itself (NetworkManager.conf) via configuration.nix. But it seems I cannot handle the system connections in /etc/NetworkManager/system-connections/ directly.

I also found out that I can manage files in /etc/ using environment.etc (basically copying a file to the nix store and linking it to /etc/somewhere, IIUC).

Are there any experiences on doing this for the NetworkManager system-connection files? Does this simply not work (because $REASONS) or is this a valid approach?

I am happy for any feedback.

Thanks in advance,
Johannes

Please take a look at NixOS Search I recently wrote the module and also GitHub - Janik-Haag/nm2nix: Converts .nmconnection files into nix code which is probably what you are looking for

I do exactly that, but keep in mind that the files have to be copied in and not symlinked as they need to have mode “0600” in order for NM to accept them.

OK, how would I do that? I.e. how to copy and not symlink? environment.etc creates a link AFAIK.

Or, to paraphase the question:
Where can I find out, what options environment.etc accepts? Is the code in the Nixos git repository the only place to find this? Or is this another case of “missing search skills”? :slight_smile:

I’ll take a look, thanks! That feature is only in unstable yet, right?

Where can I find out, what options environment.etc accepts?

man configuration.nix is your friend as well as https://search.nixos.org/options.

But here is an example:

  {
    environment.etc."foo" = {
      mode = "0600";
      text = "hello hello";
    };
  }

1 Like

Thanks Peter and Janik! Peter’s snippet solves this for me (for now, as i am on 23.05, but will use networking.networkmanager.ensure-profiles.profiles once this is stable).

Yep currently it’s only in unstable but it will land in 23.11 in roughly a month

1 Like