biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / applications / editors / sublime / 4 / common.nix
blobb594633ea3cb136aa6a287e1957d57e547acd3d3
2   buildVersion,
3   dev ? false,
4   aarch64sha256,
5   x64sha256,
6 }:
9   fetchurl,
10   stdenv,
11   lib,
12   xorg,
13   glib,
14   libglvnd,
15   glibcLocales,
16   gtk3,
17   cairo,
18   pango,
19   makeWrapper,
20   wrapGAppsHook3,
21   writeShellScript,
22   common-updater-scripts,
23   curl,
24   openssl_1_1,
25   bzip2,
26   sqlite,
29 let
30   pnameBase = "sublimetext4";
31   packageAttribute = "sublime4${lib.optionalString dev "-dev"}";
32   binaries = [
33     "sublime_text"
34     "plugin_host-3.3"
35     "plugin_host-3.8"
36     crashHandlerBinary
37   ];
38   primaryBinary = "sublime_text";
39   primaryBinaryAliases = [
40     "subl"
41     "sublime"
42     "sublime4"
43   ];
44   crashHandlerBinary =
45     if lib.versionAtLeast buildVersion "4153" then "crash_handler" else "crash_reporter";
46   downloadUrl =
47     arch: "https://download.sublimetext.com/sublime_text_build_${buildVersion}_${arch}.tar.xz";
48   versionUrl = "https://download.sublimetext.com/latest/${if dev then "dev" else "stable"}";
49   versionFile = builtins.toString ./packages.nix;
51   neededLibraries = [
52     xorg.libX11
53     xorg.libXtst
54     glib
55     libglvnd
56     openssl_1_1
57     gtk3
58     cairo
59     pango
60     curl
61   ] ++ lib.optionals (lib.versionAtLeast buildVersion "4145") [
62     sqlite
63   ];
65   binaryPackage = stdenv.mkDerivation rec {
66     pname = "${pnameBase}-bin";
67     version = buildVersion;
69     src = passthru.sources.${stdenv.hostPlatform.system};
71     dontStrip = true;
72     dontPatchELF = true;
74     buildInputs = [
75       glib
76       # for GSETTINGS_SCHEMAS_PATH
77       gtk3
78     ];
80     nativeBuildInputs = [
81       makeWrapper
82       wrapGAppsHook3
83     ];
85     buildPhase = ''
86       runHook preBuild
88       for binary in ${builtins.concatStringsSep " " binaries}; do
89         patchelf \
90           --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
91           --set-rpath ${lib.makeLibraryPath neededLibraries}:${stdenv.cc.cc.lib}/lib${lib.optionalString stdenv.hostPlatform.is64bit "64"} \
92           $binary
93       done
95       # Rewrite pkexec argument. Note that we cannot delete bytes in binary.
96       sed -i -e 's,/bin/cp\x00,cp\x00\x00\x00\x00\x00\x00,g' ${primaryBinary}
98       runHook postBuild
99     '';
101     installPhase = ''
102       runHook preInstall
104       # No need to patch these libraries, it works well with our own
105       rm libcrypto.so.1.1 libssl.so.1.1
106       ${lib.optionalString (lib.versionAtLeast buildVersion "4145") "rm libsqlite3.so"}
108       mkdir -p $out
109       cp -r * $out/
111       runHook postInstall
112     '';
114     dontWrapGApps = true; # non-standard location, need to wrap the executables manually
116     postFixup = ''
117       sed -i 's#/usr/bin/pkexec#pkexec\x00\x00\x00\x00\x00\x00\x00\x00\x00#g' "$out/${primaryBinary}"
119       wrapProgram $out/${primaryBinary} \
120         --set LOCALE_ARCHIVE "${glibcLocales.out}/lib/locale/locale-archive" \
121         "''${gappsWrapperArgs[@]}"
122     '';
124     passthru = {
125       sources = {
126         "aarch64-linux" = fetchurl {
127           url = downloadUrl "arm64";
128           sha256 = aarch64sha256;
129         };
130         "x86_64-linux" = fetchurl {
131           url = downloadUrl "x64";
132           sha256 = x64sha256;
133         };
134       };
135     };
136   };
138 stdenv.mkDerivation (rec {
139   pname = pnameBase;
140   version = buildVersion;
142   dontUnpack = true;
144   ${primaryBinary} = binaryPackage;
146   nativeBuildInputs = [
147     makeWrapper
148   ];
150   installPhase =
151     ''
152       mkdir -p "$out/bin"
153       makeWrapper "''$${primaryBinary}/${primaryBinary}" "$out/bin/${primaryBinary}"
154     ''
155     + builtins.concatStringsSep "" (
156       map (binaryAlias: "ln -s $out/bin/${primaryBinary} $out/bin/${binaryAlias}\n") primaryBinaryAliases
157     )
158     + ''
159       mkdir -p "$out/share/applications"
161       substitute \
162         "''$${primaryBinary}/${primaryBinary}.desktop" \
163         "$out/share/applications/${primaryBinary}.desktop" \
164         --replace-fail "/opt/${primaryBinary}/${primaryBinary}" "${primaryBinary}"
166       for directory in ''$${primaryBinary}/Icon/*; do
167         size=$(basename $directory)
168         mkdir -p "$out/share/icons/hicolor/$size/apps"
169         ln -s ''$${primaryBinary}/Icon/$size/* $out/share/icons/hicolor/$size/apps
170       done
171     '';
173   passthru = {
174     updateScript =
175       let
176         script = writeShellScript "${packageAttribute}-update-script" ''
177           set -o errexit
178           PATH=${
179             lib.makeBinPath [
180               common-updater-scripts
181               curl
182             ]
183           }
185           versionFile=$1
186           latestVersion=$(curl -s "${versionUrl}")
188           if [[ "${buildVersion}" = "$latestVersion" ]]; then
189               echo "The new version same as the old version."
190               exit 0
191           fi
193           for platform in ${lib.escapeShellArgs meta.platforms}; do
194               update-source-version "${packageAttribute}.${primaryBinary}" "$latestVersion" --ignore-same-version --file="$versionFile" --version-key=buildVersion --source-key="sources.$platform"
195           done
196         '';
197       in
198       [
199         script
200         versionFile
201       ];
202   };
204   meta = with lib; {
205     description = "Sophisticated text editor for code, markup and prose";
206     homepage = "https://www.sublimetext.com/";
207     maintainers = with maintainers; [
208       jtojnar
209       wmertens
210       demin-dmitriy
211       zimbatm
212     ];
213     sourceProvenance = with sourceTypes; [ binaryNativeCode ];
214     license = licenses.unfree;
215     platforms = [
216       "aarch64-linux"
217       "x86_64-linux"
218     ];
219   };