Skip to content

Commit

Permalink
nixos-generate-config: add useDHCP per interface
Browse files Browse the repository at this point in the history
This sets networking.useDHCP to false and for all interfaces found the
per-interface useDHCP to true. This replicates the current default
behaviour and prepares for the switch to networkd.
  • Loading branch information
globin committed Sep 24, 2019
1 parent e862dd6 commit 5ee383e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions nixos/modules/installer/tools/nixos-generate-config.pl
Expand Up @@ -563,6 +563,24 @@ sub multiLineList {
${\join "", (map { " $_\n" } (uniq @attrs))}}
EOF

sub generateNetworkingDhcpConfig {
my $config = <<EOF;
# The global useDHCP flag is deprecated, therefore explicitly set to false here.
# Per-interface useDHCP will be mandatory in the future, so this generated config
# replicates the default behaviour.
networking.useDHCP = false;
EOF

foreach my $path (glob "/sys/class/net/*") {
my $dev = basename($path);
if ($dev ne "lo") {
$config .= " networking.interfaces.$dev.useDHCP = true;\n";
}
}

return $config;
}


if ($showHardwareConfig) {
print STDOUT $hwConfig;
Expand Down Expand Up @@ -606,6 +624,8 @@ sub multiLineList {
EOF
}

my $networkingDhcpConfig = generateNetworkingDhcpConfig();

write_file($fn, <<EOF);
@configuration@
EOF
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/installer/tools/tools.nix
Expand Up @@ -96,6 +96,7 @@ in
# networking.hostName = "nixos"; # Define your hostname.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
$networkingDhcpConfig
# Configure network proxy if necessary
# networking.proxy.default = "http://user:password\@proxy:port/";
# networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
Expand Down

1 comment on commit 5ee383e

@nixos-discourse
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/networking-usenetworkd-and-usedhcp/4352/3

Please sign in to comment.