Hi, I’m trying to package a project that uses Yarn v2 lockfiles. I do not really know anything about Node.js development, I simply want to use this project myself and thus want to package it. However, I cannot get this to work.
Attempting to use fetchYarnDeps does not work, as the project uses a v2 lockfile and this function seemingly only supports Yarn 1 lockfiles. Thus, I tried to follow [quote=“dxwil, post:1, topic:51104, full:true”]
I’m trying to create an offline yarn cache for a yarn v2 lock file manually (because v2 doesn’t support fetchYarnDeps).
I saw Cannot create an offline yarn cache, it's empty and tried to replicate their subderivation, however, it does not work. Running it simply results in an error reading RequestError: getaddrinfo EAI_AGAIN registry.yarnpkg.com
, indicating a DNS failure. The only way I found to solve this is by disabling the build sandbox, but this is not ideal and I want to avoid this.
Furthermore, even disabling the sandbox still results in an empty and thus useless derivation. I suspect this is because the solution in the linked thread no longer works, attempting to use --cache-folder
results in an error indicating that this command line option is deprecated and can no longer be used. Other methods of setting cacheFolder to $out do not seem to work either, confusingly.
Below is included my code so far. If there is a better way to use v2 yarn lockfiles I would like to hear it.
{ lib, config, pkgs, ... }:
let pkg = pkgs.stdenv.mkDerivation(finalAttrs: rec {
pname = "actualbudget";
version = "24.11.0";
src = pkgs.fetchFromGitHub {
owner = "actualbudget";
repo = "actual-server";
rev = "refs/tags/v${finalAttrs.version}";
hash = "sha256-GwtJ42dBJXrOBIxwdrSvNeqQCl91m1XrtS3RBpEuZX0=";
};
yarnOfflineCache = pkgs.stdenv.mkDerivation { inherit src;
name = "actualbudget-${version}-offline-cache";
nativeBuildInputs = with pkgs; [
yarn
cacert # needed for git
gitMinimal # needed to download git dependencies
nodejs # needed for npm to download git dependencies
python3
jq
moreutils
];
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
buildPhase = ''
runHook preBuild
export HOME=$(mktemp -d)
yarn config set enableTelemetry 0
yarn config set cacheFolder $out
yarn
runHook postBuild
'';
dontConfigure = true;
dontInstall = true;
dontFixup = true;
};
nativeBuildInputs = with pkgs; [
unstable.yarnConfigHook # unstable is an overlay containing unstable nixpkgs
unstable.yarnBuildHook
nodejs
npmHooks.npmInstallHook
];
}); in
{
...
}