Commit Graph

387 Commits

Author SHA1 Message Date
Léana
199ee26b83 lib.modules: document mkOverride
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2026-09-27 12:30:55 +02:00
Robert Hensing
bc9263e560 lib.modules.mapAttrsOfSubmodule: init (#561282) 2026-09-14 23:33:23 +00:00
Eman Resu
20c3f1c345 lib/modules: fix typo (#560990) 2026-09-12 15:21:03 +00:00
Ben Siraphob
54c3e474ef lib.modules: fix typo in deprecation warning 2026-09-09 13:12:24 -07:00
Robert Hensing
eab7314fbb lib.modules.mapAttrsOfSubmodule: edit doc 2026-09-09 08:47:21 +02:00
Robert Hensing
c70d9ffe53 lib.modules.mapAttrsOfSubmodule: init 2026-09-08 16:19:46 +02:00
HigherOrderLogic
47f57f573f lib/modules: fix typo 2026-09-07 19:04:28 +00:00
Eman Resu
89a82e0ec7 lib.modules: avoid merging when type is already specified 2026-08-31 13:50:33 -04:00
Eman Resu
b8930be77c lib.modules: check res first when merging 2026-08-31 13:50:33 -04:00
Eman Resu
6a71bffb1b lib.modules: avoid logic if cfg has no _type attribute
Also move the check for `_type == "if` to be first, as in my
benchmarking, if statements occur far more often than merges (23k vs
3k).
2026-08-31 13:50:33 -04:00
Eman Resu
23c973c4c1 lib.modules: inline mapAttrsRecursiveCond call with more axioms
mapAttrsRecursiveCond generates an attribute path while iterating, but
we completely ignore it. We also don't need to run the isAttrs check,
since isOption will check if `v._type == "option"`, and ? runs a
typecheck internally. These combined justify the inlining in my opinion.
2026-08-31 13:50:32 -04:00
Eman Resu
91da5d6b41 lib.modules: avoid filtering disabled modules if they're empty 2026-08-31 13:50:32 -04:00
Eman Resu
47e958cd9a lib.modules: inline mergedType into a lower scope
This will only be used if `res ? type` (which is barely ever true, since
there's typically only ever one decl). We can avoid the thunk in every
case.
2026-08-31 13:50:32 -04:00
Eman Resu
aab4682e75 lib.modules: inline value variable in evalOptionValue 2026-08-31 13:50:31 -04:00
Eman Resu
be514e8dad lib.modules: beta reduce mergeOptionDecls for free 2026-08-31 13:50:31 -04:00
Eman Resu
2abe9edb0b lib.modules: inline several variables in definition merge 2026-08-31 13:50:30 -04:00
Eman Resu
93485d98a0 lib.modules: inline defns variable 2026-08-31 13:50:30 -04:00
Eman Resu
830dd996ea lib.modules: avoid filtering option decls in most cases 2026-08-31 13:50:28 -04:00
Eman Resu
d03c2169d2 lib.modules: inline warnDeprecation
Saves 0.5% of all thunks for my personal config.
2026-08-31 13:38:08 -04:00
Eman Resu
d3bbd01933 lib.modules: compute disabled module list early
isDisabled gets the list of disabledModules ready when it's only given
two attributes, so when it's passed the third argument, it just has to
call `elem` on its precomputed list. This was being used in the graph
right below, but now in module filtering.
2026-08-31 13:38:08 -04:00
Eman Resu
4d3fcf13e7 lib.modules: store attributes to remove outside of function call 2026-08-31 13:38:08 -04:00
Eman Resu
96dbdd6a9e 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`.
2026-08-31 13:38:07 -04:00
Eman Resu
d95430f876 lib.modules: avoid isAttrs check for ?
? is untyped in its input, and performs the isAttrs check already,
returning false.
2026-08-31 13:38:07 -04:00
Eman Resu
93e3c83548 lib.modules: avoid creating variables if they'll be unused
The previous comment said "The let-bindings above are lazy and thus
never forced on this branch". Which is true, they're not forced as
values, but they still need to be allocated as thunks. We can avoid
creating them in the first place by moving them down.
2026-08-31 13:38:06 -04:00
Eman Resu
98c0d2511c lib/modules: use zipAttrsWith instead of zipAttrs -> mapAttrs 2026-08-31 13:38:06 -04:00
Johannes Kirschbauer
f01ce79aec lib/modules: inline errorContext string in applyModuleArgs 2026-08-27 14:29:49 +02:00
h7x4
741494f04d lib: replace map (x: x.attr) with catAttrs 2026-08-10 22:34:53 +09:00
Eman Resu
bb50241c60 lib.modules: remove throwIfNot usage
throwIfNot sends our error message through a function call, even if the
error condition doesn't trigger. This requires a lot of thunk allocation
that can be easily avoided.
2026-06-30 21:38:26 -04:00
Johannes Kirschbauer
0cb9aa055c lib/types: remove functor.wrapped after deprecation phase of 2 full releases 2026-06-10 21:24:53 +02:00
Eman Resu
3ec1e90b10 lib/modules: remove warnIf usage
warnIf sends our warning message through a function call, even if the
warning condition doesn't trigger. This requires a lot of thunk
allocation that can be easily avoided.
2026-05-28 00:19:32 -04:00
Robert Hensing
e29bf2412b lib.modules.mapDefinitionValue: init 2026-05-24 15:32:04 +02:00
Johannes Kirschbauer
0bb05b5bd0 lib/modules: document limitations of 'mkRenamedOptionModule' (#470160) 2026-05-14 13:35:43 +00:00
Eman Resu
4a63856f02 lib.modules: avoid override filtering on singleton lists 2026-05-12 11:22:11 -04:00
Eman Resu
b707b446ba lib.modules: use concatMap for override filtering 2026-05-12 11:22:00 -04:00
Lin Jian
e0101cb9cf lib/modules: make comment more clear 2026-05-10 15:47:59 +08:00
Ben Siraphob
b787ee3d40 lib/modules: reduce allocations in evalModules and mergeModules
- When `evalModules` is called without deprecated `args`/`check` parameters (the common case), avoid `modules ++ []` which copies the entire module list for no reason.
- `collectModules` was calling `collectStructuredModules` twice with identical arguments — once for `filterModules` and once for `toGraph`. Share the result via a `let` binding.
- Replace `zipAttrsWith (n: v: v)` with `zipAttrs`
- Replace `concatMap` with `filter`+`map` in `filterOverrides'`

NixOS minimal eval improvement: -5.0% list_concats, -1.2%
nrFunctionCalls, -0.7% nrThunks, -1.0% envs, -1.5% list_bytes.
2026-04-19 09:52:40 -07:00
Ben Siraphob
67c22bba37 lib/modules: skip optional + ++ in evalOptionValue when no default (#510028) 2026-04-14 17:42:41 +00:00
Ben Siraphob
1bec8475a6 lib/modules: skip optional + ++ in evalOptionValue when no default
Replace `(optional (opt ? default) { ... }) ++ defs` with a direct
if/then/else. When the option has no default, this skips both the
list allocation and the ++ concat entirely. Most options do have
defaults, but even then we avoid the `optional` function call overhead
(closure + env allocation).

On NixOS minimal eval: -45K function calls (-0.93%), -3.7K list
concats (-1.93%).
2026-04-14 10:25:34 -07:00
Jörg Thalheim
a3b13a82d4 lib/modules: short-circuit mergeDefinitions for plain singletons
The vast majority of option definitions reaching mergeDefinitions are
singletons whose value carries no _type wrapper (mkIf/mkMerge/
mkOverride/mkOrder). For those, the dischargeProperties ->
filterOverrides' -> sortProperties pipeline is a no-op yet still costs
~125k function calls and ~70k thunks on a minimal NixOS system eval.

Detect this case up front and reuse the input list as
defsFinal'.values, keeping the addErrorContext around the value probe
so error traces still point at the defining file. highestPrio is
defaultOverridePriority by construction.

A single-fold filterOverrides' was prototyped but allocates an attrset
per definition and regressed gc.totalBytes; with the fast path in
place that function is no longer hot enough to matter.

NIX_SHOW_STATS, minimal `nix-instantiate ./nixos -A system`:
  nrFunctionCalls  5490285 -> 5365172  (-125113)
  nrThunks         8182569 -> 8112150   (-70419)
  gc.totalBytes     640.0M -> 635.2M     (-4.8M)
2026-04-12 09:27:11 +02:00
Robert Hensing
ffe82c6a3c lib/modules: deprecate 'mkAliasIfDef' (#470154) 2026-04-07 09:05:53 +00:00
Robert Hensing
ff011b00be lib/modules: Improve errors involving pushDownProperties (#502117) 2026-04-01 16:00:01 +00:00
cinereal
ac0ef82504 lib.modules: default to emptyValue
Signed-off-by: cinereal <cinereal@riseup.net>
2026-03-23 16:04:32 +01:00
dramforever
413f4666cd lib/modules: Improve errors involving pushDownProperties
If an attrset option was given a definition like:

    { system = lib.mkIf true false; }

Before this change, we get the non-explanatory error message:

    error: expected a set but found a Boolean: true

With the stack trace having nothing to do with the module involved.
After this change, we get the better:

    error: In module `[...]', you're trying to define a value of type `bool' [...]

Which names the actual module involved.
2026-03-22 13:53:50 +08:00
İlkecan Bozdoğan
6acae46c84 lib: don't inherit unused functions 2026-03-04 00:10:00 +03:00
İlkecan Bozdoğan
e394a579b0 lib: update type signatures
- concrete types start with uppercase: Int, String, Bool, Derivation,
  etc.
- type variables start with lowercase: a, b, etc.
- list:
  - use `[x]` for homogeneous lists instead of `List x` or `[ x ]`
  - use `List` for heterogeneous lists (not that common in `lib`)
- attr:
  - use `AttrSet` for a generic attribute set type
  - use `{ key1 :: Type1; key2 :: Type2; ... }` for adding signatures
    for known attribute names and types
  - use `{ key1 = value1; key2 = value2; ... }` for adding attributes
    with known literals
  - end with an ellipsis (`...`) if the set can contain unknown
    attributes
  - use `{ [String] :: x }` if all the attributes has the same type `x`
- prefer `Any` over `a` if the latter is not reused
2026-03-04 00:10:00 +03:00
Silvan Mosberger
58b187378d lib/modules: add suggestions to invalid option name errors (#442263) 2026-02-03 19:10:35 +00:00
Johannes Kirschbauer
6ca8927eb0 lib/modules: deprecate 'mkAliasIfDef' 2025-12-14 21:44:28 +01:00
Johannes Kirschbauer
95afd78e86 lib/modules: inline trivial 'mkAliasIfDef' 2025-12-14 21:34:12 +01:00
Johannes Kirschbauer
2916db79f3 lib/modules: remove silent failure of 'mkAliasIfDef' 2025-12-14 21:30:54 +01:00
Johannes Kirschbauer
023e9300bb lib/modules: document limitations of 'mkRenamedOptionModule' 2025-12-12 15:14:38 +01:00