Dockerize a Node project using Nix

I’ve not been able to find an example of this nor figure out how it should work.

If I had a basic say Nest.js application. Anybody have an example of how to build it and its dependencies and wrap it into a docker container?

I tried out yarn2nix which is doing a bunch of stuff, but nothing really that will work.

1 Like

Not an expert in TypeScript, Nix nor Node packaging in Nix so I’d doubt this is production ready if that’s what you’re looking for, but I threw together an example which seems to work. Let me know if you see any potential improvements.

It uses buildNpmPackage and is based on typescript-starter repository.

Thanks, that seems to do something but which arch is it building for? I can’t run the docker image on my macOS.

Ah, I see. I’m on NixOS 23.05.589.a558f7ac29f (Stoat) x86_64 and I’ve never built Docker images for macOS so I don’t know how to make that work unfortunately.

That’s fine, I just don’t see anywhere in the code there be an architecture specific setting so in principal it should have worked on my system too?

Mac is complicated.

You want to use a VM running Linux to build the image, or a dockercontainer running Linux (which on MacOSs runs in a VM).

If you build the image on Mac directly, you’ll end up with an image that says in its metadata that it was “Linux”, but it’s binaries will be “macho” rather than “ELF”.