1 { config, lib, pkgs, ... }:
3 cfg = config.services.frp;
4 settingsFormat = pkgs.formats.toml { };
5 configFile = settingsFormat.generate "frp.toml" cfg.settings;
6 isClient = (cfg.role == "client");
7 isServer = (cfg.role == "server");
12 enable = lib.mkEnableOption "frp";
14 package = lib.mkPackageOption pkgs "frp" { };
17 type = lib.types.enum [ "server" "client" ];
19 The frp consists of `client` and `server`. The server is usually
20 deployed on the machine with a public IP address, and
21 the client is usually deployed on the machine
22 where the Intranet service to be penetrated resides.
26 settings = lib.mkOption {
27 type = settingsFormat.type;
30 Frp configuration, for configuration options
31 see the example of [client](https://github.com/fatedier/frp/blob/dev/conf/frpc_full_example.toml)
32 or [server](https://github.com/fatedier/frp/blob/dev/conf/frps_full_example.toml) on github.
35 serverAddr = "x.x.x.x";
44 serviceCapability = lib.optionals isServer [ "CAP_NET_BIND_SERVICE" ];
45 executableFile = if isClient then "frpc" else "frps";
50 wants = lib.optionals isClient [ "network-online.target" ];
51 after = if isClient then [ "network-online.target" ] else [ "network.target" ];
52 wantedBy = [ "multi-user.target" ];
53 description = "A fast reverse proxy frp ${cfg.role}";
56 Restart = "on-failure";
58 ExecStart = "${cfg.package}/bin/${executableFile} --strict_config -c ${configFile}";
59 StateDirectoryMode = lib.optionalString isServer "0700";
62 UMask = lib.optionalString isServer "0007";
63 CapabilityBoundingSet = serviceCapability;
64 AmbientCapabilities = serviceCapability;
65 PrivateDevices = true;
66 ProtectHostname = true;
68 ProtectKernelTunables = true;
69 ProtectKernelModules = true;
70 ProtectKernelLogs = true;
71 ProtectControlGroups = true;
72 RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ] ++ lib.optionals isClient [ "AF_UNIX" ];
73 LockPersonality = true;
74 MemoryDenyWriteExecute = true;
75 RestrictRealtime = true;
76 RestrictSUIDSGID = true;
78 SystemCallArchitectures = "native";
79 SystemCallFilter = [ "@system-service" ];
85 meta.maintainers = with lib.maintainers; [ zaldnoay ];