How can I get the GHC with JS backend enabled?

This appears to be working. I haven’t compiled anything yet, but invoking the GHCwith --print-target-platform results in javascript-unknown-ghcjs.

Do note that it seems like if we change the default platform settings the derivation will output a differently named binary. Instead of a “clean” ghc we get javascript-unknown-ghcjs-ghc. Which is convenient, because I don’t have to tweak the derivations further in order to be able to have both the native GHC and the JS enabled GHC simultaneously.

I’ve added a ghcjs alias for convenience:

{
  description = "A pristine single page web app example written in Haskell.";

  inputs =
  {
    nixpkgs.url = "github:nixos/nixpkgs";
  };

  outputs = { self , nixpkgs }:
  {
    devShells.x86_64-linux.default = with import nixpkgs { system = "x86_64-linux"; }; with pkgs;
    let
      ghc = haskell.compiler.ghc9101;
      ghc-js = haskell.compiler.ghc9101.override
      {
        stdenv = stdenv.override { targetPlatform = pkgsCross.ghcjs.stdenv.targetPlatform; };
      };
    in
      mkShell
      {
        packages = [ ghc ghc-js cabal-install ghcid hello ];
        shellHook = "alias ghcjs=javascript-unknown-ghcjs-ghc";
      };
  };
}