1 { config, lib, pkgs, ... }:
4 inherit (lib) mkEnableOption mkIf mkOption optionalString types;
6 cfg = config.services.bird2;
7 caps = [ "CAP_NET_ADMIN" "CAP_NET_BIND_SERVICE" "CAP_NET_RAW" ];
13 enable = mkEnableOption "BIRD Internet Routing Daemon";
17 BIRD Internet Routing Daemon configuration file.
18 <http://bird.network.cz/>
21 autoReload = mkOption {
25 Whether bird2 should be automatically reloaded when the configuration changes.
28 checkConfig = mkOption {
32 Whether the config should be checked at build time.
33 When the config can't be checked during build time, for example when it includes
34 other files, either disable this option or use `preCheckConfig` to create
35 the included files before checking.
38 preCheckConfig = mkOption {
42 echo "cost 100;" > include.conf
45 Commands to execute before the config file check. The file to be checked will be
46 available as `bird2.conf` in the current directory.
48 Files created with this option will not be available at service runtime, only during
57 (lib.mkRemovedOptionModule [ "services" "bird" ] "Use services.bird2 instead")
58 (lib.mkRemovedOptionModule [ "services" "bird6" ] "Use services.bird2 instead")
62 config = mkIf cfg.enable {
63 environment.systemPackages = [ pkgs.bird ];
65 environment.etc."bird/bird2.conf".source = pkgs.writeTextFile {
68 checkPhase = optionalString cfg.checkConfig ''
71 ${pkgs.buildPackages.bird}/bin/bird -d -p -c bird2.conf
75 systemd.services.bird2 = {
76 description = "BIRD Internet Routing Daemon";
77 wantedBy = [ "multi-user.target" ];
78 reloadTriggers = lib.optional cfg.autoReload config.environment.etc."bird/bird2.conf".source;
81 Restart = "on-failure";
84 ExecStart = "${pkgs.bird}/bin/bird -c /etc/bird/bird2.conf";
85 ExecReload = "${pkgs.bird}/bin/birdc configure";
86 ExecStop = "${pkgs.bird}/bin/birdc down";
87 RuntimeDirectory = "bird";
88 CapabilityBoundingSet = caps;
89 AmbientCapabilities = caps;
90 ProtectSystem = "full";
92 ProtectKernelTunables = true;
93 ProtectControlGroups = true;
95 PrivateDevices = true;
96 SystemCallFilter = "~@cpu-emulation @debug @keyring @module @mount @obsolete @raw-io";
97 MemoryDenyWriteExecute = "yes";
102 description = "BIRD Internet Routing Daemon user";