nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 buildVersion,
3 x32sha256,
4 x64sha256,
5 dev ? false,
6}:
7
8{
9 fetchurl,
10 lib,
11 stdenv,
12 xorg,
13 glib,
14 glibcLocales,
15 gtk3,
16 cairo,
17 pango,
18 libredirect,
19 makeWrapper,
20 wrapGAppsHook3,
21 pkexecPath ? "/run/wrappers/bin/pkexec",
22 openssl,
23 bzip2,
24 bash,
25 unzip,
26 zip,
27}:
28
29let
30 pname = "sublimetext3";
31 packageAttribute = "sublime3${lib.optionalString dev "-dev"}";
32 binaries = [
33 "sublime_text"
34 "plugin_host"
35 "crash_reporter"
36 ];
37 primaryBinary = "sublime_text";
38 primaryBinaryAliases = [
39 "subl"
40 "sublime"
41 "sublime3"
42 ];
43 downloadUrl = "https://download.sublimetext.com/sublime_text_3_build_${buildVersion}_${arch}.tar.bz2";
44 versionUrl = "https://download.sublimetext.com/latest/${if dev then "dev" else "stable"}";
45 versionFile = builtins.toString ./packages.nix;
46 archSha256 = if stdenv.hostPlatform.system == "i686-linux" then x32sha256 else x64sha256;
47 arch = if stdenv.hostPlatform.system == "i686-linux" then "x32" else "x64";
48
49 libPath = lib.makeLibraryPath [
50 xorg.libX11
51 glib
52 gtk3
53 cairo
54 pango
55 ];
56 redirects = [ "/usr/bin/pkexec=${pkexecPath}" ];
57
58 binaryPackage = stdenv.mkDerivation {
59 pname = "${pname}-bin";
60 version = buildVersion;
61
62 src = fetchurl {
63 url = downloadUrl;
64 sha256 = archSha256;
65 };
66
67 dontStrip = true;
68 dontPatchELF = true;
69 buildInputs = [
70 glib
71 gtk3
72 ]; # for GSETTINGS_SCHEMAS_PATH
73 nativeBuildInputs = [
74 zip
75 unzip
76 makeWrapper
77 wrapGAppsHook3
78 ];
79
80 # make exec.py in Default.sublime-package use own bash with an LD_PRELOAD instead of "/bin/bash"
81 patchPhase = ''
82 runHook prePatch
83
84 mkdir Default.sublime-package-fix
85 ( cd Default.sublime-package-fix
86 unzip -q ../Packages/Default.sublime-package
87 substituteInPlace "exec.py" --replace \
88 "[\"/bin/bash\"" \
89 "[\"$out/sublime_bash\""
90 zip -q ../Packages/Default.sublime-package **/*
91 )
92 rm -r Default.sublime-package-fix
93
94 runHook postPatch
95 '';
96
97 buildPhase = ''
98 runHook preBuild
99
100 for binary in ${builtins.concatStringsSep " " binaries}; do
101 patchelf \
102 --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
103 --set-rpath ${libPath}:${lib.getLib stdenv.cc.cc}/lib${lib.optionalString stdenv.hostPlatform.is64bit "64"} \
104 $binary
105 done
106
107 # Rewrite pkexec argument. Note that we cannot delete bytes in binary.
108 sed -i -e 's,/bin/cp\x00,cp\x00\x00\x00\x00\x00\x00,g' ${primaryBinary}
109
110 runHook postBuild
111 '';
112
113 installPhase = ''
114 runHook preInstall
115
116 mkdir -p $out
117 cp -r * $out/
118
119 # We can't just call /usr/bin/env bash because a relocation error occurs
120 # when trying to run a build from within Sublime Text
121 ln -s ${bash}/bin/bash $out/sublime_bash
122
123 runHook postInstall
124 '';
125
126 dontWrapGApps = true; # non-standard location, need to wrap the executables manually
127
128 postFixup = ''
129 wrapProgram $out/sublime_bash \
130 --set LD_PRELOAD "${lib.getLib stdenv.cc.cc}/lib${lib.optionalString stdenv.hostPlatform.is64bit "64"}/libgcc_s.so.1"
131
132 wrapProgram $out/${primaryBinary} \
133 --set LD_PRELOAD "${libredirect}/lib/libredirect.so" \
134 --set NIX_REDIRECTS ${builtins.concatStringsSep ":" redirects} \
135 --set LOCALE_ARCHIVE "${glibcLocales.out}/lib/locale/locale-archive" \
136 "''${gappsWrapperArgs[@]}"
137
138 # Without this, plugin_host crashes, even though it has the rpath
139 wrapProgram $out/plugin_host --prefix LD_PRELOAD : ${lib.getLib stdenv.cc.cc}/lib${lib.optionalString stdenv.hostPlatform.is64bit "64"}/libgcc_s.so.1:${lib.getLib openssl}/lib/libssl.so:${bzip2.out}/lib/libbz2.so
140 '';
141 };
142in
143stdenv.mkDerivation (rec {
144 inherit pname;
145 version = buildVersion;
146
147 dontUnpack = true;
148
149 ${primaryBinary} = binaryPackage;
150
151 nativeBuildInputs = [ makeWrapper ];
152
153 installPhase = ''
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"
162 substitute "''$${primaryBinary}/${primaryBinary}.desktop" "$out/share/applications/${primaryBinary}.desktop" --replace "/opt/${primaryBinary}/${primaryBinary}" "$out/bin/${primaryBinary}"
163 for directory in ''$${primaryBinary}/Icon/*; do
164 size=$(basename $directory)
165 mkdir -p "$out/share/icons/hicolor/$size/apps"
166 ln -s ''$${primaryBinary}/Icon/$size/* $out/share/icons/hicolor/$size/apps
167 done
168 '';
169
170 meta = with lib; {
171 description = "Sophisticated text editor for code, markup and prose";
172 homepage = "https://www.sublimetext.com/";
173 maintainers = with maintainers; [
174 wmertens
175 demin-dmitriy
176 zimbatm
177 ];
178 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
179 license = licenses.unfree;
180 platforms = [
181 "x86_64-linux"
182 "i686-linux"
183 ];
184 };
185})