···28582858 })
28592859 ];
2860286028612861+ stage1Options = {
28622862+ options.boot.initrd.systemd.network.networks = mkOption {
28632863+ type = with types; attrsOf (submodule {
28642864+ # Default in initrd is dhcp-on-stop, which is correct if flushBeforeStage2 = false
28652865+ config = mkIf config.boot.initrd.network.flushBeforeStage2 {
28662866+ networkConfig.KeepConfiguration = mkDefault false;
28672867+ };
28682868+ });
28692869+ };
28702870+ };
28712871+28612872 stage1Config = let
28622873 cfg = config.boot.initrd.systemd.network;
28632874 in mkMerge [
···29212932 ];
29222933 kernelModules = [ "af_packet" ];
2923293429242924- systemd.services.nixos-flush-networkd = mkIf config.boot.initrd.network.flushBeforeStage2 {
29252925- description = "Flush Network Configuration";
29262926- wantedBy = ["initrd.target"];
29272927- after = ["systemd-networkd.service" "dbus.socket" "dbus.service"];
29282928- before = ["shutdown.target" "initrd-switch-root.target"];
29292929- conflicts = ["shutdown.target" "initrd-switch-root.target"];
29302930- unitConfig.DefaultDependencies = false;
29312931- serviceConfig = {
29322932- # This service does nothing when starting, but brings down
29332933- # interfaces when switching root. This is the easiest way to
29342934- # ensure proper ordering while stopping. See systemd.unit(5)
29352935- # section on Before= and After=. The important part is that
29362936- # we are stopped before units we need, like dbus.service,
29372937- # and that we are stopped before starting units like
29382938- # initrd-switch-root.target
29392939- Type = "oneshot";
29402940- RemainAfterExit = true;
29412941- ExecStart = "/bin/true";
29422942- };
29432943- # systemd-networkd doesn't bring down interfaces on its own
29442944- # when it exits (see: systemd-networkd(8)), so we have to do
29452945- # it ourselves. The networkctl command doesn't have a way to
29462946- # bring all interfaces down, so we have to iterate over the
29472947- # list and filter out unmanaged interfaces to bring them down
29482948- # individually.
29492949- preStop = ''
29502950- networkctl list --full --no-legend | while read _idx link _type _operational setup _; do
29512951- [ "$setup" = unmanaged ] && continue
29522952- networkctl down "$link"
29532953- done
29542954- '';
29552955- };
29562956-29572935 })
29582936 ];
2959293729602938in
2961293929622940{
29412941+ imports = [ stage1Options ];
29422942+29632943 options = {
29642944 systemd.network = commonOptions true;
29652945 boot.initrd.systemd.network = commonOptions "shallow";