22 pkexecPath ? "/run/wrappers/bin/pkexec",
24 common-updater-scripts,
31 pnameBase = "sublime-merge";
32 packageAttribute = "sublime-merge${lib.optionalString dev "-dev"}";
36 "git-credential-sublime"
39 primaryBinary = "sublime_merge";
40 primaryBinaryAliases = [
44 if lib.versionAtLeast buildVersion "2086" then "crash_handler" else "crash_reporter";
46 arch: "https://download.sublimetext.com/sublime_merge_build_${buildVersion}_${arch}.tar.xz";
47 versionUrl = "https://www.sublimemerge.com/${if dev then "dev" else "download"}";
48 versionFile = builtins.toString ./default.nix;
60 "/usr/bin/pkexec=${pkexecPath}"
61 "/bin/true=${coreutils}/bin/true"
64 binaryPackage = stdenv.mkDerivation rec {
65 pname = "${pnameBase}-bin";
66 version = buildVersion;
68 src = passthru.sources.${stdenv.hostPlatform.system};
74 # for GSETTINGS_SCHEMAS_PATH
85 for binary in ${builtins.concatStringsSep " " binaries}; do
87 --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
88 --set-rpath ${lib.makeLibraryPath neededLibraries}:${libGL}/lib:${lib.getLib stdenv.cc.cc}/lib${lib.optionalString stdenv.hostPlatform.is64bit "64"} \
92 # Rewrite pkexec argument. Note that we cannot delete bytes in binary.
93 sed -i -e 's,/bin/cp\x00,cp\x00\x00\x00\x00\x00\x00,g' ${primaryBinary}
107 dontWrapGApps = true; # non-standard location, need to wrap the executables manually
110 wrapProgram $out/${primaryBinary} \
111 --set LD_PRELOAD "${libredirect}/lib/libredirect.so" \
112 --set NIX_REDIRECTS ${builtins.concatStringsSep ":" redirects} \
113 --set LOCALE_ARCHIVE "${glibcLocales.out}/lib/locale/locale-archive" \
114 "''${gappsWrapperArgs[@]}"
116 # We need to replace the ssh-askpass-sublime executable because the default one
117 # will not function properly, in order to work it needs to pass an argv[0] to
118 # the sublime_merge binary, and the built-in version will try to call the
119 # sublime_merge wrapper script which cannot pass through the original argv[0] to
120 # the sublime_merge binary. Thankfully the ssh-askpass-sublime functionality is
121 # very simple and can be replaced with a simple wrapper script.
122 rm $out/ssh-askpass-sublime
123 makeWrapper $out/.${primaryBinary}-wrapped $out/ssh-askpass-sublime \
124 --argv0 "/ssh-askpass-sublime"
129 "aarch64-linux" = fetchurl {
130 url = downloadUrl "arm64";
131 sha256 = aarch64sha256;
133 "x86_64-linux" = fetchurl {
134 url = downloadUrl "x64";
141 stdenv.mkDerivation (rec {
143 version = buildVersion;
147 ${primaryBinary} = binaryPackage;
149 nativeBuildInputs = [
156 makeWrapper "''$${primaryBinary}/${primaryBinary}" "$out/bin/${primaryBinary}"
158 + builtins.concatStringsSep "" (
159 map (binaryAlias: "ln -s $out/bin/${primaryBinary} $out/bin/${binaryAlias}\n") primaryBinaryAliases
162 mkdir -p "$out/share/applications"
165 "''$${primaryBinary}/${primaryBinary}.desktop" \
166 "$out/share/applications/${primaryBinary}.desktop" \
167 --replace-fail "/opt/${primaryBinary}/${primaryBinary}" "${primaryBinary}"
169 for directory in ''$${primaryBinary}/Icon/*; do
170 size=$(basename $directory)
171 mkdir -p "$out/share/icons/hicolor/$size/apps"
172 ln -s ''$${primaryBinary}/Icon/$size/* $out/share/icons/hicolor/$size/apps
179 script = writeShellScript "${packageAttribute}-update-script" ''
183 common-updater-scripts
190 latestVersion=$(curl -s ${versionUrl} | grep -Po '(?<=<p class="latest"><i>Version:</i> Build )([0-9]+)')
192 if [[ "${buildVersion}" = "$latestVersion" ]]; then
193 echo "The new version same as the old version."
197 for platform in ${lib.escapeShellArgs meta.platforms}; do
198 update-source-version "${packageAttribute}.${primaryBinary}" "$latestVersion" --ignore-same-version --file="$versionFile" --version-key=buildVersion --source-key="sources.$platform"
209 description = "Git client from the makers of Sublime Text";
210 homepage = "https://www.sublimemerge.com";
211 maintainers = with maintainers; [ zookatron ];
212 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
213 license = licenses.unfree;