reflex-frp / reflex-platform

A curated package set and set of tools that let you build Haskell packages so they can run on a variety of platforms. reflex-platform is built on top of the nix package manager.

Home Page:https://reflex-frp.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Differing behaviour between shells & build outputs confusion.

asheshambasta opened this issue · comments

Hi all, I've been trying reflex for a first project, and I'm running into some trouble.
I currently have a default.nix:

{ system ? builtins.currentSystem }:
let
  sources = import ./nix/sources.nix;
  rp = import sources.reflex-platform { inherit system; };
in rp.project ({ pkgs, ... }: {
  useWarp = true; 
  withHoogle = false;
  packages = { fht-frontend = ./fht-frontend; 
               fht-data = ./fht-data;
               fht-api = ./fht-api;
               fht-backend = ./fht-backend;
             };
  shells = {
    ghc = [ "fht-frontend" "fht-backend" "fht-data" "fht-api" ];
    ghcjs = [ "fht-frontend" "fht-data" "fht-api" ];
  };

  overrides = self: super: { 
    inherit (sources) bulmex reflex-dom-helpers;
  };

})
  • data: common types shared across the FE and BE.
  • api: common servant API types (also shared)
  • frontend: frontend code
  • backend: backend code

Here's the fht-frontend.cabal: https://gist.github.com/asheshambasta/423fd27b04c37e2a8f14bf84068f139a#file-fht-frontend-cabal
And my sources: https://gist.github.com/asheshambasta/423fd27b04c37e2a8f14bf84068f139a#file-sources-json

Now there are several things which seem confusing to me.

Build outputs in the REPL.

I followed a similar project, reflex-stone,, to bootstrap an experimental project, reflex-stone-playground, of mine, which is a fork of the former.
When I use the reflex-stone-playground, and drop to GHCI, I can import Main and run main, which fires up warp on 3003.

If I do the same in the derived project, I instead am greeted with some DOM based UI instead of a warp server message. Nor does any server start.

What determines this?

  • I've read through useWarp, which is set to true in my default.nix.
  • I've also come across #448 which was fixed AFAICS.
  • I've tried deleting dist* as in #322 and ran nix-shell --run 'cabal new-configure' in the project root, which has no effect.

Overrides.

(After having removed the shell.nix from the original reflex-stone project)

Overrides also seem confusing to me. In my sources.json, I've added reflex-dom-helpers and bulmex to my dependencies (tracked from forked WIP branches). And this mostly works, but depending on the chosen shell, my results are different:

Fails: -A shells.ghcjs

╰─$ nix-shell -A shells.ghcjs
error: Package ‘bulmex-2.0.0’ in /nix/store/p3x4ha4dwj9agifi05wq0vf3m93p3vsx-source/pkgs/development/haskell-modules/hackage-packages.nix:43445 is marked as broken, refusing to evaluate.

a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowBroken = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowBroken = true; }
to ~/.config/nixpkgs/config.nix.

(use '--show-trace' to show detailed location information)

Works: -A shells.ghc

╭─ashesh@quasar-nixos-tr ~/code/asheshambasta/reflex-frp/projects/flowerpower ‹release/0.1.0.0*›
╰─$ nix-shell -A shells.ghc                                                 1 ↵

[nix-shell:~/code/asheshambasta/reflex-frp/projects/flowerpower]$

It seems like the overriden package isn't used in ghcjs, but this is only a guess at this point.


I feel I've made mistakes somewhere but I'm unable to find them.

Some more strange stuff:

So as a workaround, I've now imported JSaddle.Warp.run and wired up main to :

main :: IO ()
main = run 3003 $ liftIO $ mainWidgetWithBulma $ do
  RD.elClass "div" "bar" $ RD.text "hi"
  pure ()

Then doing the following causes the repl session to eventually crash:

*Frontend.Shared Main RD
λ> import Main
*Frontend.Shared Main RD
λ> main
^C^C^C^Ccabal: repl failed for exe:fht-frontend from fht-frontend-0.1.0.0. The build
process terminated with exit code -6

Where mainWidgetWithBulma is:

-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.1/css/bulma.min.css">
mainWidgetWithBulma :: (forall x . Dom.Widget x ()) -> IO ()
mainWidgetWithBulma = Dom.mainWidgetWithHead $ do
  utf8Charset
  responsive
  fontAwesome
  emptyEl "link" bulmaAttrs
 where
  bulmaAttrs =
    ("rel" =: "stylesheet")
      <> ("href" =: "https://cdn.jsdelivr.net/npm/bulma@0.9.1/css/bulma.min.css"
         )

What's also really weird is that firing this up does seem to start a warp server. However, visiting localhost:3003 causes the same behaviour as before: the browser page goes blank and the same window with the dom based GUI pops up.

commented

run 3003 $ liftIO $ mainWidgetWithBulma is wrong, you should use the mainWidgetWithHead with type JSM () (not IO ()) (import from Reflex.Dom.Core and not Reflex.Dom)

With that do run 3003 $ mainWidgetWithBulma

But another option is to get rid of run 3003, as the Dom.mainWidgetWithHead calls run automatically.

@dfordivam Thanks for taking the time to look into this.
However, I'm confused. This post seems to suggest otherwise; which is also what I've set in default.nix.

commented

@dfordivam Thanks for taking the time to look into this.
However, I'm confused. This post seems to suggest otherwise; which is also what I've set in default.nix.

I meant to say the exact same thing as the reddit comment, perhaps the way I wrote is confusing.
Instead of main = run 3003 $ liftIO $ mainWidgetWithBulma, do main = mainWidgetWithBulma

@asheshambasta did that resolve your issue?

@asheshambasta did that resolve your issue?

Hi @ali-abrar, I'm afraid it did not. It turned out that something was wrong in my build process, and I'm totally unsure on what. But I eventually ended up wiring things up again and it did seem to work as expected in the end.
I would've liked to understand why things didn't work as expected, but my workload didn't allow for further investigation.
However, the latest commits are pushed to the repo I shared above; one can revert back to the previous commits to see if the issue can be reproduced.