From 96dbdd6a9ec709290e822d3e8f15e628c1f415dd Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Sun, 7 Jun 2026 16:28:24 -0400 Subject: [PATCH] lib.modules: inline `head defs` variable Each value passed to a function or primop is passed as a thunk, so `head defs` will only be evaluated twice if we're throwing an error. Validated with `builtins.trace`. --- lib/modules.nix | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/modules.nix b/lib/modules.nix index f953b9e62a68..a84ffd2d9aa6 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -1193,11 +1193,8 @@ let # original singleton straight to the type merge. if length defs == 1 - && ( - let - d = head defs; - in - addErrorContext "while evaluating definitions from `${d.file}':" (!d.value ? _type) + && addErrorContext "while evaluating definitions from `${(head defs).file}':" ( + !(head defs).value ? _type ) then {