Npm package build failed

I’m trying to add a package to nixpkgs. The package is epg. After reading some guide this is what I came up with:

derivation.nix

{
  lib,
  buildNpmPackage,
  fetchFromGitHub,
}:

buildNpmPackage rec {
  pname = "epg";
  version = "2023.12.1";

  src = fetchFromGitHub {
    owner = "iptv-org";
    repo = pname;
    rev = "${version}";
    hash = "sha256-4YS7ZscNPPMK0V2U1uDgBKfQa0qSpa3LG0yl1zYkjDA=";
  };

  npmDepsHash = "sha256-D3poXVVq7VfOF9GhDyC9k5MOhsBSVffCokA0HSC5WCU=";

  # The prepack script runs the build script, which we'd rather do in the build phase.
  npmPackFlags = [ "--ignore-scripts" ];

  NODE_OPTIONS = "--openssl-legacy-provider";

  meta = with lib; {
    description = "Utilities for downloading the EPG (Electronic Program Guide) for thousands of TV channels from hundreds of sources.";
    homepage = "https://github.com/iptv-org/epg";
    license = licenses.unlicense;
    maintainers = with maintainers; [ janurskremer ];
  };
}

default.nix

{
  pkgs ? import <nixpkgs> { },
}:
pkgs.callPackage ./derivation.nix { }

First lines of the npm error message:

npm ERR! code 1
npm ERR! path /build/source
npm ERR! command failed
npm ERR! command sh -c npm run api:load
npm ERR! > api:load
npm ERR! > npx tsx scripts/commands/api/load.ts
...

What am I missing? I tried it on a x84_64-darwin and a x84_64-linux machine, both fail.

Please remove the npmPackFlags and NODE_OPTIONS attributes (they’re unnecessary here), and then post the entire build log.

I’m new to this so could be wrong.
I believe the build occurs without network access. Hence this line:

So perhaps one of the dependencies is trying to fetch something from 'iptv-org.github.io`?

How would I allow that?

You want it to not run the postinstall script (which is making the network request) during the build. Set npmInstallFlags = [ "--ignore-scripts" ].

I updated the log file but I got the same message.

My bad, I didn’t read the log close enough. Can you just patch out the postinstall line in the package.json for now? I’ll need to take a closer glance at how to do it with an npm flag later, but patching out that line will get you the same result.

How do I do that?

Maybe I need something like:

npm pkg set scripts.postinstall="echo no-postinstall"

Great question! I’ve not done this before but I’m sure there are some good examples of how to patch an upstream file.

The npm set idea is great too. That might work.

I’m understanding winter correctly, we want to create a git patch.
In my case, I cloned the epg project, edited the line, then ran git diff
I saved that patch output here: https://paste.sr.ht/~efx/20fc8ddf72177b5081d1145ed12bc402da3bb005

Then, we can put the patch wherever our derivation.nix is, load it, and apply.
That part I’m unsure how to do but I’m sure someone can give us a hand!

ha, even better, @jonringer answered it for us in splendid tutorial: https://www.youtube.com/watch?v=5K_2RSjbdXc

1 Like

General question: Will I be able to use this package afterwards? Like for example the cron job flag. Can I set this up as a systemd service?

What if I do something like this:

patchPhase = ''
      sed -i 's/Hello, world!/Hello, Nix!/g' src/hello.c
    '';

Either a patch/diff file or sed works (though you’ll want it in postPatch):

postPatch = ''
  sed -i "s/postinstall/d" package.json
'';
1 Like

I added the patch and updated the log file.

Do I have to add a build phase now?

This isn’t related to the absence of a build script, but it looks like this script doesn’t have any way to be installed using npm install. You’ll need to patch it so that it can run as a standalone program, instead of npm scripts, or create wrappers to do so.

Oh, this sounds complicated.

Do I need to do something along these lines?

Or are there mechanisms in Nix to do this?

No, none of those would work, as there’s no entrypoint to the program – all the functionality is exposed as npm scripts.

So is there even a solution or do I need to find another program?