diff --git a/nix/deps/clojure/default.nix b/nix/deps/clojure/default.nix new file mode 100644 index 0000000000..b3b1379f2d --- /dev/null +++ b/nix/deps/clojure/default.nix @@ -0,0 +1,60 @@ +{ stdenv, lib, writeShellScriptBin, fetchurl }: + +let + inherit (lib) + removeSuffix optionalString splitString concatMapStrings + attrByPath attrValues last makeOverridable; + + # load dependencies + deps = import ./deps.nix; + + # some .jar files have an `-aot` suffix that doesn't work for .pom files + getPOM = jarUrl: "${removeSuffix "-aot" jarUrl}.pom"; + + script = writeShellScriptBin "create-local-maven-repo" ('' + mkdir -p $out + cd $out + '' + + (concatMapStrings (dep: + let + url = "${dep.host}/${dep.path}"; + pom = { + sha1 = attrByPath [ "pom" "sha1" ] "" dep; + sha256 = attrByPath [ "pom" "sha256" ] "" dep; + }; + pom-download = optionalString (pom.sha256 != "") ( + fetchurl { url = getPOM url; inherit (pom) sha256; } + ); + jar = { + sha1 = attrByPath [ "jar" "sha1" ] "" dep; + sha256 = attrByPath [ "jar" "sha256" ] "" dep; + }; + jar-download = optionalString (jar.sha256 != "") ( + fetchurl { url = "${url}.${dep.type}"; inherit (jar) sha256; } + ); + fileName = last (splitString "/" dep.path); + directory = removeSuffix fileName dep.path; + in + '' + mkdir -p ${directory} + + ${optionalString (pom-download != "") '' + ln -s "${pom-download}" "${getPOM dep.path}" + ''} + ${optionalString (pom.sha1 != "") '' + echo "${pom.sha1}" > "${getPOM dep.path}.sha1" + ''} + ${optionalString (jar-download != "") '' + ln -s "${jar-download}" "${dep.path}.${dep.type}" + ''} + ${optionalString (jar.sha1 != "") '' + echo "${jar.sha1}" > "${dep.path}.${dep.type}.sha1" + ''} + '') + (attrValues deps))); + +in makeOverridable stdenv.mkDerivation { + name = "status-react-clojure-deps"; + phases = [ "buildPhase" ]; + buildPhase = "${script}/bin/create-local-maven-repo"; +} diff --git a/nix/deps/clojure/deps.nix b/nix/deps/clojure/deps.nix index a2efbd6fed..474b772085 100644 --- a/nix/deps/clojure/deps.nix +++ b/nix/deps/clojure/deps.nix @@ -1,5 +1,4 @@ # Auto-generated by /nix/deps/clojure/generate.sh -{ }: let repos = rec { diff --git a/nix/deps/clojure/generate.sh b/nix/deps/clojure/generate.sh index 2a5ad84537..b8b899f268 100755 --- a/nix/deps/clojure/generate.sh +++ b/nix/deps/clojure/generate.sh @@ -44,8 +44,6 @@ function get_nix_sha() { function get_deps_header() { echo "# Auto-generated by /nix/deps/clojure/generate.sh -{ }: - let repos = rec { central = \"https://repo1.maven.org/maven2\"; diff --git a/nix/mobile/android/default.nix b/nix/mobile/android/default.nix index cd8585c351..bf85f0a0ab 100644 --- a/nix/mobile/android/default.nix +++ b/nix/mobile/android/default.nix @@ -5,10 +5,8 @@ let callPackage = newScope { inherit localMavenRepoBuilder projectNodePackage; }; - clojureDeps = import ../../deps/clojure/deps.nix { }; - # Import a jsbundle compiled out of clojure codebase - jsbundle = callPackage ./jsbundle { inherit clojureDeps; }; + jsbundle = callPackage ./jsbundle { }; # Import a patched version of watchman (important for sandboxed builds on macOS) watchmanFactory = callPackage ./watchman.nix { }; diff --git a/nix/mobile/android/jsbundle/default.nix b/nix/mobile/android/jsbundle/default.nix index 35fcc16157..ac121f50f1 100644 --- a/nix/mobile/android/jsbundle/default.nix +++ b/nix/mobile/android/jsbundle/default.nix @@ -3,12 +3,10 @@ # { target ? "android", - stdenv, lib, clojure, nodejs, bash, git, openjdk, - clojureDeps, localMavenRepoBuilder, projectNodePackage }: + stdenv, lib, deps, clojure, nodejs, bash, git, openjdk, + localMavenRepoBuilder, projectNodePackage }: -let - clojureDepsLocal = localMavenRepoBuilder "clojure-project-deps" clojureDeps; -in stdenv.mkDerivation { +stdenv.mkDerivation { name = "status-react-build-jsbundle-${target}"; src = let path = ./../../../..; @@ -45,7 +43,7 @@ in stdenv.mkDerivation { substituteInPlace shadow-cljs.edn \ --replace '${anchor}' \ '${anchor} - :maven {:local-repo "${clojureDepsLocal}"}' + :maven {:local-repo "${deps.clojure}"}' ''; configurePhase = '' # Symlink Node.js modules to build directory @@ -58,7 +56,7 @@ in stdenv.mkDerivation { buildPhase = '' # Assemble CLASSPATH from available clojure dependencies. # We append 'src' so it can find the local sources. - export CLASS_PATH="$(find ${clojureDepsLocal} -iname '*.jar' | tr '\n' ':')src" + export CLASS_PATH="$(find ${deps.clojure} -iname '*.jar' | tr '\n' ':')src" # target must be one of the builds defined in shadow-cljs.edn java -cp "$CLASS_PATH" clojure.main -m shadow.cljs.devtools.cli release ${target} diff --git a/nix/overlay.nix b/nix/overlay.nix index da6cec3ab9..1551e85d9c 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -20,6 +20,11 @@ in { inherit (self) config; }); + # Project dependencies + deps = { + clojure = callPackage ./deps/clojure { }; + }; + # Android environement androidEnvCustom = callPackage ./mobile/android/sdk { }; androidPkgs = self.androidEnvCustom.licensedPkgs;