From 3716f2e81194c721ab1b07a90ba34b485e95fccc Mon Sep 17 00:00:00 2001 From: Edgar Pireyn Date: Mon, 6 Apr 2026 18:19:55 +0200 Subject: [PATCH 1/2] nixos/frp: add 'extraConfig' option This feature allows for unparsable settings (by nix) to be used, such as Go templates. It is needed to configure port ranges (https://github.com/fatedier/frp?tab=readme-ov-file#port-range-mapping). --- nixos/modules/services/networking/frp.nix | 33 +++++++++++++++++++- nixos/tests/frp.nix | 37 ++++++++++++++++++++--- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/nixos/modules/services/networking/frp.nix b/nixos/modules/services/networking/frp.nix index f43a102d741d..0cb5b00fd350 100644 --- a/nixos/modules/services/networking/frp.nix +++ b/nixos/modules/services/networking/frp.nix @@ -76,6 +76,26 @@ in ]; }; }; + + extraConfig = lib.mkOption { + type = lib.types.lines; + default = ""; + description = '' + Extra frp TOML configuration included at the end of the generated configuration file. + Especially useful for [port range mapping]. + + [port range mapping]: https://github.com/fatedier/frp#port-range-mapping + ''; + example = '' + {{- range $_, $v := parseNumberRangePair "6000-6006,6007" "6000-6006,6007" }} + [[proxies]] + name = "tcp-{{ $v.First }}" + type = "tcp" + localPort = {{ $v.First }} + remotePort = {{ $v.Second }} + {{- end }} + ''; + }; }; } ); @@ -94,7 +114,18 @@ in instance: options: let serviceName = "frp" + lib.optionalString (instance != "") ("-" + instance); - configFile = settingsFormat.generate "${serviceName}.toml" options.settings; + baseConfigFile = settingsFormat.generate "${serviceName}-base.toml" options.settings; + configFile = + if options.extraConfig == "" then + baseConfigFile + else + pkgs.writeText "${serviceName}.toml" '' + # Nixos Module settings + ${builtins.readFile baseConfigFile} + + # Nixos Module extraConfig + ${options.extraConfig} + ''; isClient = (options.role == "client"); isServer = (options.role == "server"); serviceCapability = lib.optionals isServer [ "CAP_NET_BIND_SERVICE" ]; diff --git a/nixos/tests/frp.nix b/nixos/tests/frp.nix index 48c4e2bc842c..1d71767f33d5 100644 --- a/nixos/tests/frp.nix +++ b/nixos/tests/frp.nix @@ -9,6 +9,7 @@ let name = "secrets"; text = "token=${token}"; }; + portRange = 6003; in { name = "frp"; @@ -56,14 +57,25 @@ in services.httpd = { enable = true; adminAddr = "admin@example.com"; - virtualHosts."test-appication" = + virtualHosts = let testdir = pkgs.writeTextDir "web/index.php" " Date: Sat, 13 Jun 2026 22:52:16 +0200 Subject: [PATCH 2/2] nixos/frp: add self to maintainers --- nixos/modules/services/networking/frp.nix | 5 ++++- nixos/tests/frp.nix | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/networking/frp.nix b/nixos/modules/services/networking/frp.nix index 0cb5b00fd350..fa636bbe06fc 100644 --- a/nixos/modules/services/networking/frp.nix +++ b/nixos/modules/services/networking/frp.nix @@ -175,5 +175,8 @@ in ) enabledInstances; }; - meta.maintainers = with lib.maintainers; [ zaldnoay ]; + meta.maintainers = with lib.maintainers; [ + zaldnoay + epireyn + ]; } diff --git a/nixos/tests/frp.nix b/nixos/tests/frp.nix index 1d71767f33d5..00982a6e05bf 100644 --- a/nixos/tests/frp.nix +++ b/nixos/tests/frp.nix @@ -13,7 +13,10 @@ let in { name = "frp"; - meta.maintainers = with lib.maintainers; [ zaldnoay ]; + meta.maintainers = with lib.maintainers; [ + zaldnoay + epireyn + ]; nodes = { frps = { networking = {