I am trying to create a package for a nodejs app defined at AceMagic-S1-LED-TFT-Linux/s1panel at main · tjaworski/AceMagic-S1-LED-TFT-Linux · GitHub (All relevant code is in s1panel directory).
The first issue I found with the app(s) is regarding package-lock.json
file(s) are not present in the repo, so in the end I decided to fork it and add them with other minor configuration files. After that, I was able to create a nix package but, the code is split in two coupled nodejs folders/apps: main and api/gui. If you have a look at the install script you can see first is performing npm install
in s1panel
then npm install
in s1panel/gui
and finally build the gui app npm run build
, later the service is launched by running the main.js
file in s1panel
folder.
I would like to know if there is a way to use buildNpmPackage in this scenario, picking up dependencies from two sources, doing build on the second one.
This is what I have been trying:
{
lib,
buildNpmPackage,
# importNpmLock,
fetchNpmDeps,
npmHooks,
pkgs,
pkg-config,
nodejs_22,
makeWrapper,
lm_sensors,
pixman,
cairo,
pango,
libudev-zero,
}:
let
pname = "s1panel";
version = "2024-04-09";
src = pkgs.fetchgit {
url = "https://github.com/jriguera/AceMagic-S1-LED-TFT.git";
sparseCheckout = [
"s1panel"
];
rev = "refs/tags/0.1.0";
hash = "sha256-QyO/8CXwYclDdMEJJj5qHQsMbnqYfWGXcvWLBsdQvA0=";
};
npmDepsMain = fetchNpmDeps {
name = "npm-deps-main";
src = "${src}/s1panel";
hash = "sha256-lD5AVFE5fPPZ9FV6DSUNE0w+bnoDoqttbV86Cp7FpuA=";
};
npmDepsGui = fetchNpmDeps {
name = "npm-deps-gui";
src = "${src}/s1panel/gui";
hash = "sha256-Jc16eK59dNqX85SpBH8htIiwX5pG9bwJqZDpznW/eNQ=";
};
in
buildNpmPackage {
inherit pname version;
src = "${src}/s1panel";
# This hash is generated at build time, and uniquely identifies
# the cache of NodeJS dependencies used for the build.
# npmDepsHash = lib.fakeHash;
#npmDepsHash = "sha256-lD5AVFE5fPPZ9FV6DSUNE0w+bnoDoqttbV86Cp7FpuA=";
buildInputs = [
pixman
cairo
pango
libudev-zero
];
nativeBuildInputs = [
pkg-config
makeWrapper
];
nodejs = pkgs.nodejs_22;
postPatch = ''
echo Here
npm
# Tricky way to run npmConfigHook multiple times
local postPatchHooks=() # written to by npmConfigHook
source ${npmHooks.npmConfigHook}/nix-support/setup-hook
npmRoot=. npmDeps=${npmDepsMain} npmConfigHook
npmRoot=./gui npmDeps=${npmDepsGui} npmConfigHook
echo "Done"
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r * $out
runHook postInstall
'';
# needs to be wrapped with nodejs so that it can be executed
postInstall = ''
chmod +x $out/main.js
makeWrapper $out/main.js $out/bin/s1panel --prefix PATH:"${lib.makeBinPath [nodejs_22]}"
'';
meta = with lib; {
description = "S1 Panel";
homepage = "https://github.com/tjaworski/AceMagic-S1-LED-TFT-Linux";
license = licenses.gpl3Only;
maintainers = with maintainers; [];
platforms = platforms.linux;
mainProgram = "s1panel";
};
}
I took some inspiration from this post Need help with buildNpmPackage and pagefind derivation but I am getting npm: command not found
:
warning: found empty hash, assuming 'sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='
these 2 derivations will be built:
/nix/store/vvcghkzq8fkhw1lhl22kf9963fzjalwl-s1panel-2024-04-09-npm-deps.drv
/nix/store/k8099k8s8qg95vz8bbg286ngr248z1fs-s1panel-2024-04-09.drv
building '/nix/store/vvcghkzq8fkhw1lhl22kf9963fzjalwl-s1panel-2024-04-09-npm-deps.drv'...
Running phase: unpackPhase
unpacking source archive /nix/store/v4b86bxzzj97mj5v3lfmkw5yci6lhyl3-AceMagic-S1-LED-TFT/s1panel
source root is s1panel
Running phase: patchPhase
Here
/nix/store/rnph566f9n93lnda6wrlcip5wpxmlmlb-stdenv-linux/setup: line 228: npm: command not found
note: keeping build directory '/tmp/nix-build-s1panel-2024-04-09-npm-deps.drv-54/build'
error: builder for '/nix/store/vvcghkzq8fkhw1lhl22kf9963fzjalwl-s1panel-2024-04-09-npm-deps.drv' failed with exit code 127;
last 6 log lines:
> Running phase: unpackPhase
> unpacking source archive /nix/store/v4b86bxzzj97mj5v3lfmkw5yci6lhyl3-AceMagic-S1-LED-TFT/s1panel
> source root is s1panel
> Running phase: patchPhase
> Here
> /nix/store/rnph566f9n93lnda6wrlcip5wpxmlmlb-stdenv-linux/setup: line 228: npm: command not found
For full logs, run 'nix-store -l /nix/store/vvcghkzq8fkhw1lhl22kf9963fzjalwl-s1panel-2024-04-09-npm-deps.drv'.
error: 1 dependencies of derivation '/nix/store/k8099k8s8qg95vz8bbg286ngr248z1fs-s1panel-2024-04-09.drv' failed to build