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:
parent
3e20616471
commit
604362958b
|
@ -1,13 +1,11 @@
|
||||||
# This method patches Node.js dependencies by taking the
|
# This derivation patches Node.js dependencies by
|
||||||
# result of yarn2nix and symlinking what is fine, and
|
# taking the result of yarn2nix and symlinking what is fine,
|
||||||
# copying and modifying what needs to be adjusted.
|
# and copying and modifying what needs to be adjusted.
|
||||||
|
|
||||||
{ stdenv, patchMavenSources, nodejs }:
|
{ stdenv, deps, nodejs, patchMavenSources }:
|
||||||
|
|
||||||
nodePkgs: mavenPkgs:
|
|
||||||
|
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
name = "${nodePkgs.name}-patched";
|
name = "${deps.nodejs.name}-patched";
|
||||||
|
|
||||||
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
|
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
|
||||||
|
|
||||||
|
@ -15,10 +13,10 @@ stdenv.mkDerivation {
|
||||||
# WARNING: Metro has issues when dealing with symlinks!
|
# WARNING: Metro has issues when dealing with symlinks!
|
||||||
unpackPhase = ''
|
unpackPhase = ''
|
||||||
mkdir -p ./node_modules/
|
mkdir -p ./node_modules/
|
||||||
for module in $(ls ${nodePkgs}/node_modules); do
|
for module in $(ls ${deps.nodejs}/node_modules); do
|
||||||
ln -s ${nodePkgs}/node_modules/$module ./node_modules/
|
ln -s ${deps.nodejs}/node_modules/$module ./node_modules/
|
||||||
done
|
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
|
# Then patch the modules that have build.gradle files
|
||||||
|
@ -30,10 +28,10 @@ stdenv.mkDerivation {
|
||||||
moduleName=''${relativeToNode%%/*}
|
moduleName=''${relativeToNode%%/*}
|
||||||
if [[ -L ./node_modules/$moduleName ]]; then
|
if [[ -L ./node_modules/$moduleName ]]; then
|
||||||
unlink ./node_modules/$moduleName
|
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
|
chmod u+w -R ./node_modules/$moduleName
|
||||||
fi
|
fi
|
||||||
${patchMavenSources} $modBuildGradle '${mavenPkgs}'
|
${patchMavenSources} $modBuildGradle '${deps.gradle}'
|
||||||
done
|
done
|
||||||
|
|
||||||
patchShebangs ./node_modules
|
patchShebangs ./node_modules
|
|
@ -1,5 +1,5 @@
|
||||||
{ lib, pkgs, deps, callPackage, mkShell
|
{ lib, pkgs, deps, callPackage, mkShell
|
||||||
, status-go, androidPkgs, androidShell, patchNodeModules }:
|
, status-go, androidPkgs, androidShell }:
|
||||||
|
|
||||||
let
|
let
|
||||||
# Import a jsbundle compiled out of clojure codebase
|
# 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)
|
# Import a patched version of watchman (important for sandboxed builds on macOS)
|
||||||
watchmanFactory = callPackage ./watchman.nix { };
|
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
|
# TARGETS
|
||||||
release = callPackage ./release.nix {
|
release = callPackage ./release.nix {
|
||||||
inherit jsbundle status-go watchmanFactory nodeJsModules;
|
inherit jsbundle status-go watchmanFactory;
|
||||||
};
|
};
|
||||||
|
|
||||||
in {
|
in {
|
||||||
# TARGETS
|
# TARGETS
|
||||||
inherit release jsbundle nodeJsModules;
|
inherit release jsbundle;
|
||||||
|
|
||||||
shell = mkShell {
|
shell = mkShell {
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
|
@ -50,7 +46,7 @@ in {
|
||||||
ln -sf ./mobile/js_files/* ./
|
ln -sf ./mobile/js_files/* ./
|
||||||
|
|
||||||
# check if node modules changed and if so install them
|
# 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}
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{ stdenv, lib, config, callPackage, deps,
|
{ stdenv, pkgs, deps, lib, config, callPackage,
|
||||||
bash, file, gnumake, watchmanFactory, gradle,
|
watchmanFactory, androidPkgs, patchMavenSources,
|
||||||
androidPkgs, patchMavenSources, nodeJsModules,
|
jsbundle, status-go }:
|
||||||
nodejs, openjdk, jsbundle, status-go, unzip, zlib }:
|
|
||||||
|
|
||||||
{
|
{
|
||||||
buildEnv ? "prod", # Value for BUILD_ENV checked by Clojure code at compile time
|
buildEnv ? "prod", # Value for BUILD_ENV checked by Clojure code at compile time
|
||||||
|
@ -54,8 +53,8 @@ in stdenv.mkDerivation rec {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
buildInputs = [ nodejs openjdk ];
|
buildInputs = with pkgs; [ nodejs openjdk ];
|
||||||
nativeBuildInputs = [ bash gradle unzip ]
|
nativeBuildInputs = with pkgs; [ bash gradle unzip ]
|
||||||
++ lib.optionals stdenv.isDarwin [ file gnumake patchedWatchman ];
|
++ lib.optionals stdenv.isDarwin [ file gnumake patchedWatchman ];
|
||||||
|
|
||||||
# Used by Clojure at compile time to include JS modules
|
# 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!
|
# Copy node_modules/ directory. The -L is CRUCIAL!
|
||||||
# Otherwise Metro failes to find modules due to symlinks.
|
# 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
|
chmod +w -R ./node_modules
|
||||||
|
|
||||||
# Patch build.gradle to use local repo
|
# Patch build.gradle to use local repo
|
||||||
|
@ -113,13 +112,14 @@ in stdenv.mkDerivation rec {
|
||||||
'';
|
'';
|
||||||
buildPhase = let
|
buildPhase = let
|
||||||
adhocEnvVars = optionalString stdenv.isLinux
|
adhocEnvVars = optionalString stdenv.isLinux
|
||||||
"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${makeLibraryPath [ zlib ]}";
|
"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${makeLibraryPath [ pkgs.zlib ]}";
|
||||||
in
|
in
|
||||||
assert ANDROID_ABI_SPLIT != null && ANDROID_ABI_SPLIT != "";
|
assert ANDROID_ABI_SPLIT != null && ANDROID_ABI_SPLIT != "";
|
||||||
assert stringLength ANDROID_ABI_INCLUDE > 0;
|
assert stringLength ANDROID_ABI_INCLUDE > 0;
|
||||||
''
|
''
|
||||||
pushd ./android
|
pushd ./android
|
||||||
${adhocEnvVars} gradle ${toString gradleOpts} \
|
${adhocEnvVars} ${pkgs.gradle}/bin/gradle \
|
||||||
|
${toString gradleOpts} \
|
||||||
--offline --stacktrace \
|
--offline --stacktrace \
|
||||||
-Dmaven.repo.local='${deps.gradle}' \
|
-Dmaven.repo.local='${deps.gradle}' \
|
||||||
-PversionCode=${toString buildNumber} \
|
-PversionCode=${toString buildNumber} \
|
||||||
|
@ -129,7 +129,9 @@ in stdenv.mkDerivation rec {
|
||||||
'';
|
'';
|
||||||
doCheck = true;
|
doCheck = true;
|
||||||
checkPhase = ''
|
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 = ''
|
installPhase = ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
|
|
|
@ -24,6 +24,7 @@ in {
|
||||||
clojure = callPackage ./deps/clojure { };
|
clojure = callPackage ./deps/clojure { };
|
||||||
gradle = callPackage ./deps/gradle { };
|
gradle = callPackage ./deps/gradle { };
|
||||||
nodejs = callPackage ./deps/nodejs { };
|
nodejs = callPackage ./deps/nodejs { };
|
||||||
|
nodejs-patched = callPackage ./deps/nodejs-patched { };
|
||||||
react-native = callPackage ./deps/react-native { };
|
react-native = callPackage ./deps/react-native { };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ let
|
||||||
buildInputs = [ pkgs.androidPkgs ];
|
buildInputs = [ pkgs.androidPkgs ];
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
export STATUS_REACT_HOME=$(git rev-parse --show-toplevel)
|
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}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue