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 {
|
2023-05-16 16:42:56 +00:00
|
|
|
name = "status-mobile-jsbundle";
|
2019-06-04 16:50:29 +00:00
|
|
|
src =
|
2023-05-16 16:42:56 +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;
|
2022-07-17 12:37:46 +00:00
|
|
|
name = "status-mobile-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;
|
2024-09-20 09:31:42 +00:00
|
|
|
include = [
|
2020-04-08 13:06:40 +00:00
|
|
|
"VERSION" "BUILD_NUMBER" "scripts/version/.*"
|
2023-05-16 16:42:56 +00:00
|
|
|
"src/.*" "shadow-cljs.edn"
|
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"
|
|
|
|
];
|
|
|
|
|
2022-10-19 14:59:55 +00:00
|
|
|
# For optional POKT_TOKEN variable
|
2020-10-05 12:53:20 +00:00
|
|
|
secretsPhase = if (secretsFile != "") then ''
|
|
|
|
source "${secretsFile}"
|
2022-10-19 14:59:55 +00:00
|
|
|
${lib.checkEnvVarSet "POKT_TOKEN"}
|
2020-10-05 12:53:20 +00:00
|
|
|
'' 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 \
|
2024-09-20 09:31:42 +00:00
|
|
|
--replace-quiet '${anchor}' \
|
2019-06-04 16:50:29 +00:00
|
|
|
'${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.
|
2023-11-18 11:50:11 +00:00
|
|
|
# We prepend 'src' so it can find the local sources and prioritize
|
|
|
|
# our own namespaces over dependencies, given that indirect dependencies
|
|
|
|
# can also cause naming conflicts (e.g. prismatic/schema already uses
|
|
|
|
# namespace schema.core).
|
|
|
|
export CLASS_PATH="src:$(find ${deps.clojure} \
|
|
|
|
-iname '*.jar' | tr '\n' ':')"
|
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
|
2023-05-16 16:42:56 +00:00
|
|
|
cp -r result/* $out/
|
2019-06-04 16:50:29 +00:00
|
|
|
'';
|
|
|
|
}
|