33 kernel = config.boot.kernelPackages;
35 cfg = config.services.netbird;
38 meta.maintainers = with maintainers; [ ];
39 meta.doc = ./netbird.md;
41 options.services.netbird = {
42 enable = mkEnableOption "Netbird daemon";
43 package = mkPackageOption pkgs "netbird" { };
48 { name, config, ... }:
55 Port for the ${name} netbird interface.
59 environment = mkOption {
61 defaultText = literalExpression ''
63 NB_CONFIG = "/var/lib/''${stateDir}/config.json";
64 NB_LOG_FILE = "console";
65 NB_WIREGUARD_PORT = builtins.toString port;
66 NB_INTERFACE_NAME = name;
67 NB_DAMEON_ADDR = "/var/run/''${stateDir}"
71 Environment for the netbird service, used to pass configuration options.
77 default = "netbird-${name}";
79 Directory storing the netbird configuration.
84 config.environment = builtins.mapAttrs (_: mkDefault) {
85 NB_CONFIG = "/var/lib/${config.stateDir}/config.json";
86 NB_LOG_FILE = "console";
87 NB_WIREGUARD_PORT = builtins.toString config.port;
88 NB_INTERFACE_NAME = name;
89 NB_DAEMON_ADDR = "unix:///var/run/${config.stateDir}/sock";
96 Attribute set of Netbird tunnels, each one will spawn a daemon listening on ...
103 # For backwards compatibility
104 services.netbird.tunnels.wt0.stateDir = "netbird";
107 (mkIf (cfg.tunnels != { }) {
108 boot.extraModulePackages = optional (versionOlder kernel.kernel.version "5.6") kernel.wireguard;
110 environment.systemPackages = [ cfg.package ];
112 networking.dhcpcd.denyInterfaces = attrNames cfg.tunnels;
114 systemd.network.networks = mkIf config.networking.useNetworkd (
117 nameValuePair "50-netbird-${name}" {
123 ActivationPolicy = "manual";
129 systemd.services = mapAttrs' (
131 { environment, stateDir, ... }:
132 nameValuePair "netbird-${name}" {
133 description = "A WireGuard-based mesh network that connects your devices into a single private network";
135 documentation = [ "https://netbird.io/docs/" ];
137 after = [ "network.target" ];
138 wantedBy = [ "multi-user.target" ];
140 path = with pkgs; [ openresolv ];
145 ExecStart = "${getExe cfg.package} service run";
147 RuntimeDirectory = stateDir;
148 StateDirectory = stateDir;
149 StateDirectoryMode = "0700";
150 WorkingDirectory = "/var/lib/${stateDir}";
154 StartLimitInterval = 5;
155 StartLimitBurst = 10;
158 stopIfChanged = false;