Merge pull request #237154 from ElvishJerricco/sd-s1-networkd-flush-with-keep-configuration

systemd stage 1 networking: Use KeepConfiguration

authored by

Will Fancher and committed by
GitHub
37601de9 d1c9180c

+13 -33
+13 -33
nixos/modules/system/boot/networkd.nix
··· 2858 2858 }) 2859 2859 ]; 2860 2860 2861 + stage1Options = { 2862 + options.boot.initrd.systemd.network.networks = mkOption { 2863 + type = with types; attrsOf (submodule { 2864 + # Default in initrd is dhcp-on-stop, which is correct if flushBeforeStage2 = false 2865 + config = mkIf config.boot.initrd.network.flushBeforeStage2 { 2866 + networkConfig.KeepConfiguration = mkDefault false; 2867 + }; 2868 + }); 2869 + }; 2870 + }; 2871 + 2861 2872 stage1Config = let 2862 2873 cfg = config.boot.initrd.systemd.network; 2863 2874 in mkMerge [ ··· 2921 2932 ]; 2922 2933 kernelModules = [ "af_packet" ]; 2923 2934 2924 - systemd.services.nixos-flush-networkd = mkIf config.boot.initrd.network.flushBeforeStage2 { 2925 - description = "Flush Network Configuration"; 2926 - wantedBy = ["initrd.target"]; 2927 - after = ["systemd-networkd.service" "dbus.socket" "dbus.service"]; 2928 - before = ["shutdown.target" "initrd-switch-root.target"]; 2929 - conflicts = ["shutdown.target" "initrd-switch-root.target"]; 2930 - unitConfig.DefaultDependencies = false; 2931 - serviceConfig = { 2932 - # This service does nothing when starting, but brings down 2933 - # interfaces when switching root. This is the easiest way to 2934 - # ensure proper ordering while stopping. See systemd.unit(5) 2935 - # section on Before= and After=. The important part is that 2936 - # we are stopped before units we need, like dbus.service, 2937 - # and that we are stopped before starting units like 2938 - # initrd-switch-root.target 2939 - Type = "oneshot"; 2940 - RemainAfterExit = true; 2941 - ExecStart = "/bin/true"; 2942 - }; 2943 - # systemd-networkd doesn't bring down interfaces on its own 2944 - # when it exits (see: systemd-networkd(8)), so we have to do 2945 - # it ourselves. The networkctl command doesn't have a way to 2946 - # bring all interfaces down, so we have to iterate over the 2947 - # list and filter out unmanaged interfaces to bring them down 2948 - # individually. 2949 - preStop = '' 2950 - networkctl list --full --no-legend | while read _idx link _type _operational setup _; do 2951 - [ "$setup" = unmanaged ] && continue 2952 - networkctl down "$link" 2953 - done 2954 - ''; 2955 - }; 2956 - 2957 2935 }) 2958 2936 ]; 2959 2937 2960 2938 in 2961 2939 2962 2940 { 2941 + imports = [ stage1Options ]; 2942 + 2963 2943 options = { 2964 2944 systemd.network = commonOptions true; 2965 2945 boot.initrd.systemd.network = commonOptions "shallow";