I’m trying to find a way to include a PureScript frontend in a project that uses Nix to build. On here I found references to both spago2nix and purs-nix and opted to try out the former first (the second being a flake put me off since I haven’t any knowledge of that yet). Setting up a dev environment with spago2nix was simple enough, but writing a derivation to be able to nix-build wasn’t.
I did write an issue asking for a more complete example in the project (issue #48) but I thought I’d ask here too in an attempt to widen the net.
Any suggestions or pointers will be much appreciated.
I’m no Nix expert (even though I’d like to be one day!), but recently I got purs-tidy using spago2nix in easy-purescript-nix's derivation. I think that might be an okay place to start as it does the whole build cycle to compile and distribute an executable NodeJS script.
$ spago2nix generate 4 -- --config ./spago.dhall
This will give you a spago-packages.nix file you can import into your Nix project which will download and put the PureScript packages from their corresponding Git forge into your Nix store. The generated file also provides you some tools/functions for consuming those packages in your Nix derivation.
I’m not sure if you read some outdated text or just saw flake.nix in the repo (if it’s the former please do let me know), but purs-nix is compatible with nix stable as well
Thanks, that got me a bit closer to the goal. I have to say though that your default.nix is much different from the instructions on the spago2nix site, I don’t think I’d ever have come up with that myself.
I am aware that purs-nix is usable with nix stable as well. However, I’m not too hopeful that I’ll work out how to use it. The base is a flake and the instructions for setting it up seem geared towards getting a shell with tools while I want to set up a derivation that I can fit into my already existing project.
The main reason I built purs-nix actually was because I wanted an easy way to incorporate PureScript projects into bigger nix builds. The purs-nix command in the shell came later. For example, in purs-nix you can get the bundle for the module Main by simply using modules.Main.bundle {}. Perhaps I need to make this more clear in the README.
In my experience, spago doesn’t play very well with nix. I believe this error is caused by it trying to set up a global cache. There are flags to disable caching, I would try using them. If that doesn’t work you can set it so that it makes the cache inside the nix build I believe, but I can’t remember how off the top of my head.
edit (I read more): actually if you’re saying it works locally I might be wrong. When this happened to me it didn’t work locally. But maybe nix on you local machine has sandboxing turned off and on your CI it’s turned on?
I went ahead and packaged purescript-tidy so people could compare the two approaches side by side. You can view it here.
Also, I now probably understand why you thought it was more oriented towards making a shell - For nix stable, I only give an example shell.nix. I’ll make a note to fix that
(also thanks to @toastal for exposing me to substituteInPlace)
General comments: While I like reading the version from the package.json, one of these packages at one time forgot to update their version in cabal file or package.json; as a result, I think kind of prefer overwriting the version from the git tag. This ruined my CI at one point, but I could be swayed either way though – it may not be what non-Nix users would expect. And with your merge request to easy-purescript-nix (regardless of it not being reviewed ), do we think maybe Flakes are a better endorsement in packaging? I kinda feel like manually updating pinned versions like this is tiresome and difficult to manage versus nix flake update.
I have to say though that I can’t follow it at all I’m not sure if it’s a result of purs-nix, but at a glance it’s really hard to see how to modify that example for another package.
The comment about the global cache that @ursi made above was indeed correct. I added --global-cache skip to the arguments of spago bundle-app and now the CI service is happily building a bundle