Unverified Commit 4fc604ae authored by Peder Bergebakken Sundt's avatar Peder Bergebakken Sundt Committed by GitHub
Browse files

vrcx: Build from source (#402174)

parents 23b42333 7c53b3b6
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -10477,6 +10477,13 @@
    githubId = 36996706;
    name = "Philip Rying";
  };
  ImSapphire = {
    email = "imsapphire0@gmail.com";
    github = "ImSapphire";
    githubId = 48931512;
    name = "Sapphire";
    keys = [ { fingerprint = "D303 4473 1843 D27B 5D4E  2273 6429 11AA 4025 C8CC"; } ];
  };
  imsick = {
    email = "lent-lather-excuse@duck.com";
    github = "dvishal485";
+912 −0

File added.

Preview size limit exceeded, changes collapsed.

+103 −23
Original line number Diff line number Diff line
{
  lib,
  fetchurl,
  appimageTools,
  dotnet-runtime_9,
  fetchFromGitHub,
  buildDotnetModule,
  dotnetCorePackages,
  buildNpmPackage,
  electron_34,
  makeWrapper,
  copyDesktopItems,
  makeDesktopItem,
  stdenv,
}:
let
  pname = "vrcx";
  version = "2025.03.01";
  filename = builtins.replaceStrings [ "." ] [ "" ] version;
  src = fetchurl {
    hash = "sha256-d+sqebPDZC0GWtd+5/R1KXIKUbpZ0k9YFupsf29IHCs=";
    url = "https://github.com/vrcx-team/VRCX/releases/download/v${version}/VRCX_${filename}.AppImage";
  dotnet = dotnetCorePackages.dotnet_9;
  electron = electron_34;

  src = fetchFromGitHub {
    owner = "vrcx-team";
    repo = "VRCX";
    # v2025.03.01 tag is actually behind a few commits, namely the one that bumps the version (so it complains about not being up-to-date)
    #tag = "v${version}";
    rev = "1980eeb4cccebfcf33826d44b7833a9aa6f5a955";
    hash = "sha256-HiFcHnytynWYbeUd+KsG38dLU1FhDu0VD3JPT3kUO6s=";
  };
  appimageContents = appimageTools.extract {
    inherit pname src version;

  backend = buildDotnetModule {
    inherit version src;
    pname = "${pname}-backend";

    dotnet-sdk = dotnet.sdk;
    dotnet-runtime = dotnet.runtime;
    projectFile = "Dotnet/VRCX-Electron.csproj";

    nugetDeps = ./deps.json;

    installPhase = ''
      runHook preInstall

      cp -r build/Electron $out

      runHook postInstall
    '';
  };
in
appimageTools.wrapType2 rec {
buildNpmPackage {
  inherit pname version src;
  extraPkgs = pkgs: [ dotnet-runtime_9 ];
  extraInstallCommands = ''
    install -m 444 -D ${appimageContents}/vrcx.desktop \
      $out/share/applications/VRCX.desktop
    install -m 444 -D ${appimageContents}/usr/share/icons/hicolor/256x256/apps/vrcx.png \
      $out/share/icons/hicolor/256x256/apps/VRCX.png

    substituteInPlace $out/share/applications/VRCX.desktop \
      --replace-fail 'Exec=AppRun' 'Exec=${pname} --no-install --ozone-platform-hint=auto'
    substituteInPlace $out/share/applications/VRCX.desktop \
      --replace-fail 'Icon=VRCX' "Icon=$out/share/icons/hicolor/256x256/apps/VRCX.png"

  npmDepsHash = "sha256-2ZU+9NPPx3GbU75XfjVroZCpjXr7IK2HtEIqLJLOjyw=";
  npmFlags = [ "--ignore-scripts" ];
  makeCacheWritable = true;

  nativeBuildInputs = [
    makeWrapper
    copyDesktopItems
  ];

  buildPhase = ''
    runHook preBuild

    env PLATFORM=linux npm exec webpack -- --config webpack.config.js --mode production
    node src-electron/patch-package-version.js
    npm exec electron-builder -- --dir \
      -c.electronDist=${electron.dist} \
      -c.electronVersion=${electron.version}
    node src-electron/patch-node-api-dotnet.js

    runHook postBuild
  '';
  installPhase = ''
    runHook preInstall

    mkdir -p "$out/share/vrcx"
    cp -r build/*-unpacked/resources "$out/share/vrcx/"
    mkdir -p $out/share/vrcx/resources/app.asar.unpacked/build
    cp -r ${backend} "$out/share/vrcx/resources/app.asar.unpacked/build/Electron"

    makeWrapper '${electron}/bin/electron' "$out/bin/vrcx"  \
      --add-flags "--ozone-platform-hint=auto"              \
      --add-flags "$out/share/vrcx/resources/app.asar"      \
      --set NODE_ENV production                             \
      --set DOTNET_ROOT ${dotnet.runtime}/share/dotnet      \
      --prefix PATH : ${lib.makeBinPath [ dotnet.runtime ]}

    install -Dm644 VRCX.png "$out/share/icons/hicolor/256x256/apps/vrcx.png"

    runHook postInstall
  '';

  desktopItems = [
    (makeDesktopItem {
      name = "vrcx";
      desktopName = "VRCX";
      comment = "Friendship management tool for VRChat";
      icon = "vrcx";
      exec = "vrcx";
      terminal = false;
      categories = [
        "Utility"
        "Application"
      ];
      mimeTypes = [ "x-scheme-handler/vrcx" ];
    })
  ];

  passthru = {
    inherit backend;
  };

  meta = {
    description = "Friendship management tool for VRChat";
    longDescription = ''
@@ -40,8 +117,11 @@ appimageTools.wrapType2 rec {
    license = lib.licenses.mit;
    homepage = "https://github.com/vrcx-team/VRCX";
    downloadPage = "https://github.com/vrcx-team/VRCX/releases";
    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
    maintainers = with lib.maintainers; [ ShyAssassin ];
    maintainers = with lib.maintainers; [
      ShyAssassin
      ImSapphire
    ];
    platforms = lib.platforms.linux;
    broken = !stdenv.hostPlatform.isx86_64;
  };
}