Skip to main content

Module module_compiler

Module module_compiler 

Source
Expand description

Module-system compiler — extracts the typed ModuleNode shape from a raw AstGraph.

§What this does today

Pattern-recognizes the canonical NixOS / nix-darwin / home-manager module shape:

{ config, lib, pkgs, ... }:
{
  imports = [ ./profile.nix ./component.nix ];
  options.services.atticd.enable = mkOption { type = bool; default = false; };
  config.services.atticd.enable = mkForce true;
  config.boot.kernelParams = mkIf config.services.atticd.enable [ "amd_pstate=active" ];
}

and emits typed OptionDecl / ConfigSetter / ImportEdge lists that fill a ModuleNode. Slice analysis walks each setter body collecting every Select(config, .a.b.c) reference — this is the “input slice” the worker/wrapper-split fixed-point solver fires against.

§What this does NOT do (queued)

  1. Defunctionalization — higher-order setter functions stay AST-pointer-only for now. The full transform lands when the bytecode VM grows the supporting opcodes.
  2. NbE (normalize-by-evaluation) on the compiled closure. Cache-key uses the ModuleGraph’s BLAKE3 (good enough for structural change detection); NbE-driven canonicalization adds structural-equality across alpha-renaming etc.
  3. Slice-keyed re-firing execution — the data is captured today; the solver that fires only changed-slice setters lives in the eval-engine integration ship.
  4. Full topological discovery via resolved imports — today’s builder accepts modules in caller order. Symmetric to the follows-resolution shape lockfile_graph uses; lands when import-target resolution gets a typed pass.

§Why this exists

Cppnix re-evaluates the entire module fixed point on every rebuild. Tvix hasn’t tackled the module system. The first step toward making nixos-rebuild warm-path sub-second is lifting the module shape into the typed substrate — exactly what this compiler does. The IR (shipped in 8d07d77) is the anchor; this compiler fills it; the eval-engine ship fires it.

Enums§

ModuleCompilerError
Errors from the compiler.

Functions§

collect_config_read_slice
Public slice analysis entry — caller passes the AST + a body node id; receives the deduplicated list of config.* paths read.
compile_module
Compile one module’s AstGraph into a typed ModuleNode.