Issues using custom derivation as a service

Hey! I’m new to nix and I have run into few issues along my way, however this one is really bothering me, I have a funny feeling that I’m missing e.g piece from my setup, or it has syntax error etc.
Anyways, Im supposed to build derivation from custom nodejs app and then run it as a systemd service, my nodejs app is already built and it works as is.
e.g ExecStart = "${pkgs.nodejs-18_x}/bin/node ${my-app} where my-app is just imported directly from folder.
However after building the derivation and checking that it exists in nix-store, containing the same data under my-app-derivation/bin/my-app I can’t seem to use it like ExecStart = “${pkgs.my-app-derivation}/bin/my-app” so I’m wondering what I’m doing wrong here.

I have also placed the my-app-derivation to environment.systemPackages.

The error Im getting is “error: attribute ‘my-app-derivation’ missing”.

For context, what I’ve gathered is I need to make custom derivation so that I can use overlay for rebuilding application within an image after user makes changes to it in environment without dependencies and internet connection.

What you’re saying looks vaguely correct, but clearly nix doesn’t agree.

Kind of hard to debug code from hearsay, can you share your code?

Sounds like you missed the overlays part of documentation.
nixpkgs, pkgs var in your code, is a collection of community packages from github/NixOS/nixpkgs
Your package isn’t there, so you have to import it directly or add as overlay to nixpkgs.

That’s not needed if you add the derivation directly to environment.systemPackage.

Edit: Ah! But it is if you try to access it as pkgs.mything. Just use ${mything} instead of faffing around with overlays, in that case - either way, if we could see the code we could give more helpful advice.

1 Like