diff --git a/scripts/download-from-binary-cache.pl.in b/scripts/download-from-binary-cache.pl.in
index 3b8c8bc7f9ab20050408baac11db89469b333af1..332fe5ba563464a0b29edbdbdd1d778c00b5dfff 100644
--- a/scripts/download-from-binary-cache.pl.in
+++ b/scripts/download-from-binary-cache.pl.in
@@ -26,7 +26,7 @@ my $didExpiration = 0;
 
 my $showAfter = 5; # show that we're waiting for a request after this many seconds
 
-my $debug = ($ENV{"NIX_DEBUG_SUBST"} // "") eq 1;
+my $debug = ($Nix::Config::config{"debug-subst"} // "") eq 1 || ($Nix::Config::config{"untrusted-debug-subst"} // "") eq 1;
 
 my $cacheFileURLs = ($ENV{"_NIX_CACHE_FILE_URLS"} // "") eq 1; # for testing