nix-community / yarn2nix

Generate nix expressions from a yarn.lock file [maintainer=???]
GNU General Public License v3.0
123 stars 61 forks source link

mkYarnNix tries to update lockfile by sending requests to the network. #82

Closed arianvp closed 6 years ago

arianvp commented 6 years ago

I get

building '/nix/store/ibyvvfgvvmaxplmzv613diwx7wcz0w4n-yarn.nix.drv'...
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo ENOTFOUND codeload.github.com codeload.github.com:443
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
builder for '/nix/store/ibyvvfgvvmaxplmzv613diwx7wcz0w4n-yarn.nix.drv' failed with exit code 1
error: while evaluating the attribute 'preBuild' of the derivation 'vault-0.11.2' at /home/arian/Projects/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:177:11:
while evaluating the attribute 'node_modules' of the derivation 'vault-ui' at /home/arian/Projects/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:177:11:
while evaluating the attribute 'buildPhase' of the derivation 'vault-modules-0.0.0' at /home/arian/Projects/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:177:11:
while evaluating 'importOfflineCache' at /home/arian/Projects/nixpkgs/pkgs/development/tools/yarn2nix/default.nix:38:24, called from /home/arian/Projects/nixpkgs/pkgs/development/tools/yarn2nix/default.nix:61:22:
build of '/nix/store/ibyvvfgvvmaxplmzv613diwx7wcz0w4n-yarn.nix.drv' failed
arianvp commented 6 years ago

This only seems to show up if src != ./. if that helps...

arianvp commented 6 years ago
let pkgs = import <nixpkgs> {}; in
pkgs.yarn2nix.mkYarnPackage rec {
  name = "vault-ui";
  src2 = pkgs.fetchFromGitHub {
    owner = "hashicorp";
    repo = "vault";
    rev = "v0.11.2";
    sha256 = "0lckpfp1yw6rfq2cardsp2qjiajg706qjk98cycrlsa5nr2csafa";
  };
  src = "${src2}/ui";
}

doesn't work.

whilst this works. Only difference being the src directive :/

git clone git@github.com:hashicorp/vault
cd vault
let pkgs = import <nixpkgs> {}; in
pkgs.yarn2nix.mkYarnPackage rec {
  name = "vault-ui";
  src = ./ui;
}
arianvp commented 6 years ago

Smaller reproduce:

let
  pkgs = import <nixpkgs> {};
  src = "${pkgs.fetchFromGitHub { 
    owner = "hashicorp";
    repo = "vault";
    rev = "v0.11.2";
    sha256 = "0lckpfp1yw6rfq2cardsp2qjiajg706qjk98cycrlsa5nr2csafa"; 
  }}/ui";
in
  pkgs.yarn2nix.mkYarnNix "${src}/yarn.lock"

The error seems to come from the yarn2nix binary itself

arianvp commented 6 years ago

When I run yarn2nix manually (and thus have network, because outside of the nix sandbox) I get:

[arian@t430s:~/Projects/vault]$ yarn2nix --no-patch --lockfile /nix/store/dk3xs6za5ajgmkd1pmwqn761bdnkzjph-source/ui/yarn.lock
found changes in the lockfile /nix/store/dk3xs6za5ajgmkd1pmwqn761bdnkzjph-source/ui/yarn.lock

Is there a way to force yarn2nix to no try to update yarn.lock ? I want to use the vendored version.

--no-patch doesn't seem to do it. eventhough it says so on the tin

arianvp commented 6 years ago

Related to https://github.com/moretea/yarn2nix/issues/65

Apparently, yarn2nix parses codeload.github.com urls incorrectly, causing it to think that there's no hash

arianvp commented 6 years ago

Ah apparently it isn't implemented yet: https://github.com/moretea/yarn2nix/issues/1

arianvp commented 6 years ago

The total problem:

Vault has yarn.lock dependencies like:

Duration.js@icholy/Duration.js#golang_compatible:
  version "2.0.0"
  resolved "https://codeload.github.com/icholy/Duration.js/tar.gz/cb1c58efc2772ef0f261da9e2535890734a86417"
  dependencies:
    chai "~1.7.2"
    mocha "~1.13.0"

Because git dependencies do not contain the SHA hash, yarn2nix tries to update these in the .lock file by modifying it. However, if this lock file is inside the /nix/store than this can't be modified and it fails.

Also, if it gets executed in side a nix derivation, there's no network access, so it also fails.

I don't think we can really solve this easily, except from running yarn2nix externally

albertov commented 6 years ago

We've seen that this problem occurs when yarn.lock is generated by an older version of yarn which doesn't assign hashes to every package. This causes yarn2nix to try to fetch the files to calculate them which breaks when called from mkYarn2nix. A workaround is to use a version of yarn >= 1.10.1 which always includes an "integrity" field with a hash which satisifies yarn2nix.

zimbatm commented 6 years ago

thanks @albertov , added to the README

ghost commented 5 years ago

This is still happening to me, even when I generate a fresh lockfile with yarn 1.15.2.

The entry in package.json: "emoji-mart": "Gargron/emoji-mart#build", yarn.lock does not contain a hash for this entry. When calling mkYarnPackage I am using a local path as source: src = /home/pbb/proj/mastodon/;

zimbatm commented 5 years ago

maybe, or maybe it's a similar but different issue. It's better to create a new issue with a repro so that it can be triaged properly