From 604362958b5aa8d8ffdda0a0d8356d6b4b0d513f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 18 May 2020 12:15:49 +0200 Subject: [PATCH] nix: always use patched node_modules in shells MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../nodejs-patched/default.nix} | 22 +++++++++---------- nix/mobile/android/default.nix | 12 ++++------ nix/mobile/android/release.nix | 22 ++++++++++--------- nix/overlay.nix | 1 + nix/shells.nix | 2 +- 5 files changed, 28 insertions(+), 31 deletions(-) rename nix/{tools/patchNodeModules.nix => deps/nodejs-patched/default.nix} (78%) diff --git a/nix/tools/patchNodeModules.nix b/nix/deps/nodejs-patched/default.nix similarity index 78% rename from nix/tools/patchNodeModules.nix rename to nix/deps/nodejs-patched/default.nix index 4100f1dfdf..263eba27e7 100644 --- a/nix/tools/patchNodeModules.nix +++ b/nix/deps/nodejs-patched/default.nix @@ -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 diff --git a/nix/mobile/android/default.nix b/nix/mobile/android/default.nix index 3b50c11cd0..fb910e46a8 100644 --- a/nix/mobile/android/default.nix +++ b/nix/mobile/android/default.nix @@ -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} } ''; }; diff --git a/nix/mobile/android/release.nix b/nix/mobile/android/release.nix index 4209ed16fa..0692730a97 100644 --- a/nix/mobile/android/release.nix +++ b/nix/mobile/android/release.nix @@ -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 diff --git a/nix/overlay.nix b/nix/overlay.nix index 8c2f47e939..fb6683ed25 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -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 { }; }; diff --git a/nix/shells.nix b/nix/shells.nix index 31342ef8d0..dfa153d2b9 100644 --- a/nix/shells.nix +++ b/nix/shells.nix @@ -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} ''; };