4

I'm packaging a node script with an external dependency (GraphicsMagick), and when attempting to override the derivation generated from node2nix I get the error:

wrapProgram: command not found

The following text goes into detail of what I've tried to solve this error.


Reproducing the problem from scratch

I've created a minimal git repository that reproduces this problem if you'd just like to take a look there. Else, the steps to reproduce the problem are below.

Initial Shell Session:

In an empty directory, run:

npm init -y
npm install --save gm
curl https://i.imgur.com/addSfQi.jpg > image.png

(npm version: 5.6.0 & node version v8.9.4)

Create index.js

#!/usr/bin/env node

const path = require("path"); // node.js builtin
const gm = require("gm"); // GraphicsMagick module

const imagePath = path.join(__dirname, "image.png");

// Flip image horizontally and write to disk
gm(imagePath)
  .flop()
  .write(imagePath, error => {
    console.log("error:", error);
  });

Add a "bin" section to package.json:

"bin": "index.js"

Generate *.nix files with node2nix

node2nix -8 -l package-lock.json

Create override.nix

{ pkgs ? import <nixpkgs> {}
, system ? builtins.currentSystem
}:

let
  nodePackages = import ./default.nix {
    inherit pkgs system;
  };
in
nodePackages // {
  package = nodePackages.package.override (oldAttrs: {
    postInstall = ''
      wrapProgram "$out/bin/test-nodejs-gm-nixpkg" --prefix PATH : "${pkgs.graphicsmagick}/bin"
    '';
  });
}

Build nix package

nix-build override.nix -A package

The above fails with:

/nix/store/*/setup: line 95: wrapProgram: command not found


Helpful Resources

Jay
  • 18,959
  • 11
  • 53
  • 72
  • 5
    I believe you want to add `nativeBuildInputs = oldAttrs.nativeBuildInputs or [] ++ [ pkgs.makeWrapper ]` within your override to make `wrapProgram` available. – ppb Apr 07 '18 at 20:19
  • @ppb Adding `nativeBuildInputs = [ pkgs.makeWrapper ];` solved it. If you throw your comment into an answer I'll accept it. Also: If you don't mind me asking, where can I learn more about this? Thanks! – Jay Apr 07 '18 at 20:35
  • 2
    @x9hb8wcy6quezjk `makeWrapper` is covered in the [nixpkgs manual](https://nixos.org/nixpkgs/manual/#ssec-stdenv-functions) and the [source](https://github.com/NixOS/nixpkgs/tree/master/pkgs/build-support/setup-hooks) is within the `build-support` directory of the repo. – brocking Apr 16 '18 at 11:24

1 Answers1

6

wrapProgram is contained within the makeWrapper package.

nativeBuildInputs = oldAttrs.nativeBuildInputs or [] ++ [ pkgs.makeWrapper ];

As mentioned by @ppb in the comments.

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286