Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initrd.network: support predictable interface names #47664

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion nixos/modules/system/boot/initrd-network.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ in

boot.initrd.kernelModules = [ "af_packet" ];

boot.initrd.extraUdevRulesCommands = mkIf config.networking.usePredictableInterfaceNames ''
Copy link
Member

Choose a reason for hiding this comment

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

Can you write release notes for that?

Copy link
Member

Choose a reason for hiding this comment

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

This aligns more with the semantics of the option, but requires users to migrate.

Copy link
Contributor

Choose a reason for hiding this comment

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

#39329 contains some draft release notes, feel free to copy/adapt.

cp -v ${pkgs.systemd}/lib/udev/rules.d/75-net-description.rules $out/
cp -v ${pkgs.path}/nixos/modules/services/hardware/80-net-setup-link.rules $out/
'';

boot.initrd.extraUtilsCommands = ''
copy_bin_and_libs ${pkgs.mkinitcpio-nfs-utils}/bin/ipconfig
'';
Expand Down Expand Up @@ -103,8 +108,12 @@ in
done

# Acquire a DHCP lease.
iface="${optionalString config.networking.usePredictableInterfaceNames
"--interface $(cd /sys/class/net; printf en*)"
}"
echo "acquiring IP address via DHCP..."
udhcpc --quit --now --script ${udhcpcScript} ${udhcpcArgs} && hasNetwork=1
# The interface can be overriden in `udhcpcArgs`
udhcpc --quit --now $iface --script ${udhcpcScript} ${udhcpcArgs} && hasNetwork=1
fi
''

Expand Down
2 changes: 2 additions & 0 deletions nixos/release-combined.nix
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ in rec {
(all nixos.tests.predictable-interface-names.unpredictable)
(all nixos.tests.predictable-interface-names.predictableNetworkd)
(all nixos.tests.predictable-interface-names.unpredictableNetworkd)
(all nixos.tests.predictable-interface-names.predictableInitrdNetwork)
(all nixos.tests.predictable-interface-names.unpredictableInitrdNetwork)
(all nixos.tests.printing)
(all nixos.tests.proxy)
(all nixos.tests.sddm.default)
Expand Down
31 changes: 26 additions & 5 deletions nixos/tests/predictable-interface-names.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@

let
inherit (import ../lib/testing.nix { inherit system; }) makeTest pkgs;
in pkgs.lib.listToAttrs (pkgs.lib.crossLists (predictable: withNetworkd: {
name = pkgs.lib.optionalString (!predictable) "un" + "predictable"
+ pkgs.lib.optionalString withNetworkd "Networkd";
inherit (pkgs) lib;
in lib.listToAttrs (map ({ predictable, withNetworkd ? false, withInitrdNetwork ? false }: rec {
name = lib.optionalString (!predictable) "un" + "predictable"
+ lib.optionalString withNetworkd "Networkd"
+ lib.optionalString withInitrdNetwork "InitrdNetwork";

value = makeTest {
name = "${if predictable then "" else "un"}predictableInterfaceNames${if withNetworkd then "-with-networkd" else ""}";
name = builtins.replaceStrings ["predictable"] ["predictableInterfaceNames"] name;
meta = {};

machine = { lib, ... }: {
imports = [ ../modules/profiles/minimal.nix ];
networking.usePredictableInterfaceNames = lib.mkForce predictable;
networking.useNetworkd = withNetworkd;
networking.dhcpcd.enable = !withNetworkd;
boot.initrd.network.enable = withInitrdNetwork;

# Ensure initrd DHCP works with predictable names.
# Use the same method as in tests/initrd-network.nix
boot.initrd.network.postCommands = lib.mkIf (predictable && !withNetworkd && withInitrdNetwork) ''
ip addr | grep 10.0.2.15 || exit 1
ping -c1 10.0.2.2 || exit 1
'';
};

testScript = ''
Expand All @@ -21,4 +33,13 @@ in pkgs.lib.listToAttrs (pkgs.lib.crossLists (predictable: withNetworkd: {
$machine->fail("ip link show ${if predictable then "eth0" else "ens3"}");
'';
};
}) [[true false] [true false]])
}) [
{ predictable = true; }
{ predictable = false; }

{ withNetworkd = true; predictable = true; }
{ withNetworkd = true; predictable = false; }

{ withInitrdNetwork = true; predictable = true; }
{ withInitrdNetwork = true; predictable = false; }
])