Skip to content

Commit 09950e4

Browse files
authored
sing-box: 1.11.15 -> 1.12.3, nixos/sing-box: add user and group, nixosTests.sing-box: migrate config (#430835)
2 parents 840c2c7 + 5bcb1ac commit 09950e4

File tree

4 files changed

+56
-20
lines changed

4 files changed

+56
-20
lines changed

nixos/doc/manual/release-notes/rl-2511.section.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@
109109
- The non-LTS Forgejo package (`forgejo`) has been updated to 12.0.0. This release contains breaking changes, see the [release blog post](https://forgejo.org/2025-07-release-v12-0/)
110110
for all the details and how to ensure smooth upgrades.
111111

112+
- `sing-box` has been updated to 1.12.3, which includes a number of breaking changes, old configurations may need updating or they will cause the tool to fail to run.
113+
See the [change log](https://sing-box.sagernet.org/changelog/#1123) for details and [migration](https://sing-box.sagernet.org/migration/#1120) for how to update old configurations.
114+
112115
- The Pocket ID module ([`services.pocket-id`][#opt-services.pocket-id.enable]) and package (`pocket-id`) has been updated to 1.0.0. Some environment variables have been changed or removed, see the [migration guide](https://pocket-id.org/docs/setup/migrate-to-v1/).
113116

114117
- The `zigbee2mqtt` package was updated to version 2.x, which contains breaking changes. See the [discussion](https://github.com/Koenkk/zigbee2mqtt/discussions/24198) for further information.

nixos/modules/services/networking/sing-box.nix

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ in
1212
{
1313

1414
meta = {
15-
maintainers = with lib.maintainers; [ nickcao ];
15+
maintainers = with lib.maintainers; [
16+
nickcao
17+
prince213
18+
];
1619
};
1720

1821
options = {
@@ -59,22 +62,41 @@ in
5962
}
6063
];
6164

65+
# for polkit rules
66+
environment.systemPackages = [ cfg.package ];
67+
services.dbus.packages = [ cfg.package ];
6268
systemd.packages = [ cfg.package ];
6369

6470
systemd.services.sing-box = {
65-
preStart = utils.genJqSecretsReplacementSnippet cfg.settings "/run/sing-box/config.json";
6671
serviceConfig = {
72+
User = "sing-box";
73+
Group = "sing-box";
6774
StateDirectory = "sing-box";
6875
StateDirectoryMode = "0700";
6976
RuntimeDirectory = "sing-box";
7077
RuntimeDirectoryMode = "0700";
78+
ExecStartPre =
79+
let
80+
script = pkgs.writeShellScript "sing-box-pre-start" ''
81+
${utils.genJqSecretsReplacementSnippet cfg.settings "/run/sing-box/config.json"}
82+
chown --reference=/run/sing-box /run/sing-box/config.json
83+
'';
84+
in
85+
"+${script}";
7186
ExecStart = [
7287
""
7388
"${lib.getExe cfg.package} -D \${STATE_DIRECTORY} -C \${RUNTIME_DIRECTORY} run"
7489
];
7590
};
7691
wantedBy = [ "multi-user.target" ];
7792
};
78-
};
7993

94+
users = {
95+
users.sing-box = {
96+
isSystemUser = true;
97+
group = "sing-box";
98+
};
99+
groups.sing-box = { };
100+
};
101+
};
80102
}

nixos/tests/sing-box.nix

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ in
111111
name = "sing-box";
112112

113113
meta = {
114-
maintainers = with lib.maintainers; [ nickcao ];
114+
maintainers = with lib.maintainers; [
115+
nickcao
116+
prince213
117+
];
115118
};
116119

117120
nodes = {
@@ -436,26 +439,25 @@ in
436439
dns = {
437440
final = "dns:default";
438441
independent_cache = true;
439-
fakeip = {
440-
enabled = true;
441-
inet4_range = "198.18.0.0/16";
442-
};
443442
servers = [
444443
{
445-
detour = "outbound:direct";
444+
type = "udp";
446445
tag = "dns:default";
447-
address = hosts."${target_host}";
446+
server = hosts."${target_host}";
448447
}
449448
{
449+
type = "fakeip";
450450
tag = "dns:fakeip";
451-
address = "fakeip";
451+
inet4_range = "198.18.0.0/16";
452452
}
453-
];
454-
rules = [
455453
{
456-
outbound = [ "any" ];
457-
server = "dns:default";
454+
type = "resolved";
455+
tag = "dns:resolved";
456+
service = "service:resolved";
457+
accept_default_resolvers = true;
458458
}
459+
];
460+
rules = [
459461
{
460462
query_type = [
461463
"A"
@@ -479,6 +481,7 @@ in
479481
}
480482
];
481483
route = {
484+
default_domain_resolver = "dns:default";
482485
default_interface = "eth1";
483486
final = "outbound:direct";
484487
rules = [
@@ -491,6 +494,12 @@ in
491494
}
492495
];
493496
};
497+
services = [
498+
{
499+
type = "resolved";
500+
tag = "service:resolved";
501+
}
502+
];
494503
};
495504
};
496505
};

pkgs/by-name/si/sing-box/package.nix

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,26 @@
1010

1111
buildGoModule (finalAttrs: {
1212
pname = "sing-box";
13-
version = "1.11.15";
13+
version = "1.12.3";
1414

1515
src = fetchFromGitHub {
1616
owner = "SagerNet";
1717
repo = "sing-box";
1818
tag = "v${finalAttrs.version}";
19-
hash = "sha256-uqPV3PGk3hFpV1B8+htBG9x58RVWew0sBDUItpxyv8Q=";
19+
hash = "sha256-OHhCC+tSDZRSDN9i3L6NtwgarBKHv+KGNyPhHttqo4g=";
2020
};
2121

22-
vendorHash = "sha256-qZlnY0MxB4/ttgjuAroTfqGWqGRea549EyIjSxPAlOI=";
22+
vendorHash = "sha256-Y/UP2rbee4WSctelk9QddMXciucz5dNLOLDDWtEFfLU=";
2323

2424
tags = [
2525
"with_quic"
2626
"with_dhcp"
2727
"with_wireguard"
28-
"with_ech"
2928
"with_utls"
30-
"with_reality_server"
3129
"with_acme"
3230
"with_clash_api"
3331
"with_gvisor"
32+
"with_tailscale"
3433
];
3534

3635
subPackages = [
@@ -50,6 +49,9 @@ buildGoModule (finalAttrs: {
5049
--replace-fail "/usr/bin/sing-box" "$out/bin/sing-box" \
5150
--replace-fail "/bin/kill" "${coreutils}/bin/kill"
5251
install -Dm444 -t "$out/lib/systemd/system/" release/config/sing-box{,@}.service
52+
53+
install -Dm444 release/config/sing-box.rules $out/share/polkit-1/rules.d/sing-box.rules
54+
install -Dm444 release/config/sing-box-split-dns.xml $out/share/dbus-1/system.d/sing-box-split-dns.conf
5355
'';
5456

5557
passthru = {

0 commit comments

Comments
 (0)