summary refs log tree commit diff
path: root/nixos/modules/system/boot/networkd.nix
diff options
context:
space:
mode:
authorWill Fancher <elvishjerricco@gmail.com>2023-06-11 02:30:01 -0400
committerWill Fancher <elvishjerricco@gmail.com>2023-06-11 13:59:00 -0400
commite23693e12944091b2cc27675f4d14b77f805bfea (patch)
tree0ed6d274d8f952c5e85289b7dfca0009b2add3de /nixos/modules/system/boot/networkd.nix
parent5d6ea734a18203895360f6ea767ee47f7be22e00 (diff)
downloadnixpkgs-e23693e12944091b2cc27675f4d14b77f805bfea.tar
nixpkgs-e23693e12944091b2cc27675f4d14b77f805bfea.tar.gz
nixpkgs-e23693e12944091b2cc27675f4d14b77f805bfea.tar.bz2
nixpkgs-e23693e12944091b2cc27675f4d14b77f805bfea.tar.lz
nixpkgs-e23693e12944091b2cc27675f4d14b77f805bfea.tar.xz
nixpkgs-e23693e12944091b2cc27675f4d14b77f805bfea.tar.zst
nixpkgs-e23693e12944091b2cc27675f4d14b77f805bfea.zip
systemd stage 1 networking: Use KeepConfiguration
Diffstat (limited to 'nixos/modules/system/boot/networkd.nix')
-rw-r--r--nixos/modules/system/boot/networkd.nix46
1 files changed, 13 insertions, 33 deletions
diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix
index d88f88f9fda..59bee807bdb 100644
--- a/nixos/modules/system/boot/networkd.nix
+++ b/nixos/modules/system/boot/networkd.nix
@@ -3147,6 +3147,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 [
@@ -3210,45 +3221,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";