dream2nix
dream2nix copied to clipboard
How can I specify a dream2nix-built dependency for overrides?
I'm trying to package nodejs sharp and I'm having no luck getting it to compile because node-gyp is missing and it doesn't have it in its package.json.
To complicate matters, node-gyp from nodePackages is broken.
So ideally I'd call some function on dream2nix with npm:[email protected] and I'd get a package out of it. I already checked, node-gyp builds fine if I build it as a dependency.
Have you tried injecting the missing dependency?
There is an example of this in the README.
@tinybeachthor ah nice I missed that, thanks! It's not ideal though because node-gyp has a ton of dependencies, and they'd have to be added as well unless node-gyp is already a dependency of the app. Meaning, it would be hard to ship it in the default overrides. :thinking: Maybe we need to copy the nodePackages setup from nixpkgs and then we can refer to that.
I'm trying to package nodejs sharp and I'm having no luck getting it to compile because node-gyp is missing and it doesn't have it in its package.json.
How does it build with npm, if ndoe-gyp is missing? Does npm include that dependency by default? If it does, then maybe we should as well.
Yes I realized that today, node-gyp just ships with npm and all scripts have it in their path when npm calls them. I was bypassing npm with a specific build script and then it didn't have it. Would indeed be best to provide it in the builder path.
Perhaps the cleanest way would be to write _d2nBuild_ as a script to package.json, which runs the provided script, and then npm run _d2nBuild_. That way it's also recorded in the package.
Perhaps the cleanest way would be to write d2nBuild as a script to package.json, which runs the provided script, and then npm run d2nBuild. That way it's also recorded in the package.
Yes that makes sense. This would ensure that the PATH is setup exactly like with the usual build script.
Actually I realized that build is a special case, because it usually requires devDependencies. So in fact the translator should check if build is needed and if so, the package gets both devModules and prodModules as dependencies.
I think we should never automatically exclude devDependencies for top-level packages. Some packages might not have a build script and instead use some other command for building. We can never be really sure that devDependencies can be omitted.
Closing in favor of https://github.com/nix-community/dream2nix/issues/360
Just posting here because sharp is a rather common dependency and people might stumble upon this when searching. Node-gyp seems to be included with recent npm releases, all I needed for sharp was to add libvips and pkgconfig for node to find it:
packageOverrides = {
sharp = {
"add-vips" = {
buildInputs = old: with pkgs; old ++ [ pkgconfig vips];
};
};
};
@phaer Would you mind contributing that fix to ./overrides/nodejs/default.nix ?
Then the override will automatically be included for all users.
@DavHau Good point, just added it to https://github.com/nix-community/dream2nix/pull/370