node2nix icon indicating copy to clipboard operation
node2nix copied to clipboard

Packaged node2nix applications doesn't work in dockerTools.buildImage

Open CMCDragonkai opened this issue 5 years ago • 3 comments

When attempting to turn a node2nix packaged application into something that run in a container, the image builds, but the internal executables are symlinks that point to the wrong location.

For example with https://github.com/MatrixAI/TypeScript-Demo-Lib

nix-build ./release.nix --attr docker

Results in an image where /bin/typescript-demo-lib inside the container points like this:

lrwxrwxrwx 1 0 0      54 Jan  1  1970  typescript-demo-lib -> ../typescript-demo-lib/dist/bin/typescript-demo-lib.js

But that doesn't exist, and the actual location is at:

/lib/node_modules/typescript-demo-lib/dist/bin/typescript-demo-lib.js

Any ideas to make node2nix applications workable inside containers?

CMCDragonkai avatar Sep 04 '20 04:09 CMCDragonkai

This looks like a problem with the usage of buildImage. The contents are copied to the root, rather than using an indirection like symlinkJoin or buildEnv.

You can probably fix this problem by creating a derivation producing a symlink and putting only that derivation in contents.

This is a common pitfall without an obvious solution. It will probably involve a breaking change and some technically unnecessary obstructions to make this mistake hard to write. See https://github.com/NixOS/nixpkgs/issues/94636#issuecomment-755246646

roberth avatar Oct 20 '21 12:10 roberth

We actually fixed it here: https://github.com/MatrixAI/TypeScript-Demo-Lib/pull/13#issuecomment-760574649

CMCDragonkai avatar Oct 21 '21 02:10 CMCDragonkai

Not copying a whole package to the root is a more robust solution, because it does not interfere with other root contents, it does not change locations expected to be in the store not to be in the store and it does not cause a redundant copy to take up space in the image when the package is self-referential. Many packages are, because they reference their own libraries or data files using absolute paths; even busybox references a data file this way nowadays...

roberth avatar Oct 21 '21 09:10 roberth