Unverified Commit 9ec6ea71 authored by Jörg Thalheim's avatar Jörg Thalheim Committed by GitHub
Browse files

Merge pull request #307467 from TomaSajt/redisinsight

redisinsight: fix build, refactor
parents ba0f4049 b68be644
Loading
Loading
Loading
Loading
+84 −67
Original line number Diff line number Diff line
{ lib
, stdenv
, fetchFromGitHub
, makeWrapper
, makeDesktopItem
, fixup_yarn_lock
, yarn
, nodejs_18
, python3
, fetchYarnDeps
, electron
, desktopToDarwinBundle
, nest-cli
, libsass
, buildPackages
, pkg-config
, sqlite
, xdg-utils
{
  lib,
  stdenv,
  fetchFromGitHub,
  makeWrapper,
  makeDesktopItem,
  copyDesktopItems,
  fixup-yarn-lock,
  yarn,
  nodejs_18,
  python3,
  fetchYarnDeps,
  electron,
  nest-cli,
  libsass,
  buildPackages,
  pkg-config,
  sqlite,
  xdg-utils,
}:

let
  nodejs = nodejs_18;
in
stdenv.mkDerivation (finalAttrs: {
  pname = "redisinsight-electron";
  pname = "redisinsight";
  version = "2.32";

  src = fetchFromGitHub {
    owner = "RedisInsight";
    repo = "RedisInsight";
    rev = "${finalAttrs.version}";
    rev = finalAttrs.version;
    hash = "sha256-esaH10AyEooym/62F5LJL7oP5UmD6T2UX8g/9QniL9s=";
  };

  offlineCache = fetchYarnDeps {
    yarnLock = finalAttrs.src + "/yarn.lock";
    sha256 = "NHKttywAaWAYkciGzYCnm1speHrWsv1t+dxL1DZgM7o=";
    hash = "sha256-NHKttywAaWAYkciGzYCnm1speHrWsv1t+dxL1DZgM7o=";
  };

  feOfflineCache = fetchYarnDeps {
    yarnLock = finalAttrs.src + "/redisinsight/yarn.lock";
    sha256 = "1S1KNUOtmywQ0eyqVS2oRlhpjcL9eps8CR7AtC9ujSU=";
    hash = "sha256-1S1KNUOtmywQ0eyqVS2oRlhpjcL9eps8CR7AtC9ujSU=";
  };

  apiOfflineCache = fetchYarnDeps {
    yarnLock = finalAttrs.src + "/redisinsight/api/yarn.lock";
    sha256 = "P99+1Dhdg/vznC2KepPrVGNlrofJFydXkZVxgwprIx4=";
    hash = "sha256-P99+1Dhdg/vznC2KepPrVGNlrofJFydXkZVxgwprIx4=";
  };

  nativeBuildInputs = [ yarn fixup_yarn_lock nodejs makeWrapper python3 nest-cli libsass pkg-config ]
    ++ lib.optionals stdenv.isDarwin [ desktopToDarwinBundle ];

  buildInputs = [ sqlite xdg-utils ];
  nativeBuildInputs = [
    yarn
    fixup-yarn-lock
    nodejs
    makeWrapper
    python3
    nest-cli
    libsass
    pkg-config
    copyDesktopItems
  ];

  buildInputs = [
    sqlite
    xdg-utils
  ];

  configurePhase = ''
    runHook preConfigure

    export HOME=$(mktemp -d)
    yarn config --offline set yarn-offline-mirror $offlineCache
    fixup_yarn_lock yarn.lock
    yarn config --offline set yarn-offline-mirror ${finalAttrs.offlineCache}
    fixup-yarn-lock yarn.lock
    yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive

    yarn config --offline set yarn-offline-mirror $feOfflineCache
    fixup_yarn_lock redisinsight/yarn.lock
    yarn config --offline set yarn-offline-mirror ${finalAttrs.feOfflineCache}
    fixup-yarn-lock redisinsight/yarn.lock
    yarn --offline --cwd redisinsight/ --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive

    yarn config --offline set yarn-offline-mirror $apiOfflineCache
    fixup_yarn_lock redisinsight/api/yarn.lock
    yarn config --offline set yarn-offline-mirror ${finalAttrs.apiOfflineCache}
    fixup-yarn-lock redisinsight/api/yarn.lock
    yarn --offline --cwd redisinsight/api/ --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive

    patchShebangs node_modules/
@@ -76,29 +90,32 @@ stdenv.mkDerivation (finalAttrs: {
    ln -sfv "${nodejs}/include" "$HOME/.node-gyp/${nodejs.version}"
    export npm_config_nodedir=${nodejs}

    pushd redisinsight
    # Build the sqlite3 package.
    pushd redisinsight
    npm_config_node_gyp="${buildPackages.nodejs}/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" npm rebuild --verbose --sqlite=${sqlite.dev} sqlite3
    popd

    # Build node-sass
    LIBSASS_EXT=auto npm rebuild --verbose node-sass

    substituteInPlace redisinsight/api/config/default.ts \
      --replace "process['resourcesPath']" "\"$out/share/redisinsight\"" \
      --replace-fail "process['resourcesPath']" "\"$out/share/redisinsight\"" \

    # has irrelevant files
    rm -r resources/app

    runHook postConfigure
  '';

  buildPhase = ''
    runHook preBuild
    yarn config --offline set yarn-offline-mirror $offlineCache

    pushd node_modules/node-sass
    LIBSASS_EXT=auto yarn run build --offline
    popd
    yarn config --offline set yarn-offline-mirror ${finalAttrs.offlineCache}

    yarn --offline build:prod

    yarn --offline electron-builder \
      --dir ${if stdenv.isDarwin then "--macos" else "--linux"} ${if stdenv.hostPlatform.isAarch64 then "--arm64" else "--x64"} \
      --dir \
      -c.electronDist=${electron}/libexec/electron \
      -c.electronVersion=${electron.version}

@@ -108,32 +125,28 @@ stdenv.mkDerivation (finalAttrs: {
  installPhase = ''
    runHook preInstall

    # resources
    mkdir -p "$out/share/redisinsight"
    mkdir -p "$out/share/redisinsight/static/resources/plugins"
    mkdir -p "$out/share/redisinsight/default"
    mkdir -p "$out/share/redisinsight"/{app,defaults,static/plugins,static/resources/plugins}

    cp -r release/${if stdenv.isDarwin then "darwin-" else "linux-"}${lib.optionalString stdenv.hostPlatform.isAarch64 "arm64-"}unpacked/resources/{app.asar,app.asar.unpacked} $out/share/redisinsight/
    cp -r resources/ $out/share/redisinsight
    cp -r release/*-unpacked/{locales,resources{,.pak}} "$out/share/redisinsight/app"
    mv "$out/share/redisinsight/app/resources/resources" "$out/share/redisinsight"

    # icons
    for icon in "$out/resources/icons/*.png"; do
    for icon in "$out/share/redisinsight/resources/icons"/*.png; do
      mkdir -p "$out/share/icons/hicolor/$(basename $icon .png)/apps"
      ln -s "$icon" "$out/share/icons/hicolor/$(basename $icon .png)/apps/redisinsight.png"
    done

    ln -s "${finalAttrs.desktopItem}/share/applications" "$out/share/applications"

    makeWrapper '${electron}/bin/electron' "$out/bin/redisinsight" \
      --add-flags "$out/share/redisinsight/app.asar" \
      --add-flags "$out/share/redisinsight/app/resources/app.asar" \
      --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
      --chdir "$out/share/redisinsight" \
      --argv0 "$out/share/redisinsight/app.asar"
      --set-default ELECTRON_FORCE_IS_PACKAGED 1 \
      --inherit-argv0

    runHook postInstall
  '';

  desktopItem = makeDesktopItem {
  desktopItems = [
    (makeDesktopItem {
      name = "redisinsight";
      exec = "redisinsight %u";
      icon = "redisinsight";
@@ -142,13 +155,17 @@ stdenv.mkDerivation (finalAttrs: {
      comment = finalAttrs.meta.description;
      categories = [ "Development" ];
      startupWMClass = "redisinsight";
  };
    })
  ];

  meta = with lib; {
  meta = {
    description = "RedisInsight Redis client powered by Electron";
    homepage = "https://github.com/RedisInsight/RedisInsight";
    license = licenses.sspl;
    maintainers = with maintainers; [ gmemstr ];
    platforms = [ "x86_64-linux" ];
    #license = licenses.sspl;
    maintainers = with lib.maintainers; [
      gmemstr
      tomasajt
    ];
    platforms = lib.platforms.linux;
  };
})