A Journey To Deploy Project-M36 On Heroku ( Or To Get Rid Of GHC!)

updated:

Here is the complete recipe including deployment script.


In the beginning, I tried Using Nix to deploy a Haskell web app to Heroku. A good, simple example. But I got a R10 error.


Why is my Node.js app crashing with an R10 error?

The point is that heroku uses $PORT and 0.0.0.0 inside. Otherwise you get `Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch`

So the modification of websocket-server.hs


But the image is too big. There is a dependency of ghc, about 3GB. The deployment is slow.

So first, I tried `nixpkgs.haskell.lib.justStaticExecutables`. ghc is still there.

`nix why-depends` and `nix-tree` shows dependencies and why.

 So I need static haskell executables.


Luckily, there is static-haskell-nix to create static executables.

I add `dontStrip = false;` in my project-m36.nix.(dontStrip doesn't has effect either.)

Nix: Propagate dependency for build-time but NOT for run-time? points out the necessity of `removeReferencesTo`.

So in a new derivation nix file, I add `preFixup = ''remove-references-to -t ${ghc} $out/bin/*'';`

And finally, I got rid of ghc! 


ps. In my final test, `dontPatchELF` doesn't affect anything.


Hope this could be a lifesaver for someone else!


留言

這個網誌中的熱門文章

LeetCode 184. Department Highest Salary