GoXLR-on-Linux / goxlr-utility

An unofficial GoXLR App replacement for Linux, Windows and MacOS
MIT License
636 stars 36 forks source link

[Feature] Nix support #78

Closed Sporesirius closed 10 months ago

Sporesirius commented 1 year ago

Support for the Nix package manager.

FrostyCoolSlug commented 1 year ago

I'll accept contributions towards this end, but am unlikely to handle it myself. Currently I'm not finding any simple tooling to create a nix package that can be simply dropped into the existing CI.

Thanks.

Sporesirius commented 11 months ago

Is it possible to have a cargo.lock in the root of the monorepo or is there intentionally none? I am trying to build a nix package according to these docs: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md EDIT: this is what I currently got

{ lib
, fetchFromGitHub
, rustPlatform
, pkg-config
, libpulseaudio
, dbus
, clang
, speechd
}:

rustPlatform.buildRustPackage rec {
  pname = "goxlr-utility";
  version = "v0.12.5";

  src = fetchFromGitHub {
    owner = "GoXLR-on-Linux";
    repo = pname;
    rev = version;
    sha256 = "iKTP3TgN4CF+DLXJYio50RuP9pCVd6zeHczBpGdj6Wg=";
  };

  cargoSha256 = lib.fakeSha256;

  buildFeatures = [ "tts" ];

  meta = with lib; {
    description = "An unofficial GoXLR App replacement for Linux, Windows and MacOS";
    homepage = "https://github.com/GoXLR-on-Linux/goxlr-utility";
    license = licenses.mit;
    maintainers = [];
  };
}
FrostyCoolSlug commented 10 months ago

I've reintroduced Cargo.lock to the repository in 0.12.6

errnoh commented 10 months ago

Lucky timing it seems. Found this thread today and spent a bit of time on this. Ended up with working setup that looks like this:

{ lib
, fetchFromGitHub
, rustPlatform
, llvmPackages_11
, pkg-config
, libpulseaudio
, dbus
, clang
, speechd
}:

rustPlatform.buildRustPackage rec {
  pname = "goxlr-utility";
  version = "v0.12.6";

  src = fetchFromGitHub {
    owner = "GoXLR-on-Linux";
    repo = pname;
    rev = version;
    sha256 = "vvaKCsqncRhag8IrS0AIfNqNHGU2WIvFaYISEVfUB2Y=";
  };

  LIBCLANG_PATH = "${llvmPackages_11.libclang.lib}/lib";

  buildInputs = [
    libpulseaudio
    dbus
    speechd
  ];

  nativeBuildInputs = [
    pkg-config
    clang
  ];

  postInstall = ''
    mkdir -p $out/lib/udev/rules.d/
    cp 50-goxlr.rules $out/lib/udev/rules.d/
  '';

  cargoSha256 = "sha256-6Xw+A5l/bg8kHo5X3tc61Y8PagOSPpeF5Kealg7Y0hM=";

  buildFeatures = [ "tts" ];

  meta = with lib; {
    description = "An unofficial GoXLR App replacement for Linux, Windows and MacOS";
    homepage = "https://github.com/GoXLR-on-Linux/goxlr-utility";
    license = licenses.mit;
    maintainers = [ ];
  };
}

and then adding services.udev.packages = [ pkgs.goxlr-utility ]; to the configuration for the udev rules. (for some reason I had to reboot to get the udev rules to load properly btw).

(also adding ping to https://github.com/NixOS/nixpkgs/issues/243701 to link the nixpkgs request and this thread)

FrostyCoolSlug commented 10 months ago

You need to run sudo udevadm control --reload-rules && sudo udevadm trigger after installing the udev rules for them to be loaded without a reboot.

Sporesirius commented 10 months ago

@FrostyCoolSlug Thank you for reintroducing Cargo.lock @errnoh Cool that you got it working. Thanks for pinging the package request. I can try to make a pull request this weekend. Maybe you know, I would like to auto update the package. I know nixpkgs-update exists, but have never tried it.

errnoh commented 10 months ago

Glad to be of help. And no issues with the software so far, everything seems to work as expected. Are planning on adding an NixOS module for it as well afterwards, or is your use case covered by just having the package? There's some additional requirements like the udev rules and likely a systemd unit for the daemon. Simple enable option would likely be enough to begin with, but maybe there's some potential for writing configuration files etc at some point to be more idiomatic.

For the nigpkgs-update I'm not sure. Looks like a nice tool but I can't seem to find the most important piece, which is if it's already automatically run against all packages in nixpkgs whenever there's a GH release or not. I'm seeing the bot making pull requests there, and I know there's automated messages that are being sent from Hydra to anyone that is a package maintainer. Maybe it already just asks you for PR review whenever GH release is made and notifies if the CI process failed so that you can manually fix the build if that happens :shrug:

FrostyCoolSlug commented 10 months ago

Just to note, the util uses XDG for autostart (the option is in System -> Settings), using systemd can be problematic for autostart simply because things like pulse audio / pipewire and a few required environmental variables aren't ready when the util hits it's start point, in addition, systemd may not correctly exit the util when the user logs off (and instead will trigger them on shutdown) which can cause issues with the exit behaviours.

DEs have their own xdg target, which is called when the environment is fully set up and ready, it'll also let shutdown occur when the user logs out.

errnoh commented 10 months ago

Interesting, thanks for the information! Hadn't read about the XDG autostart before. Doesn't seem to be an issue as there's a NixOS option to enable XDG autostart apparently and seeing multiple modules copying configs to /etc/xdg/autostart, so likely good idea to keep using XDG as it's the native way for this repo.

errnoh commented 10 months ago

Seems to work fine! Had to modify the .desktop file a bit to be more NixOS friendly as well as change it to use -daemon instead of -launcher, but the actual NixOS module logic seems to be:

  services.udev.packages = [ pkgs.goxlr-utility ];
  xdg.autostart.enable = true;

  environment.systemPackages = with pkgs; [
    (makeAutostartItem
      {
        name = "goxlr-utility";
        package = goxlr-utility;
      })
  ];

and with that we should be able to get this properly packaged in NixOS.

errnoh commented 10 months ago

Nixpkgs master now has support for goxlr-utility, we should be able to close this issue :+1:

Sporesirius commented 10 months ago

goxlr-utility is on upstream nixpkgs.