✨ ARCANUM RUNE DIFFICULTY: Adept Creational

The Abstract Factory Hex

A pure environment conjuration that groups related derivation enchantments.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Abstract Factory
ARCANUM SCHOOL: Conjuration // Pure Environment Hexes
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
{ pkgs ? import <nixpkgs> {} }:

let
  # The Abstract Factory Interface (represented as a set of functions)
  createLinuxEnv = {
    mkCompiler = pkgs.gcc;
    mkDebugger = pkgs.gdb;
  };

  createWindowsEnv = {
    mkCompiler = pkgs.mingwW64;
    mkDebugger = null; # Not natively supported in this hex
  };

  # Client code that uses the factory
  buildArcaneArtifact = factory:
    pkgs.stdenv.mkDerivation {
      name = "arcane-artifact";
      src = ./.;
      buildInputs = [ factory.mkCompiler ] ++ pkgs.lib.optional (factory.mkDebugger != null) factory.mkDebugger;
      buildPhase = ''
        echo "Forging artifact with pure hermetic seals..."
      '';
    };

in
{
  linuxArtifact = buildArcaneArtifact createLinuxEnv;
  windowsArtifact = buildArcaneArtifact createWindowsEnv;
}

The Abstract Factory in Nix is naturally expressed as attribute sets containing families of related derivations or functions. By passing the factory into the client builder, we ensure hermetic purity and cross-platform alchemy.

Runic Tags: #creational #nix #environment #factory