✨ ARCANUM RUNE DIFFICULTY: Adept Structural

The Decorator Hex

Dynamically wrapping derivations to add behaviors.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Transmutation // Pure Environment Hexes
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
let
  # Base component
  baseDerivation = {
    name = "pure-core";
    buildInputs = [ "gcc" ];
  };

  # Decorator 1: Add debug symbols
  withDebug = drv: drv // {
    name = "''${drv.name}-debug";
    buildInputs = drv.buildInputs ++ [ "gdb" ];
  };

  # Decorator 2: Add profiling
  withProfiling = drv: drv // {
    name = "''${drv.name}-profiled";
    buildInputs = drv.buildInputs ++ [ "valgrind" ];
  };

  # Composition of decorators
  finalDerivation = withProfiling (withDebug baseDerivation);
in
finalDerivation

The Decorator pattern in Nix is executed via function composition and attribute updates. Instead of modifying the base derivation directly, wrappers augment the inputs and attributes, effectively composing new magical properties on top of the original hermetic seal.

Runic Tags: #structural #decorator #nix #wrappers