Hello!
I have a project that has both a Haskell backend and an Elm frontend part, and they are in a single repo. The backend also has a component that generates some code that is used by the frontend.
(Note: All the code I’m talking about here is available in my github too: GitHub - TheOddler/elmder: Trying out some elm stuff)
So my repo looks something like this (v
is an open folder, >
a closed one):
v backend
> src
> tests
> elm-gen
package.yaml
v frontend
v src
> Generated
Main.elm
...more elm files
elm.json
package.json
flake.nix
When I run stack run elm-gen
in the backend folder it’ll generate the needed Elm code in the Generated
folder.
And I have a build
script that runs parcel build src/index.html
in package.json
to build the frontend.
Then in my flake.nix I use buildNpmPackage
to build the frontend in nix:
packages.frontend = pkgs.buildNpmPackage {
name = "elmder";
src = ./frontend;
preBuild = ''
(cd ../backend && stack run elm-gen)
'';
... some more stuff that I don't think is relevant for this issue
};
When I run this, it complains ../backend
does not exist. I don’t know the details, but it seems to copy whatever folder I specify in src
somewhere to then build that.
Fair enough, however when I change src = ./.;
it then gives the error that the folder does not contain package-lock.json
file.
I found I can also set the sourceRoot
, so I tried that, setting sourceRoot = ./frontend;
, but then I get a bunch of errors stating chmod: changing permissions of '/nix/store/...-frontend/src/....elm': Operation not permitted
I tried a bunch of other combinations of src
, sourceRoot
, also tried npmRoot
I believe, but nothing seems to work.
Is there a proper way of doing something like this? Do I need to restructure my project so the package-lock.json
is in the root? Is there a way to keep it in the frontend
folder and keep the frontend and backend separated more like this?
I mentioned it at the start as well, but just in case, all the code is available at GitHub - TheOddler/elmder: Trying out some elm stuff in case I left out relevant parts (but don’t feel obligated to look at it, just asking here is good too)
Thanks!