mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-07-06 17:13:24 -05:00
[Backport release-26.05] sing-box: allow empty settings (#533179)
This commit is contained in:
commit
983debce9a
2 changed files with 38 additions and 5 deletions
|
|
@ -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" ];
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
'';
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue