python312Packages.fnllm: 0.0.11 -> 0.0.12 (#364582)
[NixPkgs.git] / pkgs / applications / editors / sublime / 4 / common.nix
blob5eb44da324944db7a2387051038bf44b3034f277
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     [
53       xorg.libX11
54       xorg.libXtst
55       glib
56       libglvnd
57       openssl_1_1
58       gtk3
59       cairo
60       pango
61       curl
62     ]
63     ++ lib.optionals (lib.versionAtLeast buildVersion "4145") [
64       sqlite
65     ];
67   binaryPackage = stdenv.mkDerivation rec {
68     pname = "${pnameBase}-bin";
69     version = buildVersion;
71     src = passthru.sources.${stdenv.hostPlatform.system};
73     dontStrip = true;
74     dontPatchELF = true;
76     buildInputs = [
77       glib
78       # for GSETTINGS_SCHEMAS_PATH
79       gtk3
80     ];
82     nativeBuildInputs = [
83       makeWrapper
84       wrapGAppsHook3
85     ];
87     buildPhase = ''
88       runHook preBuild
90       for binary in ${builtins.concatStringsSep " " binaries}; do
91         patchelf \
92           --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
93           --set-rpath ${lib.makeLibraryPath neededLibraries}:${lib.getLib stdenv.cc.cc}/lib${lib.optionalString stdenv.hostPlatform.is64bit "64"} \
94           $binary
95       done
97       # Rewrite pkexec argument. Note that we cannot delete bytes in binary.
98       sed -i -e 's,/bin/cp\x00,cp\x00\x00\x00\x00\x00\x00,g' ${primaryBinary}
100       runHook postBuild
101     '';
103     installPhase = ''
104       runHook preInstall
106       # No need to patch these libraries, it works well with our own
107       rm libcrypto.so.1.1 libssl.so.1.1
108       ${lib.optionalString (lib.versionAtLeast buildVersion "4145") "rm libsqlite3.so"}
110       mkdir -p $out
111       cp -r * $out/
113       runHook postInstall
114     '';
116     dontWrapGApps = true; # non-standard location, need to wrap the executables manually
118     postFixup = ''
119       sed -i 's#/usr/bin/pkexec#pkexec\x00\x00\x00\x00\x00\x00\x00\x00\x00#g' "$out/${primaryBinary}"
121       wrapProgram $out/${primaryBinary} \
122         --set LOCALE_ARCHIVE "${glibcLocales.out}/lib/locale/locale-archive" \
123         "''${gappsWrapperArgs[@]}"
124     '';
126     passthru = {
127       sources = {
128         "aarch64-linux" = fetchurl {
129           url = downloadUrl "arm64";
130           sha256 = aarch64sha256;
131         };
132         "x86_64-linux" = fetchurl {
133           url = downloadUrl "x64";
134           sha256 = x64sha256;
135         };
136       };
137     };
138   };
140 stdenv.mkDerivation (rec {
141   pname = pnameBase;
142   version = buildVersion;
144   dontUnpack = true;
146   ${primaryBinary} = binaryPackage;
148   nativeBuildInputs = [
149     makeWrapper
150   ];
152   installPhase =
153     ''
154       mkdir -p "$out/bin"
155       makeWrapper "''$${primaryBinary}/${primaryBinary}" "$out/bin/${primaryBinary}"
156     ''
157     + builtins.concatStringsSep "" (
158       map (binaryAlias: "ln -s $out/bin/${primaryBinary} $out/bin/${binaryAlias}\n") primaryBinaryAliases
159     )
160     + ''
161       mkdir -p "$out/share/applications"
163       substitute \
164         "''$${primaryBinary}/${primaryBinary}.desktop" \
165         "$out/share/applications/${primaryBinary}.desktop" \
166         --replace-fail "/opt/${primaryBinary}/${primaryBinary}" "${primaryBinary}"
168       for directory in ''$${primaryBinary}/Icon/*; do
169         size=$(basename $directory)
170         mkdir -p "$out/share/icons/hicolor/$size/apps"
171         ln -s ''$${primaryBinary}/Icon/$size/* $out/share/icons/hicolor/$size/apps
172       done
173     '';
175   passthru = {
176     updateScript =
177       let
178         script = writeShellScript "${packageAttribute}-update-script" ''
179           set -o errexit
180           PATH=${
181             lib.makeBinPath [
182               common-updater-scripts
183               curl
184             ]
185           }
187           versionFile=$1
188           latestVersion=$(curl -s "${versionUrl}")
190           if [[ "${buildVersion}" = "$latestVersion" ]]; then
191               echo "The new version same as the old version."
192               exit 0
193           fi
195           for platform in ${lib.escapeShellArgs meta.platforms}; do
196               update-source-version "${packageAttribute}.${primaryBinary}" "$latestVersion" --ignore-same-version --file="$versionFile" --version-key=buildVersion --source-key="sources.$platform"
197           done
198         '';
199       in
200       [
201         script
202         versionFile
203       ];
204   };
206   meta = with lib; {
207     description = "Sophisticated text editor for code, markup and prose";
208     homepage = "https://www.sublimetext.com/";
209     maintainers = with maintainers; [
210       jtojnar
211       wmertens
212       demin-dmitriy
213       zimbatm
214     ];
215     sourceProvenance = with sourceTypes; [ binaryNativeCode ];
216     license = licenses.unfree;
217     platforms = [
218       "aarch64-linux"
219       "x86_64-linux"
220     ];
221   };