diff --git a/modules/programs/nh.nix b/modules/programs/nh.nix
index a5e8dcfaf..cf6c06e54 100644
--- a/modules/programs/nh.nix
+++ b/modules/programs/nh.nix
@@ -52,8 +52,8 @@ in {
   };
 
   config = {
-    warnings = lib.optionals (!(cfg.clean.enable -> !osConfig.nix.gc.automatic))
-      [
+    warnings = lib.optionals
+      (osConfig != null && !(cfg.clean.enable -> !osConfig.nix.gc.automatic)) [
         "programs.nh.clean.enable and nix.gc.automatic (system-wide in configuration.nix) are both enabled. Please use one or the other to avoid conflict."
       ];