Help with first package

Hello All,

I am trying to package pangolin for nix, and i’m getting stuck on the last part.

i am looking at the dockerfile for inspiration but i believe something is going wrong with the copying paths.
pkgs/by-name/fo/fossorial/frontend.nix

installPhase = ''
    runHook preInstall

    mkdir -p $out/.next/

    cp package.json package-lock.json $out/

    cp -r .next/standalone/ $out/
    cp -r .next/standalone/.next $out/

    cp -r .next/static $out/.next/static
    cp -r dist $out/dist
    cp -r init $out/dist/init

    cp server/db/names.json $out/dist/names.json
    cp -r public $out/public

    cp -r node_modules $out/
    runHook postInstall
  '';

nixos/modules/services/networking/fossorial.nix

...
systemd.services.fossorial = {
      description = "Fossorial Service";
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];

      environment = {
        NODE_OPTIONS = "enable-source-maps";
        NODE_ENV = "development";
        ENVIRONMENT= "prod";
      };

      serviceConfig = {
        User = "fossorial";
        Group = "fossorial";
        GuessMainPID = true;
        WorkingDirectory = cfg.dataDir;
        UMask = 7;
        ExecStartPre = utils.escapeSystemdExecArgs [
          (lib.getExe pkgs.nodejs_22)
          "${pkgs.fossorial}/dist/migrations.mjs"
        ];
        ExecStart = utils.escapeSystemdExecArgs [
          (lib.getExe pkgs.nodejs_22)
          "${pkgs.fossorial}/dist/server.mjs"
        ];
...

–>> link to my fork for full config files if more context is needed
anyone have any idea why i cant find the production build?
journalctl -eu fossorial gives

node[287186]: 2025-04-23T09:51:04.609Z [warn]: Email SMTP configuration is missing. Emails will not be sent.
node[287186]: 2025-04-23T09:51:04.796Z [info]: API server is running on http://localhost:3000
node[287186]: 2025-04-23T09:51:04.796Z [info]: Internal server is running on http://localhost:3001
node[287186]: Error: Could not find a production build in the '.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs...
node[287186]:     at async createNextServer (../../../nix/store/mqb6z0py0q97v4p1jvr6vwhkx5fw01ij-pangolin-frontend-1.2.0/dist/server.mjs:20576:3)
node[287186]:     at async startServers (../../../nix/store/mqb6z0py0q97v4p1jvr6vwhkx5fw01ij-pangolin-frontend-1.2.0/dist/server.mjs:21635:22)

the .next folder is visible and readable:
tree result/:

 dist -> /nix/store/fgmdb49h76bhl5jkw78fhz00wnxci1fv-pangolin-frontend-1.2.0/dist
├── .next -> /nix/store/fgmdb49h76bhl5jkw78fhz00wnxci1fv-pangolin-frontend-1.2.0/.next
├── node_modules -> /nix/store/fgmdb49h76bhl5jkw78fhz00wnxci1fv-pangolin-frontend-1.2.0/node_modules
├── public -> /nix/store/fgmdb49h76bhl5jkw78fhz00wnxci1fv-pangolin-frontend-1.2.0/public
└── standalone -> /nix/store/fgmdb49h76bhl5jkw78fhz00wnxci1fv-pangolin-frontend-1.2.0/standalone

What’s going wrong here? Is there some weird nextjs folder restructuring that I should be doing?

Look into what path it’s looking relative to. It might not be the path of the file being executed, but relative to the working directory, which you have set to cfg.dataDir and not the derivation’s $out.

The Dockerfile you linked sets the workdir to /app, the equivalent should be WorkingDirectory = "${pkgs.fossorial}". Of course, that will cause trouble if the service tries to write under the working directory.

yea thats the problem. The installphase creates a folder config which is needed later in the service.
Ive also tried to pass it in via BindPaths = ${pkgs.fossorial}, but that still gives the same error

But it’s weird to me that this step in particular fails, since both the migrations called by PreExec

(lib.getExe pkgs.nodejs_22)
         "${pkgs.fossorial}/dist/migrations.mjs"

succeed, and the node_modules needed to call services are found as well…