Skip to content

Commit

Permalink
nixos/dhcpcd: fix updating resolv.conf when using systemd-resolved
Browse files Browse the repository at this point in the history
Fix the regression between NixOS 24.05 and 24.11 where using dhcpcd
(e.g. networking.useDHCP) and systemd-resolved
(services.resolved.enable) result in no "search" entry getting added to
/etc/resolv.conf, and dhcpcd logging the following error:

  $ systemctl status dhcpcd
  [...] dhcpcd[2896]: Failed to set DNS configuration: Interactive authentication required.

Fix it by adding a polkit rule that gives the required permissions to
the 'dhcpcd' user to manipulate resolved. The rule was made by using
polkit logging and allowing each action.id until the above error went
away, and /etc/resolv.conf got the correct search entry.
  • Loading branch information
bjornfor committed Jan 4, 2025
1 parent a278711 commit 452b00c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions nixos/modules/services/networking/dhcpcd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,18 @@ in
/run/current-system/systemd/bin/systemctl reload dhcpcd.service
'';

security.polkit.extraConfig = lib.mkIf config.services.resolved.enable ''
polkit.addRule(function(action, subject) {
if (action.id == 'org.freedesktop.resolve1.revert' ||
action.id == 'org.freedesktop.resolve1.set-dns-servers' ||
action.id == 'org.freedesktop.resolve1.set-domains') {
if (subject.user == '${config.systemd.services.dhcpcd.serviceConfig.User}') {
return polkit.Result.YES;
}
}
});
'';

};

}

0 comments on commit 452b00c

Please sign in to comment.