diff --git a/docs/options/index.md b/docs/options/index.md
index 90370ab..f41a49b 100644
--- a/docs/options/index.md
+++ b/docs/options/index.md
@@ -359,6 +359,7 @@ services.proxy-suite = {
clientOnly = true;
enable = false;
extraConfig = "";
+ keepAwake = false;
lyrebirdPackage = pkgs.lyrebird;
onionService = {
enable = false;
diff --git a/docs/options/tor.md b/docs/options/tor.md
index 2da7f15..d837a60 100644
--- a/docs/options/tor.md
+++ b/docs/options/tor.md
@@ -15,6 +15,7 @@ Part of the [proxy-suite options reference](./index.md).
- [lines](#services-proxy-suite-tor-bridges-lines)
- [clientOnly](#services-proxy-suite-tor-clientonly)
- [extraConfig](#services-proxy-suite-tor-extraconfig)
+ - [keepAwake](#services-proxy-suite-tor-keepawake)
- [lyrebirdPackage](#services-proxy-suite-tor-lyrebirdpackage)
- onionService
- [enable](#services-proxy-suite-tor-onionservice-enable)
@@ -101,6 +102,17 @@ Extra torrc lines\.
''
```
+
+## services\.proxy-suite\.tor\.keepAwake
+
+Never let Tor go dormant\. By default it does after a day without use, and from then on
+only rebuilds its circuits when the next connection comes: the first \.onion after a quiet
+spell may wait long enough to fail\. Turn on where clients expect \.onion at once, as on a
+server whose inbounds route it\. A dormant Tor also starts dormant again; this wakes it\.
+
+**Type:** boolean\
+**Default:** `false`
+
## services\.proxy-suite\.tor\.lyrebirdPackage
diff --git a/modules/proxy-suite/options/tor.nix b/modules/proxy-suite/options/tor.nix
index ee4503f..c489cd3 100644
--- a/modules/proxy-suite/options/tor.nix
+++ b/modules/proxy-suite/options/tor.nix
@@ -56,6 +56,17 @@ in
'';
};
+ keepAwake = mkOption {
+ type = types.bool;
+ default = false;
+ description = ''
+ Never let Tor go dormant. By default it does after a day without use, and from then on
+ only rebuilds its circuits when the next connection comes: the first .onion after a quiet
+ spell may wait long enough to fail. Turn on where clients expect .onion at once, as on a
+ server whose inbounds route it. A dormant Tor also starts dormant again; this wakes it.
+ '';
+ };
+
upstream = mkOption {
type = types.enum [
"direct"
diff --git a/modules/proxy-suite/tor.nix b/modules/proxy-suite/tor.nix
index 0f2e87e..d023ffe 100644
--- a/modules/proxy-suite/tor.nix
+++ b/modules/proxy-suite/tor.nix
@@ -89,6 +89,10 @@ let
"CookieAuthentication 0"
]
++ lib.optional t.clientOnly "ClientOnly 1"
+ ++ lib.optionals t.keepAwake [
+ "DormantTimeoutEnabled 0"
+ "DormantCanceledByStartup 1"
+ ]
++ (if t.asOutbound then [ "SocksPort 127.0.0.1:${toString t.socksPort}" ] else [ "SocksPort 0" ])
++ lib.optionals bridgesEnabled [
"UseBridges 1"
diff --git a/nix/checks/tor.nix b/nix/checks/tor.nix
index ac06b92..eddcdeb 100644
--- a/nix/checks/tor.nix
+++ b/nix/checks/tor.nix
@@ -88,6 +88,8 @@ let
relayTorStart = torStartOf (mkFixture "sing-box" { tor.clientOnly = false; });
+ awakeTorStart = torStartOf (mkFixture "sing-box" { tor.keepAwake = true; });
+
noOnion = mkFixture "sing-box" { tor.routeOnion = false; };
noOnionTun = mkTunConfig noOnion;
@@ -469,6 +471,9 @@ in
&& hasInfix "DNSPort 0" singBoxTorStart
&& hasInfix "ClientOnly 1" singBoxTorStart
&& !(hasInfix "ClientOnly" relayTorStart)
+ && !(hasInfix "Dormant" singBoxTorStart)
+ && hasInfix "DormantTimeoutEnabled 0" awakeTorStart
+ && hasInfix "DormantCanceledByStartup 1" awakeTorStart
&& hasInfix "ControlSocket unix:$RUNTIME_DIRECTORY/control/socket" singBoxTorStart
&& !(hasInfix "UseBridges" singBoxTorStart)
&& !(hasInfix "Socks5Proxy" singBoxTorStart)