NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.39k stars 13.61k forks source link

Package request: Decent Sampler #238499

Closed adam248 closed 8 months ago

adam248 commented 1 year ago

Decent Sampler

I am asking for the standalone app to be packaged. This way you can just plugin a MIDI keyboard and play music.

I am not asking for automatic VST, VST3, *.so, linking. So you can just run the DecentSampler binary directly and that is it.

I have tried just running it directly in NixOS but I get this error: bash: ./DecentSampler: cannot execute: required file not found

Project description

The Decent Samples plugin is a FREE sample player plugin that allows you to play sample libraries in the DecentSampler format (files with extensions: dspreset and dslibrary). It is available in the following formats:

- Windows (32-bit/64-bit): VST, VST3, AAX, Standalone
- Mac (Intel & M1): VST, VST3, AU, AAX, Standalone
- Linux (Intel 64-bit): VST, VST3, Standalone
- [iOS: AUv3, Standalone](https://apps.apple.com/us/app/decent-samples/id1530441977)

This app automatically downloads samples from the net, so it needs a mutable directory. I currently do not know the default dir, but will update when I figure that out.

Metadata

Important Note about Linux builds

There are two different builds for linux. One tries to staticly link needed dependencies and the other dynamically.

Dropbox API downloading You need to have ?dl=1 to get the direct download link.

adam248 commented 1 year ago

This is the Arch AUR version

https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=decent-sampler-bin

adam248 commented 1 year ago

This is the closest I could get, but when I try to run DecentSampler binary it segfaults.

{ lib, stdenv, fetchzip, patchelf, ripgrep, alsa-lib, freetype, nghttp2 }:

stdenv.mkDerivation rec {
  pname = "decent-sampler";
  version = "1.8.12";
  static = "-Static";
  dynamic = "-Dynamic";
  type = static;

  src = fetchzip {
    url = "https://www.dropbox.com/sh/dwyry6xpy5uut07/AADhKQCQZt9HYZhXL1d-6pICa/Decent_Sampler-${version}${type}-Linux-x86_64.tar.gz";
    sha256 = "sha256-9Xjo8Jk4c6dCjz6Yd0h5FKKhpRz3VZCCsbVoO/MFL1k=";
  };

  nativeBuildInputs = [ patchelf ripgrep ];
  buildInputs = [ alsa-lib freetype nghttp2 ];

  prePatch = ''
    echo Starting Patch
    patchelf --print-interpreter DecentSampler
    echo REQUIRED LIBARIES... -----------------------------
    patchelf --print-needed DecentSampler
    echo SEARCH ...............
    ldd DecentSampler | rg 'not found'
    echo REQUIRED LIBARIES... -----------------------------
  '';

  installPhase = ''
    ls
    mkdir -p "$out/bin"
    cp ./DecentSampler "$out/bin/"
    cp ./DecentSampler.so "$out/bin"
    cp -r ./DecentSampler.vst3 "$out/bin"
  '';

  preFixup = let
    libPath = lib.makeLibraryPath [
        nghttp2  # libnghttp2.so
        alsa-lib # libasound.so
        freetype # libfreetype.so
    ];
  in ''
    patchelf \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      --set-rpath "${libPath}" \
      $out/bin/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.unfree;
    platforms = platforms.linux;
  };
}
./result/bin/DecentSampler
Segmentation fault (core dumped)
adam248 commented 1 year ago

Tried using autoPatchelfHook

{ lib, stdenv, fetchzip, patchelf, ripgrep, alsa-lib, freetype, nghttp2, autoPatchelfHook }:

stdenv.mkDerivation rec {
  pname = "decent-sampler";
  version = "1.8.12";
  static = "-Static";
  dynamic = "-Dynamic";
  type = static;

  src = fetchzip {
    url = "https://www.dropbox.com/sh/dwyry6xpy5uut07/AADhKQCQZt9HYZhXL1d-6pICa/Decent_Sampler-${version}${type}-Linux-x86_64.tar.gz";
    sha256 = "sha256-9Xjo8Jk4c6dCjz6Yd0h5FKKhpRz3VZCCsbVoO/MFL1k=";
  };

  nativeBuildInputs = [ autoPatchelfHook patchelf ripgrep ];
  buildInputs = [ alsa-lib freetype nghttp2 ];

  installPhase = ''
    install -m755 -D DecentSampler $out/bin/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.unfree;
    platforms = platforms.linux;
  };
}
adam248 commented 11 months ago

