imagemin / imagemin-optipng

optipng plugin for imagemin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provide env var for passing optipng binary path?

AlexChalk opened this issue · comments

I'm on nixos, where it looks like the regular linux binary from optipng-bin fails to execute. For reference, here's how the binary is compiled on nixos: https://github.com/NixOS/nixpkgs/blob/nixos-20.09/pkgs/tools/graphics/optipng/default.nix

I see that this package (in my case) downloads a precompiled binary using optipng-bin and returns the path to the binary:

return execBuffer({
input: buffer,
bin: optipng,
args: arguments_
});

Are you ok with allowing users to specify an override of this path? I'm imagining using it something like this: OPTIPNG_EXECUTABLE_PATH=path/to/optipng yarn start.

Happy to provide the PR if you approve of this strategy!

That said, if I can get this working, I guess I might run into the same problem with mozjpeg and other imagemin packages: https://github.com/NixOS/nixpkgs/blob/nixos-20.09/pkgs/applications/graphics/mozjpeg/default.nix

I've taken a closer look, and the above solution would indeed involve passing many paths.

Instead, I ended up building a nix sandbox to run these binaries that seems to be working ok, I have the code below in default.nix in my project root, then I run build commands using nix-shell --argstr command "build command":

{ command ? "bash" }:

with import <nixpkgs> {};

(pkgs.buildFHSUserEnv {
  name = "website-npm-deps";
  targetPkgs = pkgs: (with pkgs;
  [
    # For imagemin binaries
    zlib
    libpng
  ]);

  runScript = ''
    #!@shell@
    exec ${command}
  '';
}).env

Closing as this is a good solution for my use case :).