From d30ae1657f46855a65d0994bf1c61f454356ff9e Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 14 Nov 2025 22:20:09 -0500 Subject: Fix module compilation: use custom builder to avoid GHC setup hooks The haskell.ghcWith package has setup hooks that override buildPhase even when explicitly set. Solution: use custom builder = stdenv.shell with args instead of relying on mkDerivation phases. Changes: - Module derivations: Use custom builder with single -c script - Combines unpack, build, and install into one script - Explicitly call ghc with full path to avoid hook interference - Remove unused objectPaths computation (now using ghc --make with source) This fixes builds for Omni/Lint.hs, Omni/Task.hs, and all other Haskell targets with complex dependency graphs. --- Omni/Bild/Builder.nix | 58 +++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) (limited to 'Omni') diff --git a/Omni/Bild/Builder.nix b/Omni/Bild/Builder.nix index 6610a27..3328b7d 100644 --- a/Omni/Bild/Builder.nix +++ b/Omni/Bild/Builder.nix @@ -185,28 +185,33 @@ with bild; let name = "hs-mod-${sanitize modName}"; src = mkModuleSrc node.nodePath; inherit CODEROOT; - buildInputs = sysdeps_ ++ [ghcPkg] ++ depDrvs; - buildPhase = let - copyDeps = - lib.strings.concatMapStringsSep "\n" (d: '' - cp -rL ${d}/hidir/. hidir/ 2>/dev/null || true - '') - depDrvs; - in '' - mkdir -p hidir odir - ${copyDeps} - chmod -R +w hidir || true - ghc -c \ - -Wall -Werror -haddock -Winvalid-haddock \ - -i. -ihidir \ - -odir odir -hidir hidir \ - ${node.nodePath} - ''; - installPhase = '' - mkdir -p $out/hidir $out/odir - cp -r hidir/* $out/hidir/ || true - cp -r odir/* $out/odir/ || true - ''; + nativeBuildInputs = []; + buildInputs = sysdeps_ ++ depDrvs; + builder = "${stdenv.shell}"; + args = [ + "-c" + (let + copyDeps = + lib.strings.concatMapStringsSep "\n" (d: '' + cp -rL ${d}/hidir/. hidir/ 2>/dev/null || true + '') + depDrvs; + in '' + set -eu + cd $sourceRoot + mkdir -p hidir odir + ${copyDeps} + chmod -R +w hidir || true + ${ghcPkg}/bin/ghc -c \ + -Wall -Werror -haddock -Winvalid-haddock \ + -i. -ihidir \ + -odir odir -hidir hidir \ + ${node.nodePath} + mkdir -p $out/hidir $out/odir + cp -r hidir/* $out/hidir/ || true + cp -r odir/* $out/odir/ || true + '') + ]; }; # Recursive attrset of all module derivations @@ -215,11 +220,6 @@ with bild; let (modName: node: mkModuleDrv modName node (map (dep: builtins.getAttr dep self) node.nodeImports)) graph.graphModules); - - # Compute exact object paths at eval time - moduleToObjPath = modName: drv: "${drv}/odir/${lib.strings.replaceStrings ["."] ["/"] modName}.o"; - objectPaths = - lib.attrsets.mapAttrsToList moduleToObjPath modules; in # Final link derivation stdenv.mkDerivation rec { @@ -230,8 +230,7 @@ with bild; let pkgFlags = lib.strings.concatMapStringsSep " " (p: "-package ${p}") target.langdeps; copyHiFiles = lib.strings.concatMapStringsSep "\n" (drv: "cp -rL ${drv}/hidir/. . 2>/dev/null || true") (lib.attrsets.attrValues modules); in '' - set -eux - echo "Starting custom link phase with ${builtins.toString (builtins.length objectPaths)} object files" + set -eu ${copyHiFiles} chmod -R +w . || true ${ghcPkg}/bin/ghc --make \ @@ -241,7 +240,6 @@ with bild; let -threaded \ -o ${name} \ ${lib.optionalString (target.mainModule != "Main") "-main-is ${target.mainModule}"} - echo "Link completed successfully" ''; installPhase = '' install -D ${name} $out/bin/${name} -- cgit v1.2.3