-
Notifications
You must be signed in to change notification settings - Fork 19
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
Build Clojurescript web application #14
Comments
In theory, it should be possible, to combine clj-nix with node2nix, yarn2nix, or any other 2nix for the node ecosystem. Probably some changes will be required, not sure about it. |
@storvik I'm currently using
export HOME=$(pwd)
export JAVA_TOOL_OPTIONS="-Duser.home=$HOME"
${clj-builder} --patch-git-sha $(pwd)
clj -T:build <something-you-want-to-do> I think that in order for this to work it's necessary to invoke |
@storvik I'm basically doing what @kenranunderscore described above. My goal was to not have to call any Javascript programs ( (defn build-cljs
"Buids a single cljs application with shadow-cljs.
The `task` is a task for shadow-cljs.
The `target` is a target key in the `shadow-cljs.edn` file."
[{:keys [task target]}]
(let [basis (b/create-basis {:project "deps.edn"
:aliases [:cljs]})
cmds (b/java-command {:basis basis
:main 'clojure.main
:main-args ["-m" "shadow.cljs.devtools.cli" (str task) (str target)]})]
(b/process cmds))) with a {:deps
{de.active-group/active-clojure {:mvn/version "0.41.0"}}
:paths
["src"]
:aliases
{:build
{:deps
{io.github.clojure/tools.build
{:git/tag "v0.8.2"
:git/sha "ba1a2bf421838802e7bdefc541b41f57582e53b6"}}
:ns-default build}
:cljs
{:extra-deps
{thheller/shadow-cljs {:mvn/version "2.19.0"}
de.active-group/reacl-c {:mvn/version "0.10.8"}}
:extra-paths
["test"]}}} and a {:deps {:aliases [:cljs]}
:builds
{:app
{:target :browser
:output-dir "resources/public/search-client/js"
:asset-path "/search-client/js"
:modules {:main {:entries [your.app.core]}}}}} We use # with-node-modules.nix Given some derivation `drv` and a
# `nodeDefault`, fetch the JavaScript deps and link them into `drv`
# at the start of the build.
{ pkgs, drv, nodeDefault}:
let
# the default.nix is the result of calling node2nix
nodeDependencies = (pkgs.callPackage nodeDefault {
inherit pkgs;
inherit (pkgs) nodejs;
}).nodeDependencies;
in drv.overrideAttrs (old:
old // {
buildPhase = ''
ln -s ${nodeDependencies}/lib/node_modules ./node_modules
'' + old.buildPhase;
}) When you run your build (in this case, something like This is the pipeline I've put together in the last few weeks and I'm sure we could quite easily wrap this in a |
Ok with it, I'd like to add such a nix function ;) @neshtea Thanks for sharing your approach. I don't have too much time, but I'll try to create a dummy shadow-cljs to play with it. In the meantime, a PR for it is very welcome |
If we want to try something like my setup, it would mean to include node2nix in |
@neshtea IMO it is ok to add a dependency to node2nix. node2nix doesn't provide a flake yet, but it's included in nixpkgs, we could use the nixpkgs version since anyways we already depend on it.
I don't like that option too much. While it could have some advantages, I think splitting it into 2 flakes will potentially make it more confusing to the users. I prefer to have it in one flake. One of my goals is to make clj-nix easy to use. One last thought, to support cljs we must add a dependency to one of the npm lockers (node2nix, yarn2nix, npmlock2nix, ...), I don't think there is any other solution. Ideally, we should be agnostic to the npm locker, but I fear that it's not possible, or, in the best case, it will be a lot of extra work. For that reason, I think we should just pick one. node2nix locks mature, I'll go with it. |
Thank you all for pointing me in the right direction. Managed to build my project using the helper function You can decide if you want to close this issue or keep it open to further for further discussion. |
@jlesquembre Thanks for this wonderful project :) In past I used mvn2nix, but clj-nix is much nicer 👍 You wrote
Actually there is one: https://github.com/svanderburg/node2nix/blob/master/flake.nix I had been building clojurescript and nodejs projects with node2nix and yarn2nix. Till now some manual effort and boilerplate is required. Would be nice to package shadow-cljs with clj-nix and include it in nixpkgs. A first quick trial resulted in the error:
I could try to debug it, but maybe one of you knows how to solve it already? |
This would be easier if clj-nix could be hooked into other builds: #69 |
I'm currently working on deploying my Clojurescript web application using Nix and stumbled upon this project when looking around. As this is my first Clojure(script) project and I haven't used Java before everything is new to me atm, and adding the complexity of Nix on top of that does not seem to make things easier.
Typical Clojurescript project consists of some npm dependencies and some Clojure dependencies. When developing I usually run a REPL, Clojure fetches dependencies and everything is smoothly put together with shadow-cljs. In order to build the release version of the webapp shadow-cljs is invoked (before tailwind compiles the css). This works perfectly well in my Nix shell. However when trying to do the same inside
mkDerivation
it fails because of missing network connection.This project seems to aim for a solution to this specific problem, but I cannot figure out how to use it or if it's really possible. I need to package my dependencies from my deps.edn and then use a custom jdk / Clojure which knows where to find my dependencies when invoking
shadow-cljs
. Do you think it's doable?Thank you so much for any help, and for contributing to the Nix community!
The text was updated successfully, but these errors were encountered: