leptos-rs / cargo-leptos

Build tool for Leptos (Rust)
MIT License
315 stars 88 forks source link

nixos build failure #79

Closed polarmutex closed 1 year ago

polarmutex commented 1 year ago

I am trying to build a leptos site to run on Nixos.

The project tries to create a cache folder when compiling the front even with "no_downloads" feature enabled.

I think the solution is to decouple ExeMeta from the cach dir. Where we can access the ExeMeta but not do any cach dir checks.

Thoughts or other paths I can look into, willing to make the changes just want to get your thoughts on fixing it

benwis commented 1 year ago

Hi! I'd love to here more about how you're building it! I have nix devshells and sites working, but it's possible I missed something.

There's also an edge case where if you've downloaded cargo-leptos previously without the --no-downloads flag, it'll still have the .cache folder and error. You'll want to delete that folder if so

polarmutex commented 1 year ago

I am trying to build my leptos site into a derivation. I am using the cargo-leptos nix code you have pending submission to nikpkgs. What I am seeing is the cache folder is created even though with "no_downloads" you never use it. So when you build a derivation it complains as it can not create that cache folder.

the ExeMeta and Exe classes will check for that folder and try to create it even though we set the no_downloads feature. It looks like it is not a straight forward change to try that behavior. Upon looking to create a derivation, I am starting to wonder just to build the server normally and use wasm-pack to build the wasm and merge them to together since this project seems to prioritize filesystem manipulation which nix frowns upon.

benwis commented 1 year ago

I'll have to double check that. I would say it's about the same level of complexity, but that's fair.

benwis commented 1 year ago

@polarmutex If you'd like to try my main branch here: https://github.com/benwis/cargo-leptos with your derivation, I think I configured it to not create the cache dir if the no_downloads feature is enabled

polarmutex commented 1 year ago

I have tried that locally, it gets further. but when compiling the frontend it is creating the folder

benwis commented 1 year ago

Could you post your Nix file ? I'll try it myself and not bug you quite as much. Otherwise I can modify one of my crane files with that pkgdir and see what's going on. It's good to catch it now before the nixpkgs people get around to it

polarmutex commented 1 year ago

https://github.com/polarmutex/website/blob/feat/rust/flake.nix is what I am currently using

might still be some issues in my nix code or might need to try a less complex nix rust flake template

benwis commented 1 year ago

Nice work! This is almost my default Rust Flake template. I'll setup a test env and make sure everything is good

benwis commented 1 year ago

I have made some progress, although it produces a new error. It looks like I need a way to pass additional args to the cargo build command so that we can generate the json file crane uses to find the binaries, or define our own install commands. Option 1 sounds easier to me

polarmutex commented 1 year ago

I just tried your changes and did not see that error (i do have the dependencies as build inputs to crane). Not sure that is why I am avoiding that error.

I did run into an error where the target/site (or the folder you define where the css, wasm, and js build to is not there when the css is moved to the folder. starting to look if we need to do a "mkdir -p" before moving

benwis commented 1 year ago

It might be because I'm trying to build a workspace, but my test.nix is pretty close to yours. Makes sense there'd need to be a manual file copy step for this to work. Let me know if you get it working, and especially if you run into any bugs

polarmutex commented 1 year ago

got to build (and even runs successfully) with your currrent cargo-leptos build

Thanks for looking into this

benwis commented 1 year ago

Alright, I've got it working too. It looks like I may have broken regular operation in some way, but once I figure out why, #80 can be merged and I'll update the nixpkg

benwis commented 1 year ago

@polarmutex A new version of cargo-leptos is out with a version of my proposed changes, and I have updated the Nixpkg PR. Let me know if that has any issues for you

polarmutex commented 1 year ago

v0.1.8 works for me, thanks for the changes