Skip to content

WIP: Switch to ghc (js) 9.12 via nixpkgs #846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from

Conversation

maralorn
Copy link
Contributor

This does probably drop Android and iOS support, otherwise it works on examples projects.

@arthurl
Copy link

arthurl commented Jun 8, 2025

Hi, is reflex-dom compiling on your branch? I used the work-on script on a sample project, and got this error:

error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:37:12:
           36|
           37|   strict = derivationStrict drvAttrs;
             |            ^
           38|

       … while evaluating derivation 'ghc-shell-for-reflex-template-0.1'
         whose name attribute is located at /nix/store/7a31bwdzpywkr8rw5cspqcw5wd0fxr0d-source/pkgs/stdenv/generic/make-derivation.nix:439:13

       … while evaluating attribute 'NIX_GHC' of derivation 'ghc-shell-for-reflex-template-0.1'
         at /nix/store/7a31bwdzpywkr8rw5cspqcw5wd0fxr0d-source/pkgs/development/haskell-modules/generic-builder.nix:999:13:
          998|             ) "${buildPackages.glibcLocales}/lib/locale/locale-archive";
          999|             "NIX_${ghcCommandCaps}" = "${ghcEnv}/bin/${ghcCommand}";
             |             ^
         1000|             "NIX_${ghcCommandCaps}PKG" = "${ghcEnv}/bin/${ghcCommand}-pkg";

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: attribute 'sharedLibrary' missing
       at /nix/store/7a31bwdzpywkr8rw5cspqcw5wd0fxr0d-source/pkgs/development/libraries/gobject-introspection/default.nix:174:33:
          173|   postCheck = ''
          174|     rm $out/lib/libregress-1.0${stdenv.targetPlatform.extensions.sharedLibrary}
             |                                 ^
          175|   '';

Looking at the full trace suggest that reflex-dom is the problem:

error:
       [...]
       … while evaluating derivation 'ghc-shell-for-reflex-template-0.1'
       [...]
       … while evaluating derivation 'javascript-unknown-ghcjs-ghc-native-bignum-9.12.2-with-packages'
       [...]
       … while evaluating derivation 'reflex-dom-0.6.3.4'
       [...]
       … while evaluating derivation 'jsaddle-webkit2gtk-0.9.9.3'
       [...]
       … while evaluating derivation 'gi-gio-2.0.37'
       [...]
       … while evaluating derivation 'gi-glib-2.0.30'
       [...]
       … while evaluating derivation 'haskell-gi-0.26.15'
       [...]
       … while evaluating derivation 'gobject-introspection-wrapped-1.82.0'
       [...]
       … while evaluating derivation 'gobject-introspection-1.82.0'
       [...]

(I'm new to reflex, so maybe I'm just doing something stupid.)

@maralorn
Copy link
Contributor Author

Hey. Yes, reflex-dom compiles on my branch. However I haven’t tried the work-on script and it might need adapting.

@arthurl
Copy link

arthurl commented Jun 10, 2025

Hey. Yes, reflex-dom compiles on my branch. However I haven’t tried the work-on script and it might need adapting.

Just to confirm, is that with GHCJS?

@arthurl
Copy link

arthurl commented Jun 10, 2025

It probably doesn’t have anything to do with the work-on script; I tried the nix project setup as described here (https://github.com/reflex-frp/reflex-platform/blob/develop/docs/project-development.rst), and reflex / reflex-dom compiles just fine with GHC, but not GHCJS, yielding the same error as above.

@maralorn
Copy link
Contributor Author

Yes I have built and executed a whole reflex-dom project with the js backend.

Your trace suggests that nix is trying to build libraries which should only be built for ghc native not for the js target. Which command are you running?

@maralorn maralorn force-pushed the maralorn/new-backend branch from f3305ff to fd30696 Compare June 10, 2025 13:24
@arthurl
Copy link

arthurl commented Jun 10, 2025

Your trace suggests that nix is trying to build libraries which should only be built for ghc native not for the js target. Which command are you running?

I’ve made a minimal reflex project template (which is quite literally just this official guide) here: https://github.com/arthurl/reflex-project-template

If you clone the repository and run nix-shell default.nix -A shells.ghcjs, you should be able to reproduce the error.

(On the other hand, nix-shell default.nix -A shells.ghc does work, and the subsequent cabal build all succeeds.)

Am I missing something obvious? To be clear, the above does work on the master branch of reflex-platform.

@alexfmpe
Copy link
Member

Sounds like both things are the same error - the project shell setup uses the same thing as workOn under the hood.

workOnMulti {

I believe this all pre-dates shellFor which is probably what we want in the long run, assuming it works for cross or at least ghcjs.

@maralorn
Copy link
Contributor Author

I never used -A shells.ghjs and am not sure what it is for. Maybe you can try -A ghcjs.frontend?

@arthurl
Copy link

arthurl commented Jun 10, 2025

I never used -A shells.ghjs and am not sure what it is for. Maybe you can try -A ghcjs.frontend?

Huh, to my sheer surprise, it works! (To be clear, nix-build -A ghcjs.frontend succeeds.)

nix-shell default.nix -A shells.ghcjs just gives you a shell with ghcjs and cabal, for development. I don’t know enough about reflex-platform to figure out why this fails, while directly building the entire project with nix succeeds (since nix obviously has to use ghcjs to build the project).

What do you use for your dev environment then? nix-build doesn’t give you incremental builds like cabal does, which sort of suck if you’re actively modifying and re-compiling the project.

@alexfmpe
Copy link
Member

I never used -A shells.ghcjs and am not sure what it is for.

It used to be for doing incremental cabal builds with ghcjs (e.g. fixing imports), debug (peek at ghc-pkg), etc.

@arthurl
Copy link

arthurl commented Jun 10, 2025

Actually, nix-build -A ghcjs.frontend does not work either, though it is a different problem. As mentioned in my previous post, the build succeeds, but when I opened the file bin/frontend.jsexe/index.html, I get the following error in the dev console in chromium:

all.js:149170 Aborted('HEAP8' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ))
abort @ all.js:149170

all.js:149188 Uncaught (in promise) RuntimeError: Aborted('HEAP8' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ))
    at abort (all.js:149188:11)
    at Object.get (all.js:149013:9)
    at h$initEmscriptenHeap (all.js:13531:35)
    at Module.onRuntimeInitialized (all.js:150267:1)
    at doRun (all.js:150201:37)
    at run (all.js:150217:5)
    at removeRunDependency (all.js:149158:7)
    at receiveInstance (all.js:149299:5)
    at receiveInstantiationResult (all.js:149317:12)
    at createWasm (all.js:149343:19)

(The above issue does not appear on the master branch of reflex-platform.)

@maralorn
Copy link
Contributor Author

Yes, that is an issue I am working on.

See obsidiansystems/obelisk@c0bbd8f for more and a workaround.

@arthurl
Copy link

arthurl commented Jun 10, 2025

See obsidiansystems/obelisk@c0bbd8f for more and a workaround.

That works, thanks!

maralorn added 8 commits June 11, 2025 11:56
It somehow creates an infinite recursion, also only seems to be relevant for cross compilation
Causes infinite recursion

According to @alexfmpe unnecessary since: NixOS/nixpkgs#355543
Invalidates cache for unknown reason
reflex-vty is broken in nixpkgs
broken on ghc 9.12
@maralorn maralorn force-pushed the maralorn/new-backend branch from fd30696 to 88792de Compare June 11, 2025 11:18
@maralorn
Copy link
Contributor Author

After inspecting the reflex-packages overlay I guess we will need to go through that more careful again to make sure that overlay expects all flags that r-p is exposing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants