1 { config, lib, pkgs, ... }:
3 cfg = config.services.cloudflare-warp;
6 options.services.cloudflare-warp = {
7 enable = lib.mkEnableOption "Cloudflare Zero Trust client daemon";
9 package = lib.mkPackageOption pkgs "cloudflare-warp" { };
11 rootDir = lib.mkOption {
13 default = "/var/lib/cloudflare-warp";
15 Working directory for the warp-svc daemon.
19 udpPort = lib.mkOption {
20 type = lib.types.port;
23 The UDP port to open in the firewall. Warp uses port 2408 by default, but fallback ports can be used
24 if that conflicts with another service. See the [firewall documentation](https://developers.cloudflare.com/cloudflare-one/connections/connect-devices/warp/deployment/firewall#warp-udp-ports)
25 for the pre-configured available fallback ports.
29 openFirewall = lib.mkEnableOption "opening UDP ports in the firewall" // {
34 config = lib.mkIf cfg.enable {
35 environment.systemPackages = [ cfg.package ];
37 networking.firewall = lib.mkIf cfg.openFirewall {
38 allowedUDPPorts = [ cfg.udpPort ];
41 systemd.tmpfiles.rules = [
42 "d ${cfg.rootDir} - root root"
43 "z ${cfg.rootDir} - root root"
46 systemd.services.cloudflare-warp = {
48 description = "Cloudflare Zero Trust Client Daemon";
50 # lsof is used by the service to determine which UDP port to bind to
51 # in the case that it detects collisions.
53 requires = [ "network.target" ];
54 wantedBy = [ "multi-user.target" ];
60 "CAP_NET_BIND_SERVICE"
66 ExecStart = "${cfg.package}/bin/warp-svc";
67 ReadWritePaths = [ "${cfg.rootDir}" "/etc/resolv.conf" ];
68 CapabilityBoundingSet = caps;
69 AmbientCapabilities = caps;
72 Environment = [ "RUST_BACKTRACE=full" ];
73 WorkingDirectory = cfg.rootDir;
75 # See the systemd.exec docs for the canonicalized paths, the service
76 # makes use of them for logging, and account state info tracking.
77 # https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#RuntimeDirectory=
78 StateDirectory = "cloudflare-warp";
79 RuntimeDirectory = "cloudflare-warp";
80 LogsDirectory = "cloudflare-warp";
82 # The service needs to write to /etc/resolv.conf to configure DNS, so that file would have to
83 # be world read/writable to run as anything other than root.
90 meta.maintainers = with lib.maintainers; [ treyfortmuller ];