Trying to contribute to nixpkgs but only buildFHSEnv works for binary

Hi,
I have been working on trying to add my very first binary to nixpkgs called Decent Sampler.

However, I have so far only got it to work with using the pkgs.buildFHSEnv nix shell.

For a complete log of the work I have done so far please see this github issue:
https://github.com/NixOS/nixpkgs/issues/238499

My main question right now is:

Can I simply add a package to nixpkgs that makes its own FHSEnv?

This doesn’t feel like the correct way to do things in nixpkgs, but this is the only way that works as far as I can see.

So if not, then how can I find out why DecentSampler binary works in an FHSEnv and not in a normal nix package.

It seems the original developer is not going to help out with this issue, so my only hope left is the nix community.

I have fought long and hard alone, but I am finally willing to say I am out of my depth here and need a pro or at least someone with one more brain cell than me: :smiling_face:
Thank you

I have at least found the answer to my question:

Can I simply add a package to nixpkgs that makes its own FHSEnv?

Answer: Yes, this is how Steam is packaged in nixpkgs.

Now I simply have to learn how to do it…

I believe I have finally solved this issue completely and here is the fully completed package ready for nixpkgs (and I believe it is pretty simple and clean solution):

# default.nix
{ lib
, stdenv
, fetchzip
, buildFHSEnv
, alsa-lib
, freetype
, nghttp2
, xorg
, }:

let
  pname = "decent-sampler";
  version = "1.9.4";

  decent-sampler = stdenv.mkDerivation {
    inherit pname version;

    src = fetchzip {
      # dropbox link: https://www.dropbox.com/sh/dwyry6xpy5uut07/AABBJ84bjTTSQWzXGG5TOQpfa\

      # Internet Archive should be more reliable
      url = "https://archive.org/download/decent-sampler-linux-static-download-mirror/Decent_Sampler-${version}-Linux-Static-x86_64.tar.gz";
      sha256 = "sha256-O/0R70tZOmSGgth6nzt4zPiJr1P8890uzk8PiQGnC6M=";
    };

    installPhase = ''
      mkdir -p $out/bin
      install -m755 -D DecentSampler $out/bin/
    '';

  };
in

buildFHSEnv {
  name = pname;

  targetPkgs = pkgs: [
    decent-sampler
    alsa-lib
    freetype
    nghttp2
    xorg.libX11
  ];

  runScript = "DecentSampler";

  meta = with lib; {
    description = "An audio sample player";
    longDescription = ''
        Decent Sampler is an audio sample player.
        Allowing you to play sample libraries in the DecentSampler format
        (files with extensions: dspreset and dslibrary).
        It claims to be free but we currently cannot find any license
        that it is released under.
    '';
    homepage = "https://www.decentsamples.com/product/decent-sampler-plugin/";
    license = licenses.unlicense;
    platforms = platforms.linux;
    maintainers = with maintainers; [ adam248 ];
  };
}

There were so many complex examples out there that were really hard to wrap my head around but in the end my package is now the simplest example of how to use buildFHSUserEnv (aka buildFHSEnv) to make a package in nixpkgs.

I plan to update it later to enable the linking of the vst and vst3 plugins for use with Reaper and other such DAWs later.

Please let me know if this has helped anyone else…

Just for the record buildFHSEnv is a direct alias of buildFHSUserEnv