I have raised an issue with the dev here: https://www.decentsamples.com/bugtracker/view.php?id=37 Anyone who wishes to comment on the bugtracker to help get it resolved will be most welcome. Thanks

adam248 commented 9 months ago

I have some good news. I managed to get Decent Sampler working on NixOS via pkgs.buildFHSEnv. Since this is the first time I am using this build method I am not sure how this is working, but I am posting the details here now to keep a good log of what is happening. I also am not sure how to package this for nixpkgs.

Here I am able to run DecentSampler binary without it being patched (manually or via autoPatchelfHook). So here you just download DecentSampler as a normal Linux download then point this shell.nix file's runScript attribute at the Decent Sampler binary (./nixpkgs/source/DecentSampler) and it just works™.

I simply copied the example from https://ryantm.github.io/nixpkgs/builders/special/fhs-environments/ and added freetype and nghttp2.

I have tried removing ++ (with pkgs.xorg; [ libX11 libXcursor libXrandr ]) but it goes back to segfaulting. So this might be the reason?

# file: shell.nix
# use nix-shell to run
{ pkgs ? import <nixpkgs> {} }:

(pkgs.buildFHSEnv {
  name = "simple-x11-env";
  targetPkgs = pkgs: (with pkgs; [
    udev
    alsa-lib 
    freetype 
    nghttp2
  ]) ++ (with pkgs.xorg; [
    libX11
    libXcursor
    libXrandr
  ]);
  multiPkgs = pkgs: (with pkgs; [
    udev
    alsa-lib
  ]);
  runScript = "./nixpkgs/source/DecentSampler";
}).env

Can anyone explain why this works when the other methods end with a segfault?

adam248 commented 9 months ago

Did some more digging and it appears that only pkgs.xorg.libX11 is needed. If I remove that then we go back to segfaulting.

adam248 commented 9 months ago
{ pkgs ? import <nixpkgs> {} }:

(pkgs.buildFHSEnv {
  name = "decent-sampler-env";
  targetPkgs = pkgs: (with pkgs; [
    xorg.libX11

    alsa-lib 
    freetype 
    nghttp2

  ]);
  runScript = "./nixpkgs/source/DecentSampler";
}).env

Is the simplest FHSEnv needed....

adam248 commented 9 months ago
{ pkgs, lib, stdenv, fetchzip, autoPatchelfHook, alsa-lib, freetype, nghttp2}:

stdenv.mkDerivation rec {
  pname = "decent-sampler";
  version = "1.9.8";
  static = "Static";
  dynamic = "Dynamic";
  type = static; # this will get patched by autoPatchelfHook

  src = fetchzip {
    url = "https://www.dropbox.com/sh/dwyry6xpy5uut07/AACSicfMpcDXSbYg2UqIIymLa/Decent_Sampler-${version}-Linux-${type}-x86_64.tar.gz?dl=0";
    sha256 = "sha256-O/0R70tZOmSGgth6nzt4zPiJr1P8890uzk8PiQGnC6M=";
  };

  nativeBuildInputs = [ autoPatchelfHook ];
  buildInputs = [ pkgs.xorg.libX11 alsa-lib freetype nghttp2 ];

  installPhase = ''
    mkdir -p $out/{bin,lib}
    install -m755 -D DecentSampler $out/bin/
    install -m755 -D DecentSampler.so $out/lib/
  '';

  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;
  };
}

Updated this to have pkgs.xorg.libX11 still doesn't work. It seems that pkgs.buildFHSEnv is working for another reason other than simply pkgs.xorg.libX11.

nixos-discourse commented 9 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/trying-to-contribute-to-nixpkgs-but-only-buildfhsenv-works-for-binary/36579/1

adam248 commented 9 months ago

@tobiasBora did a great article on stack exchange that might help... https://unix.stackexchange.com/questions/522822/different-methods-to-run-a-non-nixos-executable-on-nixos

However, it appears that an example of how to use buildFHSEnv along with mkDerivation is missing. I will read it again later....

adam248 commented 9 months ago

I have finally figured it out by copying this package's methodology: https://github.com/NixOS/nixpkgs/blob/12a0a9da151da0750988c8dd489c5794d7cc7c83/pkgs/development/tools/hover/default.nix

Here is the final and tested (on my machine) default.nix file:

# 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 "DecentSampler" "$out/bin/decent-sampler"
    '';

  };
in

buildFHSEnv {
  inherit pname version;

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

  runScript = "decent-sampler";

  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 ];
  };
}
adam248 commented 9 months ago

@PowerUser64 just letting you know that I have now made a pull request, please add a thumbs up to it to help get it merged.... thanks