For a HTML/CSS/JS website in Haskell, do I really need a Nix within Nix?

I have an existing cabal project that successfully does Lucid → HTML and Clay → CSS. It uses GHC. Its flake.nix is based on the pkgs.haskell.packages.ghc8107 package set.

How should I add GHCJS (JavaScript) features to this project? Here is the issue:

  • The haskell4nix ecosystem seems somehow “hardwired” for a single GHC (or GHCJS) at the same time. I can’t somehow magically “mix” pkgs.haskell.packages.ghc8107 with pkgs.haskell.packages.ghcjs in the same environment (AFAIK).

If I’m right, what are my options? My current ideas:

  • Create two separate targets in my flake.nix: One for the HTML/CSS stuff (the one I already have) and another one for the JavaScript stuff. I could access those environments like this: nix develop .#htmlcss and nix develop .#javascript. (And similar for nix build.)
  • This is a problem: Since they’re two separate targets, they’ll end up in two separate /store/* paths, so how should I package them into a single directory/package for deployment? (Ideally the .js files should simply end up in the same place as the .css and other static files.)
  • I can think of one solution: Those two Nix targets would go into an outer Nix project, and the outer Nix project would have a postBuild hook to merge those two inner Nix results into a single directory/package for deployment. (I could get this deployable directory/package by just running nix build on the outer Nix.)

Am I on the wrong path?

It should be fine to compose two target into a final build output. For what it’s worth, I am doing this for a rust/wasm project to create a container image with both results: logjuicer/flake.nix

Thanks, this is working well for me. Your logjuicer flake helped (I believe you linked to the wrong thing in your post).

I’m becoming amazed at how… versatile/general Nix is and because of this, there have to be countless ways of doing any given thing!

Oops, I fixed the link. Glad to hear it helped!