diff --git a/pkgs/development/haskell-modules/configuration-nix.nix b/pkgs/development/haskell-modules/configuration-nix.nix index 92df739b084b..f434334909ef 100644 --- a/pkgs/development/haskell-modules/configuration-nix.nix +++ b/pkgs/development/haskell-modules/configuration-nix.nix @@ -2141,6 +2141,21 @@ builtins.intersectAttrs super { cpython = doJailbreak super.cpython; botan-bindings = super.botan-bindings.override { botan = pkgs.botan3; }; + + # Avoids a cycle by disabling use of the external interpreter for the packages that are dependencies of iserv-proxy. + # These in particular can't rely on template haskell for cross-compilation anyway as they can't rely on iserv-proxy. + inherit + ( + let + noExternalInterpreter = overrideCabal { + enableExternalInterpreter = false; + }; + in + lib.mapAttrs (_: noExternalInterpreter) { inherit (super) iserv-proxy network; } + ) + iserv-proxy + network + ; } // lib.optionalAttrs pkgs.config.allowAliases ( diff --git a/pkgs/development/haskell-modules/configuration-windows.nix b/pkgs/development/haskell-modules/configuration-windows.nix index bef866162481..3dd93aa5c17f 100644 --- a/pkgs/development/haskell-modules/configuration-windows.nix +++ b/pkgs/development/haskell-modules/configuration-windows.nix @@ -14,6 +14,23 @@ with haskellLib; else super.network; + # Avoids a cycle by disabling use of the external interpreter for the packages that are dependencies of iserv-proxy. + # See configuration-nix.nix, where iserv-proxy and network are handled. + # On Windows, network depends on temporary (see above), which depends on random, which depends on splitmix. + inherit + ( + let + noExternalInterpreter = overrideCabal { + enableExternalInterpreter = false; + }; + in + lib.mapAttrs (_: noExternalInterpreter) { inherit (super) random splitmix temporary; } + ) + random + splitmix + temporary + ; + # https://github.com/fpco/streaming-commons/pull/84 streaming-commons = appendPatch (fetchpatch { name = "fix-headers-case.patch"; diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index 5cebe4aec5d0..0d488ed48ef2 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -10,12 +10,60 @@ runCommandCC, ghcWithHoogle, ghcWithPackages, + haskellLib, + iserv-proxy, nodejs, + writeShellScriptBin, }: let isCross = stdenv.buildPlatform != stdenv.hostPlatform; + crossSupport = rec { + emulator = stdenv.hostPlatform.emulator buildPackages; + + canProxyTH = + # iserv-proxy currently does not build on GHC 9.6 + lib.versionAtLeast ghc.version "9.8" && stdenv.hostPlatform.emulatorAvailable buildPackages; + + iservWrapper = + let + wrapperScript = + enableProfiling: + let + overrides = haskellLib.overrideCabal { + enableLibraryProfiling = enableProfiling; + enableExecutableProfiling = enableProfiling; + }; + buildProxy = lib.getExe' iserv-proxy.build "iserv-proxy"; + hostProxy = lib.getExe' (overrides iserv-proxy.host) "iserv-proxy-interpreter"; + in + buildPackages.writeShellScriptBin ("iserv-wrapper" + lib.optionalString enableProfiling "-prof") '' + set -euo pipefail + PORT=$((5000 + $RANDOM % 5000)) + (>&2 echo "---> Starting interpreter on port $PORT") + ${emulator} ${hostProxy} tmp $PORT & + RISERV_PID="$!" + trap "kill $RISERV_PID" EXIT # Needs cleanup when building without sandbox + ${buildProxy} $@ 127.0.0.1 "$PORT" + (>&2 echo "---> killing interpreter...") + ''; + + # GHC will add `-prof` to the external interpreter when doing a profiled build. + # Since a single derivation can build with both profiling and non-profiling versions + # we need both versions made available + both = buildPackages.symlinkJoin { + name = "iserv-wrapper-both"; + paths = map wrapperScript [ + false + true + ]; + }; + + in + "${both}/bin/iserv-wrapper"; + }; + # Pass the "wrong" C compiler rather than none at all so packages that just # use the C preproccessor still work, see # https://github.com/haskell/cabal/issues/6466 for details. @@ -205,10 +253,15 @@ in # of `meta.pkgConfigModules`. This option defaults to false for now, since # this metadata is far from complete in nixpkgs. __onlyPropagateKnownPkgConfigModules ? false, + + enableExternalInterpreter ? isCross && crossSupport.canProxyTH, }@args: assert editedCabalFile != null -> revision != null; +# We only use iserv-proxy for the external interpreter +assert enableExternalInterpreter -> crossSupport.canProxyTH; + # --enable-static does not work on windows. This is a bug in GHC. # --enable-static will pass -staticlib to ghc, which only works for mach-o and elf. assert stdenv.hostPlatform.isWindows -> enableStaticLibraries == false; @@ -298,7 +351,15 @@ let "--hsc2hs-option=--cross-compile" (optionalString enableHsc2hsViaAsm "--hsc2hs-option=--via-asm") ] - ++ optional (allPkgconfigDepends != [ ]) "--with-pkg-config=${pkg-config.targetPrefix}pkg-config"; + ++ optional (allPkgconfigDepends != [ ]) "--with-pkg-config=${pkg-config.targetPrefix}pkg-config" + + ++ optionals enableExternalInterpreter ( + map (opt: "--ghc-option=${opt}") [ + "-fexternal-interpreter" + "-pgmi" + crossSupport.iservWrapper + ] + ); makeGhcOptions = opts: lib.concatStringsSep " " (map (opt: "--ghc-option=${opt}") opts); diff --git a/pkgs/development/haskell-modules/make-package-set.nix b/pkgs/development/haskell-modules/make-package-set.nix index 36d0fe878970..74369bf2ea67 100644 --- a/pkgs/development/haskell-modules/make-package-set.nix +++ b/pkgs/development/haskell-modules/make-package-set.nix @@ -49,7 +49,7 @@ let inherit (haskellLib) overrideCabal; mkDerivationImpl = pkgs.callPackage ./generic-builder.nix { - inherit stdenv; + inherit stdenv haskellLib; nodejs = buildPackages.nodejs-slim; inherit (self) buildHaskellPackages @@ -57,6 +57,10 @@ let ghcWithHoogle ghcWithPackages ; + iserv-proxy = { + build = buildHaskellPackages.iserv-proxy; + host = self.iserv-proxy; + }; inherit (self.buildHaskellPackages) jailbreak-cabal; hscolour = overrideCabal (drv: { isLibrary = false; diff --git a/pkgs/top-level/release-haskell.nix b/pkgs/top-level/release-haskell.nix index 2fc2fd113afc..4ebe57961762 100644 --- a/pkgs/top-level/release-haskell.nix +++ b/pkgs/top-level/release-haskell.nix @@ -520,7 +520,24 @@ let ghc948 ; }; - }; + } + // + removePlatforms + [ + # Testing cross from x86_64-linux + "aarch64-darwin" + "aarch64-linux" + "x86_64-darwin" + ] + { + haskellPackages = { + inherit (packagePlatforms pkgs.pkgsCross.aarch64-multiplatform.haskellPackages) + ghc + hello + th-orphans + ; + }; + }; }; }) (versionedCompilerJobs {