all repos — flake @ f54b116972bb4c730b9ba98e570f3d64d90a8a0a

got my cool flake

pkgs/zed.nix (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
{
  stdenv,
  fetchurl,
  lib,
  makeWrapper,
  patchelf,
  alsa-lib,
  wayland,
  libxkbcommon,
  vulkan-loader,
  mesa,
  xkeyboard-config,
  libXau,
  libxcb,
  libX11,
  libXdmcp,
  ...
}:

stdenv.mkDerivation rec {
  pname = "zeditor";
  version = "0.234.5-pre";

  src = fetchurl {
    url = "https://github.com/zed-industries/zed/releases/download/v${version}/zed-linux-x86_64.tar.gz";
    sha256 = "sha256-6zeKuSQax2jHMgoYqwAsGRMTUIVBo/5Acf6Qr4TrYno=";
  };

  nativeBuildInputs = [
    makeWrapper
    patchelf
  ];

  sourceRoot = ".";

  dontBuild = true;
  dontConfigure = true;

  installPhase = ''
    runHook preInstall
    mkdir -p $out/bin $out/libexec $out/lib $out/share

    APP_NAME=zed-preview
    TARGET_DIR=$APP_NAME.app

    cp -r $TARGET_DIR/bin/* $out/bin/
    cp -r $TARGET_DIR/libexec/* $out/libexec/
    cp -r $TARGET_DIR/lib/* $out/lib/
    cp -r $TARGET_DIR/share/* $out/share/
    cp $TARGET_DIR/licenses.md $out/share/

    chmod +x $out/bin/zed
    chmod +x $out/libexec/zed-editor


    wrapProgram $out/bin/zed \
        --prefix LD_LIBRARY_PATH : ${alsa-lib}/lib:${wayland}/lib:${libxkbcommon}/lib:${vulkan-loader}/lib:${mesa}/lib:${libXau}/lib:${libxcb}/lib:${libX11}/lib:${libXdmcp}/lib \
        --set XKB_CONFIG_ROOT ${xkeyboard-config}/share/X11/xkb

    wrapProgram $out/libexec/zed-editor \
        --prefix LD_LIBRARY_PATH : ${alsa-lib}/lib:${wayland}/lib:${libxkbcommon}/lib:${vulkan-loader}/lib:${mesa}/lib \
        --set XKB_CONFIG_ROOT ${xkeyboard-config}/share/X11/xkb

    for lib in $out/lib/*.so*; do
        if patchelf --print-rpath "$lib" &>/dev/null; then
        patchelf --set-rpath '$ORIGIN' "$lib" || true
        fi
    done
    patchelf --set-rpath '$ORIGIN/../lib' $out/libexec/.zed-editor-wrapped

    patchelf --set-rpath '$ORIGIN/../lib' $out/libexec/.zed-editor-wrapped


    runHook postInstall
  '';

  postInstall = ''
    substituteInPlace $out/share/applications/dev.zed.Zed-Preview.desktop \
      --replace "TryExec=zed" "TryExec=$out/bin/zed" \
      --replace "Exec=zed %U" "Exec=$out/bin/zed %U" \
      --replace "Exec=zed --new %U" "Exec=$out/bin/zed --new %U"
  '';

  meta = with lib; {
    description = "A high-performance, multiplayer code editor";
    homepage = "https://zed.dev";
    platforms = [ "x86_64-linux" ];
    license = licenses.mit;
    maintainers = with maintainers; [ apr ];
  };
}