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.
opened 06:35AM - 17 Apr 24 UTC
0.kind: packaging request
**Project description**
Utilities for downloading the EPG (Electronic Program… Guide) for thousands of TV channels from hundreds of sources.
**Metadata**
* homepage URL: [iptv-org.github.io/](https://iptv-org.github.io/)
* source URL: https://github.com/iptv-org/epg
* license: unlicense
* platforms: linux, darwin
---
Add a :+1: [reaction] to [issues you find important].
[reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[issues you find important]: https://github.com/NixOS/nixpkgs/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc
winter
April 17, 2024, 4:38pm
2
Please remove the npmPackFlags
and NODE_OPTIONS
attributes (they’re unnecessary here), and then post the entire build log.
efx
April 17, 2024, 5:46pm
4
I’m new to this so could be wrong.
I believe the build occurs without network access. Hence this line:
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m > api:load
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m > npx tsx scripts/commands/api/load.ts
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m (node:1563) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m --import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("file%3A///build/source/node_modules/tsx/dist/loader.mjs", pathToFileURL("./"));'
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m (Use `node --trace-warnings ...` to show where the warning was created)
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m /build/source/node_modules/axios/lib/core/AxiosError.js:89
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m AxiosError.call(axiosError, error.message, code, config, request, response);
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m ^
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m AxiosError: getaddrinfo EAI_AGAIN iptv-org.github.io
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m at Function.AxiosError.from (/build/source/node_modules/axios/lib/core/AxiosError.js:89:14)
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m at RedirectableRequest.handleRequestError (/build/source/node_modules/axios/lib/adapters/http.js:606:25)
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m at RedirectableRequest.emit (node:events:517:28)
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m at ClientRequest.eventHandlers.<computed> (/build/source/node_modules/follow-redirects/index.js:14:24)
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m at ClientRequest.emit (node:events:517:28)
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m at TLSSocket.socketErrorListener (node:_http_client:501:9)
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m at TLSSocket.emit (node:events:517:28)
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m at emitErrorNT (node:internal/streams/destroy:151:8)
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m at emitErrorCloseNT (node:internal/streams/destroy:116:3)
[0m[37;40mnpm[0m [0m[31;40mERR![0m[35m[0m at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
So perhaps one of the dependencies is trying to fetch something from 'iptv-org.github.io`?
winter
April 17, 2024, 6:14pm
6
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.
@nix { "action": "setPhase", "phase": "unpackPhase" }
Running phase: unpackPhase
unpacking source archive /nix/store/wpgp3ws19hpg2inbgzir6b0sfzrdx38y-source
source root is source
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: patchPhase
Executing npmConfigHook
Configuring npm
Validating consistency between /build/source/package-lock.json and /nix/store/pig0200vxmmz8x6prqw4ixiaqc211gb8-epg-2023.12.1-npm-deps/package-lock.json
Fixing lockfile
Installing dependencies
added 754 packages, and audited 755 packages in 4s
116 packages are looking for funding
run `npm fund` for details
found [32m[1m0[22m[39m vulnerabilities
patching script interpreter paths in node_modules
node_modules/rc/cli.js: interpreter directive changed from "#! /usr/bin/env node" to "/nix/store/wnbxah2y943l73hdmq5r7lb92lsa5f8z-nodejs-18.19.1/bin/node"
This file has been truncated. show original
winter
April 17, 2024, 6:40pm
8
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"
node.js, npm
efx
April 17, 2024, 6:58pm
10
janurskremer:
How do I do that?
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: epg-package.json.patch — paste.sr.ht
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!
efx
April 17, 2024, 7:02pm
11
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
'';
winter
April 17, 2024, 7:28pm
14
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
committed 07:56PM - 17 Apr 24 UTC
I added the patch and updated the log file.
Do I have to add a build phase now?
winter
April 17, 2024, 8:31pm
16
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?
winter
April 18, 2024, 2:07pm
19
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?