From b0d9d4d0f9b003ecf92d26f8fea01b65ce1e2294 Mon Sep 17 00:00:00 2001
From: Tom Herbers <mail@tomherbers.de>
Date: Wed, 18 Dec 2024 15:56:20 +0100
Subject: [PATCH] nixos/bird: rename bird2 to bird, switch to bird3 by default

This is done in view of the Release of the new v3 of Bird.

Switch to the bird3 package for the `services.bird.package` option.

Switch the `bird` package alias to bird3.
---
 .../manual/release-notes/rl-2505.section.md   |  2 +
 .../monitoring/prometheus/exporters/bird.nix  |  2 +-
 nixos/modules/services/networking/bird-lg.nix |  2 +-
 nixos/modules/services/networking/bird.nix    | 44 +++++++++++--------
 .../services/networking/birdwatcher.nix       |  2 +-
 nixos/tests/bird.nix                          | 16 +++----
 nixos/tests/birdwatcher.nix                   |  6 +--
 nixos/tests/fastnetmon-advanced.nix           |  4 +-
 nixos/tests/prometheus-exporters.nix          |  4 +-
 pkgs/top-level/aliases.nix                    |  2 +-
 10 files changed, 46 insertions(+), 38 deletions(-)

diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md
index fca105e284f4fa..9494aa38bf01d4 100644
--- a/nixos/doc/manual/release-notes/rl-2505.section.md
+++ b/nixos/doc/manual/release-notes/rl-2505.section.md
@@ -182,6 +182,8 @@
 
 - `linuxPackages.nvidiaPackages.dc_520` has been removed since it is marked broken and there are better newer alternatives.
 
+- `services.bird2` has been renamed to `services.bird` and the default bird package has been switched to `bird3`. `bird2` can still be choosen via the `services.bird.package` option.
+
 - `programs.less.lessopen` is now null by default. To restore the previous behaviour, set it to `''|${lib.getExe' pkgs.lesspipe "lesspipe.sh"} %s''`.
 
 - `hardware.pulseaudio` has been renamed to `services.pulseaudio`.  The deprecated option names will continue to work, but causes a warning.
diff --git a/nixos/modules/services/monitoring/prometheus/exporters/bird.nix b/nixos/modules/services/monitoring/prometheus/exporters/bird.nix
index 00b217e1fd2ab2..78174385d0d0b5 100644
--- a/nixos/modules/services/monitoring/prometheus/exporters/bird.nix
+++ b/nixos/modules/services/monitoring/prometheus/exporters/bird.nix
@@ -45,7 +45,7 @@ in
   };
   serviceOpts = {
     serviceConfig = {
-      SupplementaryGroups = singleton (if cfg.birdVersion == 1 then "bird" else "bird2");
+      SupplementaryGroups = "bird";
       ExecStart = ''
         ${pkgs.prometheus-bird-exporter}/bin/bird_exporter \
           -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
diff --git a/nixos/modules/services/networking/bird-lg.nix b/nixos/modules/services/networking/bird-lg.nix
index ed296b98943f31..f565c7f505fbfe 100644
--- a/nixos/modules/services/networking/bird-lg.nix
+++ b/nixos/modules/services/networking/bird-lg.nix
@@ -320,7 +320,7 @@ in
       groups."bird-lg" = lib.mkIf (cfg.group == "bird-lg") { };
       users."bird-lg" = lib.mkIf (cfg.user == "bird-lg") {
         description = "Bird Looking Glass user";
-        extraGroups = lib.optionals (config.services.bird2.enable) [ "bird2" ];
+        extraGroups = lib.optionals (config.services.bird.enable) [ "bird" ];
         group = cfg.group;
         isSystemUser = true;
       };
diff --git a/nixos/modules/services/networking/bird.nix b/nixos/modules/services/networking/bird.nix
index 880581c2a033de..f4995e9aa4ef34 100644
--- a/nixos/modules/services/networking/bird.nix
+++ b/nixos/modules/services/networking/bird.nix
@@ -14,7 +14,7 @@ let
     types
     ;
 
-  cfg = config.services.bird2;
+  cfg = config.services.bird;
   caps = [
     "CAP_NET_ADMIN"
     "CAP_NET_BIND_SERVICE"
@@ -24,9 +24,9 @@ in
 {
   ###### interface
   options = {
-    services.bird2 = {
+    services.bird = {
       enable = mkEnableOption "BIRD Internet Routing Daemon";
-      package = lib.mkPackageOption pkgs "bird2" { };
+      package = lib.mkPackageOption pkgs "bird3" { };
       config = mkOption {
         type = types.lines;
         description = ''
@@ -38,7 +38,7 @@ in
         type = types.bool;
         default = true;
         description = ''
-          Whether bird2 should be automatically reloaded when the configuration changes.
+          Whether bird should be automatically reloaded when the configuration changes.
         '';
       };
       checkConfig = mkOption {
@@ -59,7 +59,7 @@ in
         '';
         description = ''
           Commands to execute before the config file check. The file to be checked will be
-          available as `bird2.conf` in the current directory.
+          available as `bird.conf` in the current directory.
 
           Files created with this option will not be available at service runtime, only during
           build time checking.
@@ -69,34 +69,36 @@ in
   };
 
   imports = [
-    (lib.mkRemovedOptionModule [ "services" "bird" ] "Use services.bird2 instead")
-    (lib.mkRemovedOptionModule [ "services" "bird6" ] "Use services.bird2 instead")
+    (lib.mkRemovedOptionModule [ "services" "bird2" ]
+      "Use services.bird instead. bird3 is the new default bird package. You can choose to remain with bird2 by setting the service.bird.package option."
+    )
+    (lib.mkRemovedOptionModule [ "services" "bird6" ] "Use services.bird instead")
   ];
 
   ###### implementation
   config = mkIf cfg.enable {
     environment.systemPackages = [ cfg.package ];
 
-    environment.etc."bird/bird2.conf".source = pkgs.writeTextFile {
-      name = "bird2";
+    environment.etc."bird/bird.conf".source = pkgs.writeTextFile {
+      name = "bird";
       text = cfg.config;
       checkPhase = optionalString cfg.checkConfig ''
-        ln -s $out bird2.conf
+        ln -s $out bird.conf
         ${cfg.preCheckConfig}
-        ${pkgs.buildPackages.bird}/bin/bird -d -p -c bird2.conf
+        ${pkgs.buildPackages.bird}/bin/bird -d -p -c bird.conf
       '';
     };
 
-    systemd.services.bird2 = {
+    systemd.services.bird = {
       description = "BIRD Internet Routing Daemon";
       wantedBy = [ "multi-user.target" ];
-      reloadTriggers = lib.optional cfg.autoReload config.environment.etc."bird/bird2.conf".source;
+      reloadTriggers = lib.optional cfg.autoReload config.environment.etc."bird/bird.conf".source;
       serviceConfig = {
         Type = "forking";
         Restart = "on-failure";
-        User = "bird2";
-        Group = "bird2";
-        ExecStart = "${lib.getExe' cfg.package "bird"} -c /etc/bird/bird2.conf";
+        User = "bird";
+        Group = "bird";
+        ExecStart = "${lib.getExe' cfg.package "bird"} -c /etc/bird/bird.conf";
         ExecReload = "${lib.getExe' cfg.package "birdc"} configure";
         ExecStop = "${lib.getExe' cfg.package "birdc"} down";
         RuntimeDirectory = "bird";
@@ -113,12 +115,16 @@ in
       };
     };
     users = {
-      users.bird2 = {
+      users.bird = {
         description = "BIRD Internet Routing Daemon user";
-        group = "bird2";
+        group = "bird";
         isSystemUser = true;
       };
-      groups.bird2 = { };
+      groups.bird = { };
     };
   };
+
+  meta = {
+    maintainers = with lib.maintainers; [ herbetom ];
+  };
 }
diff --git a/nixos/modules/services/networking/birdwatcher.nix b/nixos/modules/services/networking/birdwatcher.nix
index 07df2ee6244435..3325d454633a2f 100644
--- a/nixos/modules/services/networking/birdwatcher.nix
+++ b/nixos/modules/services/networking/birdwatcher.nix
@@ -58,7 +58,7 @@ in
 
           [bird]
           listen = "0.0.0.0:29184"
-          config = "/etc/bird/bird2.conf"
+          config = "/etc/bird/bird.conf"
           birdc  = "''${pkgs.bird}/bin/birdc"
           ttl = 5 # time to live (in minutes) for caching of cli output
 
diff --git a/nixos/tests/bird.nix b/nixos/tests/bird.nix
index 9b52e1beccaef2..d6dccd0f71a37f 100644
--- a/nixos/tests/bird.nix
+++ b/nixos/tests/bird.nix
@@ -13,7 +13,7 @@ let
   inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest;
   inherit (pkgs.lib) optionalString;
 
-  makeBird2Host =
+  makeBirdHost =
     hostId:
     { pkgs, ... }:
     {
@@ -32,7 +32,7 @@ let
         networkConfig.Address = "10.0.0.${hostId}/24";
       };
 
-      services.bird2 = {
+      services.bird = {
         enable = true;
 
         config = ''
@@ -107,17 +107,17 @@ let
     };
 in
 makeTest {
-  name = "bird2";
+  name = "bird";
 
-  nodes.host1 = makeBird2Host "1";
-  nodes.host2 = makeBird2Host "2";
+  nodes.host1 = makeBirdHost "1";
+  nodes.host2 = makeBirdHost "2";
 
   testScript = ''
     start_all()
 
-    host1.wait_for_unit("bird2.service")
-    host2.wait_for_unit("bird2.service")
-    host1.succeed("systemctl reload bird2.service")
+    host1.wait_for_unit("bird.service")
+    host2.wait_for_unit("bird.service")
+    host1.succeed("systemctl reload bird.service")
 
     with subtest("Waiting for advertised IPv4 routes"):
       host1.wait_until_succeeds("ip --json r | jq -e 'map(select(.dst == \"10.10.0.2\")) | any'")
diff --git a/nixos/tests/birdwatcher.nix b/nixos/tests/birdwatcher.nix
index 1f90e840e441a9..00b3b6d77af2c5 100644
--- a/nixos/tests/birdwatcher.nix
+++ b/nixos/tests/birdwatcher.nix
@@ -17,7 +17,7 @@ makeTest {
   nodes = {
     host1 = {
       environment.systemPackages = with pkgs; [ jq ];
-      services.bird2 = {
+      services.bird = {
         enable = true;
         config = ''
           log syslog all;
@@ -71,7 +71,7 @@ makeTest {
           filter_fields = []
           [bird]
           listen = "0.0.0.0:29184"
-          config = "/etc/bird/bird2.conf"
+          config = "/etc/bird/bird.conf"
           birdc  = "${pkgs.bird}/bin/birdc"
           ttl = 5 # time to live (in minutes) for caching of cli output
           [parser]
@@ -89,7 +89,7 @@ makeTest {
   testScript = ''
     start_all()
 
-    host1.wait_for_unit("bird2.service")
+    host1.wait_for_unit("bird.service")
     host1.wait_for_unit("birdwatcher.service")
     host1.wait_for_open_port(29184)
     host1.succeed("curl http://[::]:29184/status | jq -r .status.message | grep 'Daemon is up and running'")
diff --git a/nixos/tests/fastnetmon-advanced.nix b/nixos/tests/fastnetmon-advanced.nix
index 1582280cb5df81..99ef0513b1b40f 100644
--- a/nixos/tests/fastnetmon-advanced.nix
+++ b/nixos/tests/fastnetmon-advanced.nix
@@ -9,7 +9,7 @@
       { ... }:
       {
         networking.firewall.allowedTCPPorts = [ 179 ];
-        services.bird2 = {
+        services.bird = {
           enable = true;
           config = ''
             router id 192.168.1.1;
@@ -59,7 +59,7 @@
     ''
       start_all()
       fnm.wait_for_unit("fastnetmon.service")
-      bird.wait_for_unit("bird2.service")
+      bird.wait_for_unit("bird.service")
 
       fnm.wait_until_succeeds('journalctl -eu fastnetmon.service | grep "BGP daemon restarted correctly"')
       fnm.wait_until_succeeds("journalctl -eu gobgp.service | grep BGP_FSM_OPENCONFIRM")
diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix
index c20b3e4f99fe94..3afe4fcc957911 100644
--- a/nixos/tests/prometheus-exporters.nix
+++ b/nixos/tests/prometheus-exporters.nix
@@ -116,8 +116,8 @@ let
         enable = true;
       };
       metricProvider = {
-        services.bird2.enable = true;
-        services.bird2.config = ''
+        services.bird.enable = true;
+        services.bird.config = ''
           router id 127.0.0.1;
 
           protocol kernel MyObviousTestString {
diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix
index 7e6dcb6b48c1b5..9b142a1492517f 100644
--- a/pkgs/top-level/aliases.nix
+++ b/pkgs/top-level/aliases.nix
@@ -148,7 +148,7 @@ mapAliases {
   bibata-extra-cursors = throw "bibata-cursors has been removed as it was broken"; # Added 2024-07-15
   bitcoin-unlimited = throw "bitcoin-unlimited has been removed as it was broken and unmaintained"; # Added 2024-07-15
   bitcoind-unlimited = throw "bitcoind-unlimited has been removed as it was broken and unmaintained"; # Added 2024-07-15
-  bird = bird2; # Added 2025-01-11
+  bird = bird3; # Added 2025-01-11
   bisq-desktop = throw "bisq-desktop has been removed because OpenJFX 11 was removed"; # Added 2024-11-17
   bitwarden = bitwarden-desktop; # Added 2024-02-25
   blender-with-packages = args: