nix: always use patched node_modules in shells

Becuase `clojure` shell used unpatched `node_modules` while the
`android` shell used the patched version when starting these shells
the `node_modules` would keep being switched between them wasting time.

Changes:
- Move `nix/tools/patchNodeModules.nix` to `nix/deps/nodejs-patched`
- Make `nix/deps/nodejs-patched` a normal derivation without extra arguments
- Use `deps.nodejs-patched` in `nix/mobile/android` shell
- Use `deps.nodejs-patched` in `nix/shells.nix` node shell
- Use `with pkgs` to reduce arguments in `nix/mobile/android/release.nix`

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2020-05-18 12:15:49 +02:00
parent 3e20616471
commit 604362958b
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
5 changed files with 28 additions and 31 deletions

View File

@ -1,13 +1,11 @@
# This method patches Node.js dependencies by taking the
# result of yarn2nix and symlinking what is fine, and
# copying and modifying what needs to be adjusted.
# This derivation patches Node.js dependencies by
# taking the result of yarn2nix and symlinking what is fine,
# and copying and modifying what needs to be adjusted.
{ stdenv, patchMavenSources, nodejs }:
nodePkgs: mavenPkgs:
{ stdenv, deps, nodejs, patchMavenSources }:
stdenv.mkDerivation {
name = "${nodePkgs.name}-patched";
name = "${deps.nodejs.name}-patched";
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
@ -15,10 +13,10 @@ stdenv.mkDerivation {
# WARNING: Metro has issues when dealing with symlinks!
unpackPhase = ''
mkdir -p ./node_modules/
for module in $(ls ${nodePkgs}/node_modules); do
ln -s ${nodePkgs}/node_modules/$module ./node_modules/
for module in $(ls ${deps.nodejs}/node_modules); do
ln -s ${deps.nodejs}/node_modules/$module ./node_modules/
done
cp -r ${nodePkgs}/node_modules/.bin ./node_modules/
cp -r ${deps.nodejs}/node_modules/.bin ./node_modules/
'';
# Then patch the modules that have build.gradle files
@ -30,10 +28,10 @@ stdenv.mkDerivation {
moduleName=''${relativeToNode%%/*}
if [[ -L ./node_modules/$moduleName ]]; then
unlink ./node_modules/$moduleName
cp -r ${nodePkgs}/node_modules/$moduleName ./node_modules/
cp -r ${deps.nodejs}/node_modules/$moduleName ./node_modules/
chmod u+w -R ./node_modules/$moduleName
fi
${patchMavenSources} $modBuildGradle '${mavenPkgs}'
${patchMavenSources} $modBuildGradle '${deps.gradle}'
done
patchShebangs ./node_modules

View File

@ -1,5 +1,5 @@
{ lib, pkgs, deps, callPackage, mkShell
, status-go, androidPkgs, androidShell, patchNodeModules }:
, status-go, androidPkgs, androidShell }:
let
# Import a jsbundle compiled out of clojure codebase
@ -8,18 +8,14 @@ let
# Import a patched version of watchman (important for sandboxed builds on macOS)
watchmanFactory = callPackage ./watchman.nix { };
# Some node_modules have build.gradle files that reference remote repos.
# This patches them to reference local repos only
nodeJsModules = patchNodeModules deps.nodejs deps.gradle;
# TARGETS
release = callPackage ./release.nix {
inherit jsbundle status-go watchmanFactory nodeJsModules;
inherit jsbundle status-go watchmanFactory;
};
in {
# TARGETS
inherit release jsbundle nodeJsModules;
inherit release jsbundle;
shell = mkShell {
buildInputs = with pkgs; [
@ -50,7 +46,7 @@ in {
ln -sf ./mobile/js_files/* ./
# check if node modules changed and if so install them
$STATUS_REACT_HOME/nix/scripts/node_modules.sh ${nodeJsModules}
$STATUS_REACT_HOME/nix/scripts/node_modules.sh ${deps.nodejs-patched}
}
'';
};

View File

@ -1,7 +1,6 @@
{ stdenv, lib, config, callPackage, deps,
bash, file, gnumake, watchmanFactory, gradle,
androidPkgs, patchMavenSources, nodeJsModules,
nodejs, openjdk, jsbundle, status-go, unzip, zlib }:
{ stdenv, pkgs, deps, lib, config, callPackage,
watchmanFactory, androidPkgs, patchMavenSources,
jsbundle, status-go }:
{
buildEnv ? "prod", # Value for BUILD_ENV checked by Clojure code at compile time
@ -54,8 +53,8 @@ in stdenv.mkDerivation rec {
};
};
buildInputs = [ nodejs openjdk ];
nativeBuildInputs = [ bash gradle unzip ]
buildInputs = with pkgs; [ nodejs openjdk ];
nativeBuildInputs = with pkgs; [ bash gradle unzip ]
++ lib.optionals stdenv.isDarwin [ file gnumake patchedWatchman ];
# Used by Clojure at compile time to include JS modules
@ -102,7 +101,7 @@ in stdenv.mkDerivation rec {
# Copy node_modules/ directory. The -L is CRUCIAL!
# Otherwise Metro failes to find modules due to symlinks.
cp -aL ${nodeJsModules}/node_modules/ ./
cp -aL ${deps.nodejs-patched}/node_modules/ ./
chmod +w -R ./node_modules
# Patch build.gradle to use local repo
@ -113,13 +112,14 @@ in stdenv.mkDerivation rec {
'';
buildPhase = let
adhocEnvVars = optionalString stdenv.isLinux
"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${makeLibraryPath [ zlib ]}";
"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${makeLibraryPath [ pkgs.zlib ]}";
in
assert ANDROID_ABI_SPLIT != null && ANDROID_ABI_SPLIT != "";
assert stringLength ANDROID_ABI_INCLUDE > 0;
''
pushd ./android
${adhocEnvVars} gradle ${toString gradleOpts} \
${adhocEnvVars} ${pkgs.gradle}/bin/gradle \
${toString gradleOpts} \
--offline --stacktrace \
-Dmaven.repo.local='${deps.gradle}' \
-PversionCode=${toString buildNumber} \
@ -129,7 +129,9 @@ in stdenv.mkDerivation rec {
'';
doCheck = true;
checkPhase = ''
ls ${apksPath}/*.apk | xargs -n1 unzip -qql | grep 'assets/index.android.bundle'
ls ${apksPath}/*.apk \
| xargs -n1 ${pkgs.unzip}/bin/unzip -qql \
| grep 'assets/index.android.bundle'
'';
installPhase = ''
mkdir -p $out

View File

@ -24,6 +24,7 @@ in {
clojure = callPackage ./deps/clojure { };
gradle = callPackage ./deps/gradle { };
nodejs = callPackage ./deps/nodejs { };
nodejs-patched = callPackage ./deps/nodejs-patched { };
react-native = callPackage ./deps/react-native { };
};

View File

@ -49,7 +49,7 @@ let
buildInputs = [ pkgs.androidPkgs ];
shellHook = ''
export STATUS_REACT_HOME=$(git rev-parse --show-toplevel)
$STATUS_REACT_HOME/nix/scripts/node_modules.sh ${pkgs.deps.nodejs}
$STATUS_REACT_HOME/nix/scripts/node_modules.sh ${pkgs.deps.nodejs-patched}
'';
};