[Backport release-26.05] sing-box: allow empty settings (#533179)

This commit is contained in:
Sizhe Zhao 2026-06-19 04:32:26 +00:00 committed by GitHub
commit 983debce9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 5 deletions

View file

@ -50,6 +50,7 @@ in
serviceConfig = {
User = "sing-box";
Group = "sing-box";
ConfigurationDirectory = "sing-box";
StateDirectory = "sing-box";
StateDirectoryMode = "0700";
RuntimeDirectory = "sing-box";
@ -62,11 +63,15 @@ in
chown --reference=/run/sing-box /run/sing-box/config.json
'';
in
"+${script}";
ExecStart = [
""
"${lib.getExe cfg.package} -D \${STATE_DIRECTORY} -C \${RUNTIME_DIRECTORY} run"
];
lib.mkIf (cfg.settings != { }) "+${script}";
ExecStart =
let
configDir = if cfg.settings != { } then "RUNTIME_DIRECTORY" else "CONFIGURATION_DIRECTORY";
in
[
""
"${lib.getExe cfg.package} -D \${STATE_DIRECTORY} -C \${${configDir}} run"
];
};
# After= is specified by upstream
requires = [ "network-online.target" ];

View file

@ -511,6 +511,31 @@ in
};
};
};
empty_settings =
{ ... }:
{
environment.etc."sing-box/config.json".text = builtins.toJSON {
inbounds = [
{
type = "mixed";
listen = "127.0.0.1";
listen_port = 1088;
}
];
outbounds = [
{
type = "direct";
tag = "outbound:direct";
}
];
};
services.sing-box = {
enable = true;
settings = { };
};
};
};
testScript = ''
@ -558,6 +583,9 @@ in
fakeip.wait_for_unit("sing-box.service")
fakeip.wait_until_succeeds("ip route get ${hosts."${target_host}"} | grep 'dev ${tunInbound.interface_name}'")
fakeip.succeed("dig +short A ${target_host} @${target_host} | grep '^198.18.'")
with subtest("empty settings"):
empty_settings.wait_for_unit("sing-box.service")
'';
}