2020-05-06 12:39:49 +02:00
|
|
|
#
|
2019-09-07 14:57:22 +02:00
|
|
|
# This Nix expression builds the js files for the current repository given a node modules Nix expression
|
2019-06-04 18:50:29 +02:00
|
|
|
#
|
|
|
|
|
2020-05-14 13:58:05 +02:00
|
|
|
{ stdenv, lib, deps, pkgs }:
|
2019-06-04 18:50:29 +02:00
|
|
|
|
2020-10-05 14:53:20 +02:00
|
|
|
# Path to the file containing secret environment variables
|
|
|
|
{ secretsFile ? "" }:
|
|
|
|
|
2020-05-06 12:29:02 +02:00
|
|
|
stdenv.mkDerivation {
|
2020-05-14 13:58:05 +02:00
|
|
|
name = "status-react-build-jsbundle-android";
|
2019-06-04 18:50:29 +02:00
|
|
|
src =
|
2019-11-29 11:20:08 +01:00
|
|
|
let path = ./../../../..;
|
2020-05-16 01:08:10 +02:00
|
|
|
# We use builtins.path so that we can name the resulting derivation,
|
|
|
|
# otherwise the name would be taken from the checkout directory,
|
|
|
|
# which is outside of our control inherit path;
|
|
|
|
in builtins.path {
|
2019-06-04 18:50:29 +02:00
|
|
|
inherit path;
|
2019-07-15 18:34:33 +02:00
|
|
|
name = "status-react-source-jsbundle";
|
2019-06-04 18:50:29 +02:00
|
|
|
filter =
|
2020-05-16 01:08:10 +02:00
|
|
|
# Keep this filter as restrictive as possible in order to avoid
|
|
|
|
# unnecessary rebuilds and limit closure size
|
2020-04-26 14:40:06 +02:00
|
|
|
lib.mkFilter {
|
2020-04-08 15:06:40 +02:00
|
|
|
root = path;
|
|
|
|
ignoreVCS = false;
|
2020-03-30 09:45:25 +02:00
|
|
|
include = [
|
2020-04-08 15:06:40 +02:00
|
|
|
"VERSION" "BUILD_NUMBER" "scripts/version/.*"
|
2020-06-03 21:47:01 +02:00
|
|
|
"src/.*" "shadow-cljs.edn" "index.js"
|
2020-04-08 15:06:40 +02:00
|
|
|
# I want to avoid including the whole .git directory
|
|
|
|
".git/HEAD" ".git/objects" ".git/refs/heads/.*"
|
2019-09-07 14:57:22 +02:00
|
|
|
# shadow-cljs expects these for deps resolution
|
2020-07-01 21:45:39 +02:00
|
|
|
"package.json" "yarn.lock"
|
2019-09-07 14:57:22 +02:00
|
|
|
# build stat's images to check if they exist
|
|
|
|
"resources/.*" "translations/.*"
|
2020-03-30 09:45:25 +02:00
|
|
|
];
|
|
|
|
exclude = [
|
2020-04-06 17:30:41 +02:00
|
|
|
"resources/fonts/.*"
|
2019-06-04 18:50:29 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2020-05-06 12:39:49 +02:00
|
|
|
buildInputs = with pkgs; [ clojure nodejs bash git openjdk];
|
2020-10-05 14:53:20 +02:00
|
|
|
phases = [
|
|
|
|
"unpackPhase" "secretsPhase" "patchPhase"
|
|
|
|
"configurePhase" "buildPhase" "installPhase"
|
|
|
|
];
|
|
|
|
|
|
|
|
# For optional INFURA_TOKEN variable
|
|
|
|
secretsPhase = if (secretsFile != "") then ''
|
|
|
|
source "${secretsFile}"
|
2020-10-06 13:54:28 +02:00
|
|
|
${lib.checkEnvVarSet "INFURA_TOKEN"}
|
2020-10-05 14:53:20 +02:00
|
|
|
'' else ''
|
|
|
|
echo "No secrets provided!"
|
|
|
|
'';
|
2019-06-04 18:50:29 +02:00
|
|
|
|
2019-09-07 14:57:22 +02:00
|
|
|
# Patching shadow-cljs.edn so it uses the local maven repo of dependencies provided by Nix
|
2019-06-04 18:50:29 +02:00
|
|
|
patchPhase =
|
2019-09-07 14:57:22 +02:00
|
|
|
let anchor = ''{:source-paths ["src" "test/cljs"]'';
|
2019-06-04 18:50:29 +02:00
|
|
|
in ''
|
2019-09-07 14:57:22 +02:00
|
|
|
substituteInPlace shadow-cljs.edn \
|
2019-06-04 18:50:29 +02:00
|
|
|
--replace '${anchor}' \
|
|
|
|
'${anchor}
|
2020-05-06 12:29:02 +02:00
|
|
|
:maven {:local-repo "${deps.clojure}"}'
|
2019-06-04 18:50:29 +02:00
|
|
|
'';
|
2019-09-07 14:57:22 +02:00
|
|
|
configurePhase = ''
|
|
|
|
# Symlink Node.js modules to build directory
|
2020-05-06 12:39:49 +02:00
|
|
|
ln -s ${deps.nodejs}/node_modules
|
2019-09-07 14:57:22 +02:00
|
|
|
'';
|
|
|
|
buildPhase = ''
|
|
|
|
# Assemble CLASSPATH from available clojure dependencies.
|
|
|
|
# We append 'src' so it can find the local sources.
|
2020-05-14 13:58:05 +02:00
|
|
|
export CLASS_PATH="$(find ${deps.clojure} \
|
|
|
|
-iname '*.jar' | tr '\n' ':')src"
|
2019-06-04 18:50:29 +02:00
|
|
|
|
2019-09-07 14:57:22 +02:00
|
|
|
# target must be one of the builds defined in shadow-cljs.edn
|
2020-05-14 13:58:05 +02:00
|
|
|
java -cp "$CLASS_PATH" clojure.main \
|
|
|
|
-m shadow.cljs.devtools.cli release mobile
|
2019-06-04 18:50:29 +02:00
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
2019-09-07 14:57:22 +02:00
|
|
|
cp -r index.js app $out/
|
2019-06-04 18:50:29 +02:00
|
|
|
'';
|
|
|
|
}
|