nix-community / npmlock2nix

nixify npm based packages [maintainer=@andir]
Apache License 2.0
130 stars 42 forks source link

npmlock2nix.build doens't work #113

Closed winston0410 closed 2 years ago

winston0410 commented 3 years ago

I have this derivation:

{ pkgs, lib, stdenv, npmlock2nix, ... }:

# https://github.com/prettier/plugin-pug
let
  version = "743f5aafa11d161537bbcd614fe5af81944a8d2f";
  source = pkgs.fetchFromGitHub {
    owner = "winston0410";
    repo = "plugin-pug";
    rev = version;
    sha256 = "sha256-SUH94XnD0a0JX3SQQmHB9SWnS7oVP9BiBcS9a7o4wm0=";
  };
in (npmlock2nix.build {
  pname = "prettier-plugin-pug";
  inherit version;
  buildInputs = [ pkgs.nodejs pkgs.git ];
  src = source;
  buildCommands = [ "npm run build" ];
  installPhase = ''
    ls -a $src
  '';
})

And I got this error:

error: builder for '/nix/store/h707cvl3jk62c1kn0s9hymnwmdihvdfp-?prettier?plugin-pug-1.16.7.drv' failed with exit code 1;
       last 10 log lines:
       >
       > added 1843 packages from 762 contributors in 49.28s
       >
       > 147 packages are looking for funding
       >   run `npm fund` for details
       >
       > patching script interpreter paths in node_modules/.bin
       > installing
       > mkdir: missing operand
       > Try 'mkdir --help' for more information.
       For full logs, run 'nix log /nix/store/h707cvl3jk62c1kn0s9hymnwmdihvdfp-?prettier?plugin-pug-1.16.7.drv'.
winston0410 commented 3 years ago

I still get this error when I change the derivation to this, seems the error comes from npmlock2nix.node_modules

{ pkgs, lib, stdenv, npmlock2nix, ... }:

# https://github.com/prettier/plugin-pug
let
  version = "743f5aafa11d161537bbcd614fe5af81944a8d2f";
  src = pkgs.fetchFromGitHub {
    owner = "winston0410";
    repo = "plugin-pug";
    rev = version;
    sha256 = "sha256-SUH94XnD0a0JX3SQQmHB9SWnS7oVP9BiBcS9a7o4wm0=";
  };
  nodeModules = npmlock2nix.node_modules {
    inherit src;
  };
in (stdenv.mkDerivation {
  pname = "prettier-plugin-pug";
  inherit version src;
  buildInputs = [ pkgs.nodejs ];
  buildPhase = ''
    echo ${nodeModules}
  '';
  installPhase = ''
    echo "hello" > $out
  '';
})
andir commented 3 years ago

Can you please post the full log of the failing command?

winston0410 commented 3 years ago

@andir This is the full log. I cannot paste it out because it is too long. debug.log

andir commented 3 years ago

This smells like $out is unset when the install phase is hit (https://github.com/nix-community/npmlock2nix/blob/33eb3300561d724da64a46ab8e9a05a9cfa9264b/internal.nix#L382). Can you set postBuild to echo $out in the node_modules call ?

winston0410 commented 3 years ago

I updated it to this:

{ pkgs, lib, stdenv, npmlock2nix, ... }:

# https://github.com/prettier/plugin-pug
let
  version = "743f5aafa11d161537bbcd614fe5af81944a8d2f";
  src = pkgs.fetchFromGitHub {
    owner = "winston0410";
    repo = "plugin-pug";
    rev = version;
    sha256 = "sha256-SUH94XnD0a0JX3SQQmHB9SWnS7oVP9BiBcS9a7o4wm0=";
  };
  nodeModules = npmlock2nix.node_modules {
    inherit src;
  };
in (stdenv.mkDerivation {
  pname = "prettier-plugin-pug";
  inherit version src;
  buildInputs = [ pkgs.nodejs ];
  buildPhase = ''
    echo ${nodeModules}
  '';
  postBuild = ''
    echo $out
  '';
  installPhase = ''
    echo "hello" > $out
  '';
})

And this is the error. Looks like the same to me. debug.log

winston0410 commented 3 years ago

The problem is in this line, which $out is empty https://github.com/nix-community/npmlock2nix/blob/33eb3300561d724da64a46ab8e9a05a9cfa9264b/internal.nix#L382

But this seems to be idiomatic nix? I think I have seen something similar in tutorials.

winston0410 commented 3 years ago

A repo for reproducing this issue: https://github.com/winston0410/build-nodejs

winston0410 commented 3 years ago

Try to fix this in this pr

https://github.com/nix-community/npmlock2nix/pull/114

sephii commented 2 years ago

This just happened to me as well.

The problem was caused by the name attribute in package-lock.json containing special characters (in my case @sephii/foobar). I noticed the special characters @ and / got replaced by ? during the build process, This caused the mkdir command to fail, probably because the ? characters got interpreted in some way? I changed the name attribute to something without special characters and it fixed the problem, but I think either the $out argument should be quoted, or the special characters in the package name shouldn’t be replaced by ?. Edit: ah I didn’t check the PR, which came to the same conclusions.

winston0410 commented 2 years ago

@sephii Yes exactly. I hope they can merge it my PR to fix this.