diff --git a/nixos/boxes/home/castle/default.nix b/nixos/boxes/home/castle/default.nix index adb153e..d19dc9e 100644 --- a/nixos/boxes/home/castle/default.nix +++ b/nixos/boxes/home/castle/default.nix @@ -221,6 +221,7 @@ in my = { tmproot.size = "24G"; + network.bbr = true; user = { config.extraGroups = [ "input" ]; diff --git a/nixos/boxes/home/routing-common/default.nix b/nixos/boxes/home/routing-common/default.nix index 896bd09..7a12e59 100644 --- a/nixos/boxes/home/routing-common/default.nix +++ b/nixos/boxes/home/routing-common/default.nix @@ -317,6 +317,7 @@ in as211024 = config.age.secrets."l2mesh/as211024.key".path; }; }; + network.bbr = true; firewall = { trustedInterfaces = [ "lan-hi" "lan-lo" ]; udp.allowed = [ 5353 ]; diff --git a/nixos/modules/network.nix b/nixos/modules/network.nix index 80fabb0..3e916a4 100644 --- a/nixos/modules/network.nix +++ b/nixos/modules/network.nix @@ -1,8 +1,16 @@ { lib, pkgs, config, ... }: let inherit (lib) flatten optional mkIf mkDefault mkMerge versionAtLeast; + inherit (lib.my) mkBoolOpt'; + + cfg = config.my.network; in { + options.my.network.bbr = mkBoolOpt' false + ("Whether to use BBR congestion control for TCP connections this box sends. Unlike the default " + + "(CUBIC), BBR doesn't treat packet loss as congestion, so it keeps throughput up on lossy paths. " + + "It has no effect on traffic the box forwards."); + config = mkMerge [ { networking = { @@ -22,6 +30,14 @@ in }; } + (mkIf cfg.bbr { + # BBR paces its own sending, so the default qdisc (fq_codel) stays as it is. + boot = { + kernelModules = [ "tcp_bbr" ]; + kernel.sysctl."net.ipv4.tcp_congestion_control" = "bbr"; + }; + }) + (mkIf config.my.build.isDevVM { networking.interfaces.eth0.useDHCP = mkDefault true; virtualisation = {