Nix package for an Iced app

Hello!

I recently moved to NixOS, and I wanted to make a nix package (that I might try to add it to nixpkgs :)) for an application I made with iced (which uses winit), so I was wondering if anyone have done it before so I can borrow stuff from the package file :stuck_out_tongue:

currently I have this:

{ lib
, stdenv
, fetchFromGitHub
, rustPlatform
, pkgs
}:

rustPlatform.buildRustPackage rec {
  pname = "ytdlp-gui";
  version = "0.2.5";

  src = fetchFromGitHub {
    owner = "BKSalman";
    repo = "ytdlp-gui";
    rev = "v${version}";
    sha256 = "sha256-BB2zM0EIPYkv5tMX6TCXVkLoz7HQCXVMOiEEwPJRAB0=";
  };

  cargoSha256 = "sha256-1jvCcHDfMbVxsNI1iBngx8uEUkENeM7sbzSL0DgpK+o=";

  nativeBuildInputs = with pkgs; [
    pkg-config
    cmake
  ];

  buildInputs = with pkgs; [
    # rust-bin.stable.latest.default
    fontconfig

    vulkan-headers
    vulkan-loader

    # libxkbcommon

    # WINIT_UNIX_BACKEND=wayland
    wayland

    # WINIT_UNIX_BACKEND=x11
    xorg.libXcursor
    xorg.libXrandr
    xorg.libXi
    xorg.libX11
  ];

  meta = with lib; {
    description = "A GUI for yt-dlp written in Rust";
    homepage = "https://github.com/bksalman/ytdlp-gui/";
    license = licenses.gpl3;
    maintainers = with maintainers; [ bksalman ];
  };
}

but I’m still figuring it out.

with this current package file, I get this error message:
$ RUST_LOG=debug ./result/bin/ytdlp-gui

[2023-03-25T19:17:55Z INFO  wgpu_hal::vulkan::instance] Missing Vulkan entry points: LibraryLoadFailure(DlOpen { desc: "libvulkan.so.1: cannot open shared object file: No such file or directory" })
[2023-03-25T19:17:55Z INFO  wgpu_hal::gles::egl] Unable to open libEGL: Library(DlOpen { desc: "libEGL.so: cannot open shared object file: No such file or directory" })
[2023-03-25T19:17:55Z INFO  iced_wgpu::window::compositor] Settings {
        present_mode: AutoVsync,
        internal_backend: VULKAN | GL | METAL | DX12 | DX11 | BROWSER_WEBGPU | PRIMARY | SECONDARY,
        default_font: None,
        default_text_size: 20,
        text_multithreading: false,
        antialiasing: None,
    }
[2023-03-25T19:17:55Z INFO  iced_wgpu::window::compositor] Available adapters: []
[2023-03-25T19:17:55Z INFO  wgpu_core::hub] Dropping Global
Error: GraphicsCreationFailed(GraphicsAdapterNotFound)

OpenGL and Vulkan programs need an extra step so they can find the drivers:

  nativeBuildInputs = with pkgs; [
    pkg-config
    cmake
    addOpenGLRunpath
  ];

  postFixup = ''
    addOpenGLRunpath $out/bin/ytdlp-gui
  '';

If you’re not using NixOS, you’ll also need NixGL

1 Like

Unfortunately, that didn’t fix the issue :frowning:, I still get the same error.

even tho my shell.nix works fine with my application

I used wrapProgram (from makeWrapper package) and it worked :slight_smile: !

here is the final package file:

{ lib
, fetchFromGitHub
, rustPlatform
, pkgs
}:

rustPlatform.buildRustPackage rec {
  pname = "ytdlp-gui";
  version = "0.2.5";

  src = fetchFromGitHub {
    owner = "BKSalman";
    repo = "ytdlp-gui";
    rev = "v${version}";
    sha256 = "sha256-BB2zM0EIPYkv5tMX6TCXVkLoz7HQCXVMOiEEwPJRAB0=";
  };

  cargoSha256 = "sha256-1jvCcHDfMbVxsNI1iBngx8uEUkENeM7sbzSL0DgpK+o=";

  nativeBuildInputs = with pkgs; [
    pkg-config
    cmake
    makeWrapper
  ];

  buildInputs = with pkgs; [
    fontconfig

    vulkan-headers
    vulkan-loader
    libGL

    libxkbcommon
    # WINIT_UNIX_BACKEND=wayland
    wayland

    # WINIT_UNIX_BACKEND=x11
    xorg.libXcursor
    xorg.libXrandr
    xorg.libXi
    xorg.libX11
  ];

  postFixup = ''
    wrapProgram $out/bin/ytdlp-gui \
      --suffix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath buildInputs}
  '';

  meta = with lib; {
    description = "A GUI for yt-dlp written in Rust";
    homepage = "https://github.com/bksalman/ytdlp-gui/";
    license = licenses.gpl3;
    maintainers = with maintainers; [ bksalman ];
  };
}

not sure if there are unnecessary stuff in the file, but it works at least :slight_smile:

(I figured it needs to be wrapped with the libraries paths and stuff based on @raphi 's reply, so, thanks :)! )