diff options
author | Will Fancher <elvishjerricco@gmail.com> | 2023-10-03 23:37:03 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-03 23:37:03 -0400 |
commit | 37601de942a3abf5c8b501b829295bfb1c4a184c (patch) | |
tree | 7a46cdf56b53e92e6fac6b08da40601306b0ce7c /nixos/modules/system/boot/networkd.nix | |
parent | d1c9180c6d1f8fce9469436f48c1cb8180d7087d (diff) | |
parent | e23693e12944091b2cc27675f4d14b77f805bfea (diff) | |
download | nixpkgs-37601de942a3abf5c8b501b829295bfb1c4a184c.tar nixpkgs-37601de942a3abf5c8b501b829295bfb1c4a184c.tar.gz nixpkgs-37601de942a3abf5c8b501b829295bfb1c4a184c.tar.bz2 nixpkgs-37601de942a3abf5c8b501b829295bfb1c4a184c.tar.lz nixpkgs-37601de942a3abf5c8b501b829295bfb1c4a184c.tar.xz nixpkgs-37601de942a3abf5c8b501b829295bfb1c4a184c.tar.zst nixpkgs-37601de942a3abf5c8b501b829295bfb1c4a184c.zip |
Merge pull request #237154 from ElvishJerricco/sd-s1-networkd-flush-with-keep-configuration
systemd stage 1 networking: Use KeepConfiguration
Diffstat (limited to 'nixos/modules/system/boot/networkd.nix')
-rw-r--r-- | nixos/modules/system/boot/networkd.nix | 46 |
1 files changed, 13 insertions, 33 deletions
diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix index ef8204e2cf5..bc1a9bad9b3 100644 --- a/nixos/modules/system/boot/networkd.nix +++ b/nixos/modules/system/boot/networkd.nix @@ -2858,6 +2858,17 @@ let }) ]; + stage1Options = { + options.boot.initrd.systemd.network.networks = mkOption { + type = with types; attrsOf (submodule { + # Default in initrd is dhcp-on-stop, which is correct if flushBeforeStage2 = false + config = mkIf config.boot.initrd.network.flushBeforeStage2 { + networkConfig.KeepConfiguration = mkDefault false; + }; + }); + }; + }; + stage1Config = let cfg = config.boot.initrd.systemd.network; in mkMerge [ @@ -2921,45 +2932,14 @@ let ]; kernelModules = [ "af_packet" ]; - systemd.services.nixos-flush-networkd = mkIf config.boot.initrd.network.flushBeforeStage2 { - description = "Flush Network Configuration"; - wantedBy = ["initrd.target"]; - after = ["systemd-networkd.service" "dbus.socket" "dbus.service"]; - before = ["shutdown.target" "initrd-switch-root.target"]; - conflicts = ["shutdown.target" "initrd-switch-root.target"]; - unitConfig.DefaultDependencies = false; - serviceConfig = { - # This service does nothing when starting, but brings down - # interfaces when switching root. This is the easiest way to - # ensure proper ordering while stopping. See systemd.unit(5) - # section on Before= and After=. The important part is that - # we are stopped before units we need, like dbus.service, - # and that we are stopped before starting units like - # initrd-switch-root.target - Type = "oneshot"; - RemainAfterExit = true; - ExecStart = "/bin/true"; - }; - # systemd-networkd doesn't bring down interfaces on its own - # when it exits (see: systemd-networkd(8)), so we have to do - # it ourselves. The networkctl command doesn't have a way to - # bring all interfaces down, so we have to iterate over the - # list and filter out unmanaged interfaces to bring them down - # individually. - preStop = '' - networkctl list --full --no-legend | while read _idx link _type _operational setup _; do - [ "$setup" = unmanaged ] && continue - networkctl down "$link" - done - ''; - }; - }) ]; in { + imports = [ stage1Options ]; + options = { systemd.network = commonOptions true; boot.initrd.systemd.network = commonOptions "shallow"; |