Commit de4a7667 authored by Dominique Martinet's avatar Dominique Martinet
Browse files

rmfakecloud: build the webui together with the app

This avoids maintaining an artificial derivation for the web UI,
and hopefully will allow the auto-update bot to make PRs for further
updates
parent 1182bd00
Loading
Loading
Loading
Loading
+29 −12
Original line number Diff line number Diff line
@@ -2,8 +2,9 @@
  lib,
  fetchFromGitHub,
  buildGoModule,
  callPackage,
  enableWebui ? true,
  pnpm_9,
  nodejs,
  nixosTests,
}:

@@ -20,15 +21,31 @@ buildGoModule rec {

  vendorHash = "sha256-9tfxE03brUvCYusmewiqNpCkKyIS9qePqylrzDWrJLY=";

  ui = callPackage ./webui.nix { inherit version src; };
  # if using webUI build it
  # use env because of https://github.com/NixOS/nixpkgs/issues/358844
  env.pnpmRoot = "ui";
  env.pnpmDeps = pnpm_9.fetchDeps {
    inherit pname version src;
    sourceRoot = "${src.name}/ui";
    pnpmLock = "${src}/ui/pnpm-lock.yaml";
    hash = "sha256-VNmCT4um2W2ii8jAm+KjQSjixYEKoZkw7CeRwErff/o=";
  };
  preBuild = lib.optionals enableWebui ''
    # using sass-embedded fails at executing node_modules/sass-embedded-linux-x64/dart-sass/src/dart
    rm -r ui/node_modules/sass-embedded ui/node_modules/.pnpm/sass-embedded*

    # avoid re-running pnpm i...
    touch ui/pnpm-lock.yaml

    make ui/dist
  '';
  nativeBuildInputs = lib.optionals enableWebui [
    nodejs
    pnpm_9.configHook
  ];

  postPatch =
    if enableWebui then
      ''
        cp -a ${ui} ui/dist
      ''
    else
      ''
  # ... or don't embed it in the server
  postPatch = lib.optionals (!enableWebui) ''
    sed -i '/go:/d' ui/assets.go
  '';

+0 −46
Original line number Diff line number Diff line
{
  version,
  src,
  stdenv,
  lib,
  pnpm_9,
  nodejs,
}:

stdenv.mkDerivation (finalAttrs: {
  inherit version src;

  pname = "rmfakecloud-webui";

  pnpmDeps = pnpm_9.fetchDeps {
    inherit (finalAttrs) pname version src;
    sourceRoot = "${finalAttrs.src.name}/ui";
    pnpmLock = "${src}/ui/pnpm-lock.yaml";
    hash = "sha256-VNmCT4um2W2ii8jAm+KjQSjixYEKoZkw7CeRwErff/o=";
  };
  pnpmRoot = "ui";

  buildPhase = ''
    cd ui

    # using sass-embedded fails at executing node_modules/sass-embedded-linux-x64/dart-sass/src/dart
    rm -r node_modules/sass-embedded node_modules/.pnpm/sass-embedded*

    pnpm build
  '';

  installPhase = ''
    cp -a dist/. $out
  '';

  nativeBuildInputs = [
    nodejs
    pnpm_9.configHook
  ];

  meta = with lib; {
    description = "Only the webui files for rmfakecloud";
    homepage = "https://ddvk.github.io/rmfakecloud/";
    license = licenses.agpl3Only;
  };
})