nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 199 lines 4.6 kB view raw
1{ 2 stdenv, 3 lib, 4 makeWrapper, 5 installShellFiles, 6 nodejsInstallManuals, 7 nodejsInstallExecutables, 8 coreutils, 9 nix-prefetch-git, 10 fetchurl, 11 jq, 12 nodejs, 13 nodejs-slim, 14 prefetch-yarn-deps, 15 fixup-yarn-lock, 16 diffutils, 17 yarn, 18 makeSetupHook, 19 cacert, 20 callPackage, 21}: 22 23let 24 yarnpkg-lockfile-tar = fetchurl { 25 url = "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz"; 26 hash = "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ=="; 27 }; 28 29 tests = callPackage ./tests { }; 30in 31{ 32 prefetch-yarn-deps = stdenv.mkDerivation { 33 name = "prefetch-yarn-deps"; 34 35 dontUnpack = true; 36 dontBuild = true; 37 38 nativeBuildInputs = [ makeWrapper ]; 39 buildInputs = [ nodejs-slim ]; 40 41 installPhase = '' 42 runHook preInstall 43 44 mkdir -p $out/bin $out/libexec 45 46 tar --strip-components=1 -xf ${yarnpkg-lockfile-tar} package/index.js 47 mv index.js $out/libexec/yarnpkg-lockfile.js 48 cp ${./common.js} $out/libexec/common.js 49 cp ${./index.js} $out/libexec/index.js 50 51 patchShebangs $out/libexec 52 makeWrapper $out/libexec/index.js $out/bin/prefetch-yarn-deps \ 53 --prefix PATH : ${ 54 lib.makeBinPath [ 55 coreutils 56 nix-prefetch-git 57 ] 58 } 59 60 runHook postInstall 61 ''; 62 63 passthru = { 64 inherit tests; 65 }; 66 }; 67 68 fixup-yarn-lock = stdenv.mkDerivation { 69 name = "fixup-yarn-lock"; 70 71 dontUnpack = true; 72 dontBuild = true; 73 74 nativeBuildInputs = [ makeWrapper ]; 75 buildInputs = [ nodejs-slim ]; 76 77 installPhase = '' 78 runHook preInstall 79 80 mkdir -p $out/bin $out/libexec 81 82 tar --strip-components=1 -xf ${yarnpkg-lockfile-tar} package/index.js 83 mv index.js $out/libexec/yarnpkg-lockfile.js 84 cp ${./common.js} $out/libexec/common.js 85 cp ${./fixup.js} $out/libexec/fixup.js 86 87 patchShebangs $out/libexec 88 makeWrapper $out/libexec/fixup.js $out/bin/fixup-yarn-lock 89 90 runHook postInstall 91 ''; 92 93 passthru = { 94 inherit tests; 95 }; 96 }; 97 98 fetchYarnDeps = 99 let 100 f = 101 { 102 name ? "offline", 103 src ? null, 104 hash ? "", 105 sha256 ? "", 106 ... 107 }@args: 108 let 109 hash_ = 110 if hash != "" then 111 { 112 outputHashAlgo = null; 113 outputHash = hash; 114 } 115 else if sha256 != "" then 116 { 117 outputHashAlgo = "sha256"; 118 outputHash = sha256; 119 } 120 else 121 { 122 outputHashAlgo = "sha256"; 123 outputHash = lib.fakeSha256; 124 }; 125 in 126 stdenv.mkDerivation ( 127 { 128 inherit name; 129 130 dontUnpack = src == null; 131 dontInstall = true; 132 133 nativeBuildInputs = [ 134 prefetch-yarn-deps 135 cacert 136 ]; 137 GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt"; 138 NODE_EXTRA_CA_CERTS = "${cacert}/etc/ssl/certs/ca-bundle.crt"; 139 140 buildPhase = '' 141 runHook preBuild 142 143 yarnLock=''${yarnLock:=$PWD/yarn.lock} 144 mkdir -p $out 145 (cd $out; prefetch-yarn-deps --verbose --builder $yarnLock) 146 147 runHook postBuild 148 ''; 149 150 outputHashMode = "recursive"; 151 } 152 // hash_ 153 // (removeAttrs args ( 154 [ 155 "name" 156 "hash" 157 "sha256" 158 ] 159 ++ (lib.optional (src == null) "src") 160 )) 161 ); 162 in 163 lib.setFunctionArgs f (lib.functionArgs f) // { inherit tests; }; 164 165 yarnConfigHook = makeSetupHook { 166 name = "yarn-config-hook"; 167 propagatedBuildInputs = [ 168 yarn 169 fixup-yarn-lock 170 ]; 171 substitutions = { 172 # Specify `diff` by abspath to ensure that the user's build 173 # inputs do not cause us to find the wrong binaries. 174 diff = "${diffutils}/bin/diff"; 175 }; 176 meta = { 177 description = "Install nodejs dependencies from an offline yarn cache produced by fetchYarnDeps"; 178 }; 179 } ./yarn-config-hook.sh; 180 181 yarnBuildHook = makeSetupHook { 182 name = "yarn-build-hook"; 183 meta = { 184 description = "Run yarn build in buildPhase"; 185 }; 186 } ./yarn-build-hook.sh; 187 188 yarnInstallHook = makeSetupHook { 189 name = "yarn-install-hook"; 190 propagatedBuildInputs = [ 191 yarn 192 nodejsInstallManuals 193 nodejsInstallExecutables 194 ]; 195 substitutions = { 196 jq = lib.getExe jq; 197 }; 198 } ./yarn-install-hook.sh; 199}