Preferred way to run a node server?

I’d like to set up homebridge on NixOS. Homebridge is a nodejs server that emulates the Apple HomeKit API to allow for connecting many non-apple-certified devices to the Home app for control. It is distributed as an npm package. It also relies on many plugins which are distributed as npm packages.

What’s the best way to deploy something like this on NixOS? I would like it to start on boot and restart on failure. Do I need to write my own module? If so how do I deal with the highly variable set of npm package plugins?

Thanks!

Do I need to write my own module?

Yes, I usually write modules like I would do for nixpkgs (with options and documentations), import them into my configuration using imports and configure the software normally. Bu you don’t need to export options, you can just “hard-code” your settings in.

If you need some inspiration look at the dnschain module, which is a nodejs dns server.

If so how do I deal with the highly variable set of npm package plugins?

Depending on what you need exactly you would either use the generated package set in nixpkgs or call node2nix in your repository.

1 Like