diff --git a/pkgs/build-support/node/build-npm-package/default.nix b/pkgs/build-support/node/build-npm-package/default.nix index 9916826746f0..1e316d1be9c6 100644 --- a/pkgs/build-support/node/build-npm-package/default.nix +++ b/pkgs/build-support/node/build-npm-package/default.nix @@ -26,9 +26,9 @@ lib.extendMkDerivation { # The output hash of the dependencies for this project. # Can be calculated in advance with prefetch-npm-deps. npmDepsHash ? "", - # Cache format version for npmDeps. Set to 2 to enable packument caching + # Fetcher format version for npmDeps. Set to 2 to enable packument caching # for workspace support. Changing this will invalidate npmDepsHash. - npmDepsCacheVersion ? 1, + npmDepsFetcherVersion ? 1, # Whether to force the usage of Git dependencies that have install scripts, but not a lockfile. # Use with care. forceGitDeps ? false, @@ -69,7 +69,7 @@ lib.extendMkDerivation { ; name = "${name}-npm-deps"; hash = npmDepsHash; - cacheVersion = npmDepsCacheVersion; + fetcherVersion = npmDepsFetcherVersion; }, # Custom npmConfigHook npmConfigHook ? null, @@ -90,7 +90,7 @@ lib.extendMkDerivation { inherit npmDeps npmBuildScript; env = (args.env or { }) // { - NIX_NPM_CACHE_VERSION = npmDepsCacheVersion; + NIX_NPM_FETCHER_VERSION = npmDepsFetcherVersion; }; nativeBuildInputs = diff --git a/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh b/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh index c9e8dac4c78d..3e7fcbd69133 100644 --- a/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh +++ b/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh @@ -28,19 +28,19 @@ npmConfigHook() { exit 1 fi - if [[ -e "$npmDeps/cache_version" ]]; then - local -r cacheVersion=$(cat "$npmDeps/cache_version") + if [[ -e "$npmDeps/.fetcher-version" ]]; then + local -r fetcherVersion=$(cat "$npmDeps/.fetcher-version") else - local -r cacheVersion="1" + local -r fetcherVersion="1" fi # Only run this in buildNpmPackage, this is just for a nicer error message; we trust that # people using the setup hook directly also know how FODs work. ;) - if [[ -n ${NIX_NPM_CACHE_VERSION+x} ]] && [[ $NIX_NPM_CACHE_VERSION != $cacheVersion ]]; then + if [[ -n ${NIX_NPM_FETCHER_VERSION+x} ]] && [[ $NIX_NPM_FETCHER_VERSION != $fetcherVersion ]]; then echo echo "ERROR: npmDepsHash is out of date" echo - echo "The cache version in the arguments to buildNpmPackage ($NIX_NPM_CACHE_VERSION) is not the same as the one in $npmDeps ($cacheVersion)." + echo "The fetcher version in the arguments to buildNpmPackage ($NIX_NPM_FETCHER_VERSION) is not the same as the one in $npmDeps ($fetcherVersion)." echo echo "To fix the issue:" echo '1. Use `lib.fakeHash` as the npmDepsHash value' @@ -102,10 +102,10 @@ npmConfigHook() { local cachePath # When a given cache key has multiple entries (which is the case with - # cache version 2), npm always needs to write to the cache. + # fetcher version 2), npm always needs to write to the cache. # # TODO(winter): report upstream? - if [ -z "${makeCacheWritable-}" ] && (( cacheVersion == 1 )); then + if [ -z "${makeCacheWritable-}" ] && (( fetcherVersion == 1 )); then cachePath="$npmDeps" else echo "Making cache writable" @@ -127,7 +127,7 @@ npmConfigHook() { echo "ERROR: npm failed to install dependencies" echo echo "Here are a few things you can try, depending on the error:" - echo '1. Set `npmDepsCacheVersion = 2` (and update `npmDepsHash`)' + echo '1. Set `npmDepsFetcherVersion = 2` (and update `npmDepsHash`)' echo '2. Set `makeCacheWritable = true`' echo " Note that this won't help if npm is complaining about not being able to write to the logs directory -- look above that for the actual error." echo '3. Set `npmFlags = [ "--legacy-peer-deps" ]`' diff --git a/pkgs/build-support/node/prefetch-npm-deps/default.nix b/pkgs/build-support/node/prefetch-npm-deps/default.nix index ecf4e36a982f..bfa8fb863e4b 100644 --- a/pkgs/build-support/node/prefetch-npm-deps/default.nix +++ b/pkgs/build-support/node/prefetch-npm-deps/default.nix @@ -215,10 +215,10 @@ # A string with a JSON attrset specifying registry mirrors, for example # {"registry.example.org": "my-mirror.local/registry.example.org"} npmRegistryOverridesString ? config.npmRegistryOverridesString, - # Cache format version. Bump this to invalidate all existing hashes. + # Fetcher format version. Bump this to invalidate all existing hashes. # Version 1: original format (tarballs only) # Version 2: includes packuments for workspace support - cacheVersion ? 1, + fetcherVersion ? 1, ... }@args: let @@ -276,9 +276,9 @@ NIX_NPM_REGISTRY_OVERRIDES = npmRegistryOverridesString; - # Cache version controls which features are enabled in prefetch-npm-deps + # Fetcher version controls which features are enabled in prefetch-npm-deps # Version 2+ enables packument fetching for workspace support - NPM_CACHE_VERSION = toString cacheVersion; + NPM_FETCHER_VERSION = toString fetcherVersion; SSL_CERT_FILE = if diff --git a/pkgs/build-support/node/prefetch-npm-deps/src/main.rs b/pkgs/build-support/node/prefetch-npm-deps/src/main.rs index 4c09b0cdbbf8..fa594ce5b2af 100644 --- a/pkgs/build-support/node/prefetch-npm-deps/src/main.rs +++ b/pkgs/build-support/node/prefetch-npm-deps/src/main.rs @@ -357,15 +357,15 @@ fn main() -> anyhow::Result<()> { Ok::<_, anyhow::Error>(()) })?; - // Fetch and cache packuments (package metadata) - only for cache version 2+ - let cache_version: u32 = env::var("NPM_CACHE_VERSION") + // Fetch and cache packuments (package metadata) - only for fetcher version 2+ + let fetcher_version: u32 = env::var("NPM_FETCHER_VERSION") .ok() .and_then(|v| v.parse().ok()) .unwrap_or(1); - if cache_version >= 2 { + if fetcher_version >= 2 { fetch_packuments(&cache, package_names)?; - fs::write(out.join("cache_version"), format!("{cache_version}"))?; + fs::write(out.join(".fetcher-version"), format!("{fetcher_version}"))?; } fs::write(out.join("package-lock.json"), lock_content)?;