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