Adding to dhcpcd.conf

I have a machine runing version 23:05 that needed to request some additional options from the DHCP server. I couldn’t find any support for this using Network Manager when set to ‘internal’ so I swapped to ‘dhcpcd’ using networking.networkmanager.dhcp = "dhcpcd"; in my configuration.nix.

After doing this my machine was still getting an IP address via DHCP but it was no longer getting other basic DHCP options, such as DNS servers and domain details. There also didn’t seem to be a /etc/dhcpcd.conf file.

I tried to use the networking.dhcpcd.extraConfig option which is described as

Literal string to append to the config file generated for dhcpcd.

This didn’t appear to work and there was still no /etc/dhcpcd.conf file.

I changed to using environment.etc in configuration.nix to create the /etc/dhcpcd.conf file and supply both the domain server options and the additional ones I required and it all sprang to life.

My questions are;

A) if I misunderstood what the extraConfig option was supposed to do,
B) if I just didn’t use it or set it up properly or,
C) if I hit some snafu that I should tell someone about?

I am getting more confident with NixOS after nearly a year of using it but I still don’t feel confident enough that any errors are not me! :stuck_out_tongue: TIA

I suspect the issue here is that networking.dhcpcd module/options are meant to be used when using the NixOS scripted network backend (which uses dhcpcd) or using it completely standalone.

NetworkManager on the other hand is mostly configured non-declaratively outside of NixOS’ configration, so it doesn’t use the NixOS dhpcd module.

As it happens, NixOS provides some declarative knobs for NetworkManager and that’s where things (rightly so) become somewhat confusing. The option you configured (networking.networkmanager.dhcp) sets the DHCP backend used by NM, but telling NM what DHCP options to pass is probably part of (non-declarative) NM connection management through NM’s own abstractions.

For fully declarative connection management I recommend using networkd, but you’re probably using NM for good reasons (such as GUI WiFi configuration in your WM/DE). In that case, I recommend configuring DHCP options through NM as well.

Note NixOS does provide some global NM configuration options (see networking.networkmanager.connectionConfig and networking.networkmanager.extraConfig) but I don’t think that’s the right approach even though it looks like you could influence some DHCP related defaults…

Do you mean that the networking.dhcpcd.extraConfig should create and modify the /etc/dhcpcd.conf file normally and if I wasn’t using NetworkManager?

I have no bias towards how I create and modify the conf file, and using environment.etc worked just fine and still feels nicely declared and in the uniform place of *.nix. I just couldn’t determine if I was correctly interpreting the documentation, which seemed to suggest there was an established better-better way. :slight_smile:

NetworkManager, at least the GUI applet, makes some sense when it comes to consistency for users who might be using WiFi / VPNs and the like, but there are other machines too and I am actually intending to test not using NetworkManager so your pointer to networkd is very timely. Thank you.

Not quite, it uses pkgs.writeText to write the resulting config to the Nix store, which is then referenced in the systemd unit that spawns dhcpcd (by passing it as --config).

I guess it’s an okay solution given that we’ve established that networking.dhcpcd.extraConfig is of no use in your case.