Trouble packaging mkYarnPackage: missing dependencies, a lot of warnings

Hello, I’ve been trying to package slippi for nix.

It’s an electron app that uses yarn as its package manager; so naturally I used mkYarnPackage, but I think I messed up somewhere.

I’m stuck with the following issues:

  • There are a lot of warnings, which I am not sure is normal
  • It simply doesn’t build because ts-node is not found, it is however in package.json, so should it not be installed already ?

Here is my derivation, any help is appreciated !

{
  electron,
  fetchFromGitHub,
  lib,
  makeDesktopItem,
  makeWrapper,
  mkYarnPackage,
  slippi-netplay,
  replaceVars,
}:

let
  pname = "slippi-launcher";
  version = "2.11.10";
  src = fetchFromGitHub {
    owner = "project-slippi";
    repo = "slippi-launcher";
    tag = "v${version}";
    hash = "sha256-JrM2nm5iEAoyrGeqF1iP+kKjdiC/3mfCihzawg3Xv9s=";
  };
in
mkYarnPackage {
  inherit pname version src;
  packageJSON = "${src}/package.json";
  yarnLock = "${src}/yarn.lock";
  nativeBuildInputs = [
    makeWrapper
  ];

  ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
  patches = [
    (replaceVars ./0001-replace-findDolphinExecutable-by-NIX_DOLPHIN_PATH-va.patch {
      NIX_DOLPHIN_PATH = "${lib.getExe slippi-netplay}";
    })
  ];

  postBuild = ''
    yarn --offline run package
      --dir \
      -c.electronDist=${electron}/lib/electron \
      -c.electronVersion=${electron.version}
  '';
  installPhase = ''
    runHook preInstall

    makeWrapper "${lib.getExe electron}" "$out/bin/${pname}" \
      --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
      --inherit-argv0

    runHook postInstall
  '';

  desktopItems = [
    (makeDesktopItem {
      name = pname;
      desktopName = "Slippi Launcher";
      exec = "slippi-launcher %U";
      icon = "slippi-launcher";
      keywords = [
        "melee"
        "netplay"
        "rollback"
        "smash"
      ];
      categories = [
        "Emulator"
        "Game"
        "Network"
      ];
      terminal = false;
    })
  ];

  meta = {
    homepage = "https://slippi.gg";
    description = "The way to play Slippi Online and watch replays";
    platforms = lib.platforms.linux;
    license = lib.licenses.gpl3Only;
  };
}

Here are the logs

$ nix build .#slippi-launcher-source -L -v
this derivation will be built:
  /nix/store/hhzhqvm87f0kis4wj0gc5wc0b9n5h4mv-slippi-launcher-2.11.10.drv
building '/nix/store/hhzhqvm87f0kis4wj0gc5wc0b9n5h4mv-slippi-launcher-2.11.10.drv'...
slippi-launcher> Running phase: unpackPhase
slippi-launcher> unpacking source archive /nix/store/k7j1fp1dgmb261hsh59pcr71908q9bsg-source
slippi-launcher> source root is source
slippi-launcher> Running phase: patchPhase
slippi-launcher> applying patch /nix/store/cqz54i7pzhqlf83pmzndgyk8crmyxv9p-0001-replace-findDolphinExecutable-by-NIX_DOLPHIN_PATH-va.patch
slippi-launcher> patching file src/dolphin/install/ishiiruka_installation.ts
slippi-launcher> patching file src/dolphin/install/mainline_installation.ts
slippi-launcher> patching file src/dolphin/util.ts
slippi-launcher> Running phase: updateAutotoolsGnuConfigScriptsPhase
slippi-launcher> Running phase: configurePhase
slippi-launcher> Running phase: buildPhase
slippi-launcher> no Makefile or custom buildPhase, doing nothing
slippi-launcher> yarn run v1.22.22
slippi-launcher> warning Skipping preferred cache folder "/homeless-shelter/.cache/yarn" because it is not writable.
slippi-launcher> warning Selected the next writable cache folder in the list, will be "/build/.yarn-cache-1000".
slippi-launcher> $ yarn run clean && yarn run build && electron-builder build --publish never
slippi-launcher> warning Cannot find a suitable global folder. Tried these: "/usr/local, /homeless-shelter/.yarn"
slippi-launcher> warning You don't appear to have an internet connection. Try the --offline flag to use the cache for registry queries.
slippi-launcher> warning Skipping preferred cache folder "/homeless-shelter/.cache/yarn" because it is not writable.
slippi-launcher> warning Selected the next writable cache folder in the list, will be "/build/.yarn-cache-1000".
slippi-launcher> $ ts-node ./.erb/scripts/clean.js dist
slippi-launcher> warning Cannot find a suitable global folder. Tried these: "/usr/local, /homeless-shelter/.yarn"
slippi-launcher> /bin/sh: ts-node: not found
slippi-launcher> error Command failed with exit code 127.
slippi-launcher> info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
slippi-launcher> error Command failed with exit code 127.
slippi-launcher> info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error: builder for '/nix/store/hhzhqvm87f0kis4wj0gc5wc0b9n5h4mv-slippi-launcher-2.11.10.drv' failed with exit code 127;
       last 25 log lines:
       > source root is source
       > Running phase: patchPhase
       > applying patch /nix/store/cqz54i7pzhqlf83pmzndgyk8crmyxv9p-0001-replace-findDolphinExecutable-by-NIX_DOLPHIN_PATH-va.patch
       > patching file src/dolphin/install/ishiiruka_installation.ts
       > patching file src/dolphin/install/mainline_installation.ts
       > patching file src/dolphin/util.ts
       > Running phase: updateAutotoolsGnuConfigScriptsPhase
       > Running phase: configurePhase
       > Running phase: buildPhase
       > no Makefile or custom buildPhase, doing nothing
       > yarn run v1.22.22
       > warning Skipping preferred cache folder "/homeless-shelter/.cache/yarn" because it is not writable.
       > warning Selected the next writable cache folder in the list, will be "/build/.yarn-cache-1000".
       > $ yarn run clean && yarn run build && electron-builder build --publish never
       > warning Cannot find a suitable global folder. Tried these: "/usr/local, /homeless-shelter/.yarn"
       > warning You don't appear to have an internet connection. Try the --offline flag to use the cache for registry queries.
       > warning Skipping preferred cache folder "/homeless-shelter/.cache/yarn" because it is not writable.
       > warning Selected the next writable cache folder in the list, will be "/build/.yarn-cache-1000".
       > $ ts-node ./.erb/scripts/clean.js dist
       > warning Cannot find a suitable global folder. Tried these: "/usr/local, /homeless-shelter/.yarn"
       > /bin/sh: ts-node: not found
       > error Command failed with exit code 127.
       > info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
       > error Command failed with exit code 127.
       > info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
       For full logs, run:
         nix log /nix/store/hhzhqvm87f0kis4wj0gc5wc0b9n5h4mv-slippi-launcher-2.11.10.drv
  • The warnings seem to be because Yarn is trying to put something under $HOME, which is not set to a writable location by default. Try export HOME=$(mktemp -d).
  • ts-node might be installed, but it might not be in PATH. Try something like export PATH=$PATH:$PWD/node_modules/.bin.

Both of these suggestions are based on my experience with derivations for (non-Electron) node projects, e.g. Teleport.

Thanks for your answer

The HOME thingy did fix all of the warnings except the internet connection one, but the ts-node one is not fixed

For debugging purposes I did ls on PWD (<- contains deps node_modules and .yarnrc) and PWD/node_modules, but the latter doesn’t seem to contain .bin, only .yarn-integrity and slippi-launcher, which is the fetched git repo…

Speaking of which the repo contains a node_modules broken link to the store

> lrwxrwxrwx  1 nixbld nixbld    109 Jun 20 21:12 node_modules -> /nix/store/xc2gv9zwsdd6l41njid58xpfq094aqgn-slippi-launcher-modules-2.11.10/deps/slippi-launcher/node_modules
l /nix/store/xc2gv9zwsdd6l41njid58xpfq094aqgn-slippi-launcher-modules-2.11.10/deps/slippi-launcher/
.r--r--r--  8.2k root  1 Jan  1970   package.json

Ah, I forgot the Teleport derivation does not use mkYarnPackage, perhaps that’s why node_modules looks different in your case.

It seems like mkYarnPackage is getting deprecated anyyway, so you might want to try instead using stdenv.mkDerivation with yarnConfigHook / yarnBuildHook as documented here.

1 Like

Okay, so I did a bit of rewriting and ended up with this:

However this fails on yarn install with Couldn't find the binary git, which is very weird since it is supposed to be offline, why would it need git ??

Of course providing git doesn’t help as it cannot resolve the host github.com
I am very very puzzled as to why it needs github in offline mode

It seems like it chokes on the node-gyp dependency, which it for some reason does not find in the offline cache. Interestingly, if I try to manually build a Yarn offline cache outside of the Nix sandbox, the resulting cache has a tarball called node-gyp-06b29aafb7708acef8b3669835c8a7857ebc92d2, but the Nix built offline cache instead has one simply called node-gyp.git.

I’m not too experienced in the Node ecosystem. Perhaps this is something you could sidestep completely by patching package.json / yarn.lock to use a version of node-gyp from npm, rather than from Git.

1 Like

You were right, patching yarn.lock makes it download everything needed and it goes on to the build phase.

Now I just have to battle with the horrors of JavaScript and patch it so it works :upside_down_face:

Thanks a bunch for your help !