From 8b5644684e27ebaf1add58753544d2ab4e34b9ab Mon Sep 17 00:00:00 2001 From: Adithya Nair Date: Fri, 15 Dec 2023 15:43:45 +0530 Subject: [PATCH] nixos/frp: use toml configFile According to upstream, the INI configuration file is deprecated and TOML/YAML/JSON is recommended. Link: https://github.com/fatedier/frp/tree/dev#configuration-files --- .../manual/release-notes/rl-2405.section.md | 6 +++++ nixos/modules/services/networking/frp.nix | 22 +++++++--------- nixos/tests/frp.nix | 25 +++++++++---------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/nixos/doc/manual/release-notes/rl-2405.section.md b/nixos/doc/manual/release-notes/rl-2405.section.md index ae9352e9a921..9e8ef49783ca 100644 --- a/nixos/doc/manual/release-notes/rl-2405.section.md +++ b/nixos/doc/manual/release-notes/rl-2405.section.md @@ -67,6 +67,12 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m - The legacy and long deprecated systemd target `network-interfaces.target` has been removed. Use `network.target` instead. +- `services.frp.settings` now generates the frp configuration file in TOML format as [recommended by upstream](https://github.com/fatedier/frp#configuration-files), instead of the legacy INI format. This has also introduced other changes in the configuration file structure and options. + - The `settings.common` section in the configuration is no longer valid and all the options form inside it now goes directly under `settings`. + - The `_` separating words in the configuration options is removed so the options are now in camel case. For example: `server_addr` becomes `serverAddr`, `server_port` becomes `serverPort` etc. + - Proxies are now defined with a new option `settings.proxies` which takes a list of proxies. + - Consult the [upstream documentation](https://github.com/fatedier/frp#example-usage) for more details on the changes. + - `mkosi` was updated to v20. Parts of the user interface have changed. Consult the release notes of [v19](https://github.com/systemd/mkosi/releases/tag/v19) and [v20](https://github.com/systemd/mkosi/releases/tag/v20) for a list of changes. diff --git a/nixos/modules/services/networking/frp.nix b/nixos/modules/services/networking/frp.nix index 218d532c12da..eb022308bc29 100644 --- a/nixos/modules/services/networking/frp.nix +++ b/nixos/modules/services/networking/frp.nix @@ -4,8 +4,8 @@ with lib; let cfg = config.services.frp; - settingsFormat = pkgs.formats.ini { }; - configFile = settingsFormat.generate "frp.ini" cfg.settings; + settingsFormat = pkgs.formats.toml { }; + configFile = settingsFormat.generate "frp.toml" cfg.settings; isClient = (cfg.role == "client"); isServer = (cfg.role == "server"); in @@ -31,17 +31,13 @@ in default = { }; description = mdDoc '' Frp configuration, for configuration options - see the example of [client](https://github.com/fatedier/frp/blob/dev/conf/frpc_legacy_full.ini) - or [server](https://github.com/fatedier/frp/blob/dev/conf/frps_legacy_full.ini) on github. - ''; - example = literalExpression '' - { - common = { - server_addr = "x.x.x.x"; - server_port = 7000; - }; - } + see the example of [client](https://github.com/fatedier/frp/blob/dev/conf/frpc_full_example.toml) + or [server](https://github.com/fatedier/frp/blob/dev/conf/frps_full_example.toml) on github. ''; + example = { + serverAddr = "x.x.x.x"; + serverPort = 7000; + }; }; }; }; @@ -62,7 +58,7 @@ in Type = "simple"; Restart = "on-failure"; RestartSec = 15; - ExecStart = "${cfg.package}/bin/${executableFile} -c ${configFile}"; + ExecStart = "${cfg.package}/bin/${executableFile} --strict_config -c ${configFile}"; StateDirectoryMode = optionalString isServer "0700"; DynamicUser = true; # Hardening diff --git a/nixos/tests/frp.nix b/nixos/tests/frp.nix index 2f5c0f8ec933..1f57c031a53a 100644 --- a/nixos/tests/frp.nix +++ b/nixos/tests/frp.nix @@ -18,10 +18,8 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: { enable = true; role = "server"; settings = { - common = { - bind_port = 7000; - vhost_http_port = 80; - }; + bindPort = 7000; + vhostHTTPPort = 80; }; }; }; @@ -59,15 +57,16 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: { enable = true; role = "client"; settings = { - common = { - server_addr = "10.0.0.1"; - server_port = 7000; - }; - web = { - type = "http"; - local_port = 80; - custom_domains = "10.0.0.1"; - }; + serverAddr = "10.0.0.1"; + serverPort = 7000; + proxies = [ + { + name = "web"; + type = "http"; + localPort = 80; + customDomains = [ "10.0.0.1" ]; + } + ]; }; }; };