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 (
118 nameValuePair "50-netbird-${name}" {
124 ActivationPolicy = "manual";
135 { environment, stateDir, ... }:
136 nameValuePair "netbird-${name}" {
137 description = "A WireGuard-based mesh network that connects your devices into a single private network";
139 documentation = [ "https://netbird.io/docs/" ];
141 after = [ "network.target" ];
142 wantedBy = [ "multi-user.target" ];
144 path = with pkgs; [ openresolv ];
149 ExecStart = "${getExe cfg.package} service run";
151 RuntimeDirectory = stateDir;
152 StateDirectory = stateDir;
153 StateDirectoryMode = "0700";
154 WorkingDirectory = "/var/lib/${stateDir}";
158 StartLimitInterval = 5;
159 StartLimitBurst = 10;
162 stopIfChanged = false;