sublime4,sublime-merge: format with nixpkgs-fmt

This commit is contained in:
Jan Tojnar 2024-04-04 15:33:55 +02:00
parent ce7b7e7e8a
commit e2d93cb47e
4 changed files with 213 additions and 78 deletions

View File

@ -1,19 +1,53 @@
{ buildVersion, aarch64sha256, x64sha256, dev ? false }:
{
buildVersion,
dev ? false,
aarch64sha256,
x64sha256,
}:
{ fetchurl, stdenv, lib, xorg, glib, libglvnd, glibcLocales, gtk3, cairo, pango, makeWrapper, wrapGAppsHook
, writeShellScript, common-updater-scripts, curl
, openssl_1_1, bzip2, bash, unzip, zip
, sqlite
{
fetchurl,
stdenv,
lib,
xorg,
glib,
libglvnd,
glibcLocales,
gtk3,
cairo,
pango,
makeWrapper,
wrapGAppsHook,
writeShellScript,
common-updater-scripts,
curl,
openssl_1_1,
bzip2,
bash,
unzip,
zip,
sqlite,
}:
let
pnameBase = "sublimetext4";
packageAttribute = "sublime4${lib.optionalString dev "-dev"}";
binaries = [ "sublime_text" "plugin_host-3.3" "plugin_host-3.8" crashHandlerBinary ];
binaries = [
"sublime_text"
"plugin_host-3.3"
"plugin_host-3.8"
crashHandlerBinary
];
primaryBinary = "sublime_text";
primaryBinaryAliases = [ "subl" "sublime" "sublime4" ];
crashHandlerBinary = if lib.versionAtLeast buildVersion "4153" then "crash_handler" else "crash_reporter";
downloadUrl = arch: "https://download.sublimetext.com/sublime_text_build_${buildVersion}_${arch}.tar.xz";
primaryBinaryAliases = [
"subl"
"sublime"
"sublime4"
];
crashHandlerBinary =
if lib.versionAtLeast buildVersion "4153" then "crash_handler" else "crash_reporter";
downloadUrl =
arch: "https://download.sublimetext.com/sublime_text_build_${buildVersion}_${arch}.tar.xz";
versionUrl = "https://download.sublimetext.com/latest/${if dev then "dev" else "stable"}";
versionFile = builtins.toString ./packages.nix;
@ -30,7 +64,8 @@ let
] ++ lib.optionals (lib.versionAtLeast buildVersion "4145") [
sqlite
];
in let
in
let
binaryPackage = stdenv.mkDerivation rec {
pname = "${pnameBase}-bin";
version = buildVersion;
@ -39,8 +74,19 @@ in let
dontStrip = true;
dontPatchELF = true;
buildInputs = [ glib gtk3 ]; # for GSETTINGS_SCHEMAS_PATH
nativeBuildInputs = [ zip unzip makeWrapper wrapGAppsHook ];
buildInputs = [
glib
# for GSETTINGS_SCHEMAS_PATH
gtk3
];
nativeBuildInputs = [
zip
unzip
makeWrapper
wrapGAppsHook
];
# make exec.py in Default.sublime-package use own bash with an LD_PRELOAD instead of "/bin/bash"
patchPhase = ''
@ -63,7 +109,7 @@ in let
buildPhase = ''
runHook preBuild
for binary in ${ builtins.concatStringsSep " " binaries }; do
for binary in ${builtins.concatStringsSep " " binaries}; do
patchelf \
--interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath ${lib.makeLibraryPath neededLibraries}:${stdenv.cc.cc.lib}/lib${lib.optionalString stdenv.is64bit "64"} \
@ -116,7 +162,8 @@ in let
};
};
};
in stdenv.mkDerivation (rec {
in
stdenv.mkDerivation (rec {
pname = pnameBase;
version = buildVersion;
@ -124,12 +171,19 @@ in stdenv.mkDerivation (rec {
${primaryBinary} = binaryPackage;
nativeBuildInputs = [ makeWrapper ];
nativeBuildInputs = [
makeWrapper
];
installPhase = ''
installPhase =
''
mkdir -p "$out/bin"
makeWrapper "''$${primaryBinary}/${primaryBinary}" "$out/bin/${primaryBinary}"
'' + builtins.concatStringsSep "" (map (binaryAlias: "ln -s $out/bin/${primaryBinary} $out/bin/${binaryAlias}\n") primaryBinaryAliases) + ''
''
+ builtins.concatStringsSep "" (
map (binaryAlias: "ln -s $out/bin/${primaryBinary} $out/bin/${binaryAlias}\n") primaryBinaryAliases
)
+ ''
mkdir -p "$out/share/applications"
substitute "''$${primaryBinary}/${primaryBinary}.desktop" "$out/share/applications/${primaryBinary}.desktop" --replace "/opt/${primaryBinary}/${primaryBinary}" "${primaryBinary}"
for directory in ''$${primaryBinary}/Icon/*; do
@ -144,7 +198,12 @@ in stdenv.mkDerivation (rec {
let
script = writeShellScript "${packageAttribute}-update-script" ''
set -o errexit
PATH=${lib.makeBinPath [ common-updater-scripts curl ]}
PATH=${
lib.makeBinPath [
common-updater-scripts
curl
]
}
versionFile=$1
latestVersion=$(curl -s "${versionUrl}")
@ -161,15 +220,27 @@ in stdenv.mkDerivation (rec {
update-source-version "${packageAttribute}.${primaryBinary}" "$latestVersion" --file="$versionFile" --version-key=buildVersion --source-key="sources.$platform"
done
'';
in [ script versionFile ];
in
[
script
versionFile
];
};
meta = with lib; {
description = "Sophisticated text editor for code, markup and prose";
homepage = "https://www.sublimetext.com/";
maintainers = with maintainers; [ jtojnar wmertens demin-dmitriy zimbatm ];
maintainers = with maintainers; [
jtojnar
wmertens
demin-dmitriy
zimbatm
];
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
license = licenses.unfree;
platforms = [ "aarch64-linux" "x86_64-linux" ];
platforms = [
"aarch64-linux"
"x86_64-linux"
];
};
})

View File

@ -3,17 +3,17 @@
let
common = opts: callPackage (import ./common.nix opts);
in
{
{
sublime4 = common {
buildVersion = "4169";
x64sha256 = "jk9wKC0QgfhiHDYUcnDhsmgJsBPOUmCkyvQeI54IJJ4=";
aarch64sha256 = "/W/xGbE+8gGu1zNh6lERZrfG9Dh9QUGkYiqTzp216JI=";
} {};
} { };
sublime4-dev = common {
buildVersion = "4168";
dev = true;
x64sha256 = "KfW1Mh78CUBTmthHQd1s15a7GrmssSnWZ1RgaarJeag=";
aarch64sha256 = "qJ9oix1kwWN+TUb5/WSKyHcHzB+Q87XolMOhmqx1OFc=";
} {};
}
} { };
}

View File

@ -1,18 +1,49 @@
{ buildVersion, aarch64sha256, x64sha256, dev ? false }:
{
buildVersion,
dev ? false,
aarch64sha256,
x64sha256,
}:
{ fetchurl, lib, stdenv, xorg, glib, libGL, glibcLocales, gtk3, cairo, pango, libredirect, makeWrapper, wrapGAppsHook
, pkexecPath ? "/run/wrappers/bin/pkexec"
, writeShellScript, common-updater-scripts, curl, gnugrep, coreutils
{
fetchurl,
lib,
stdenv,
xorg,
glib,
libGL,
glibcLocales,
gtk3,
cairo,
pango,
libredirect,
makeWrapper,
wrapGAppsHook,
pkexecPath ? "/run/wrappers/bin/pkexec",
writeShellScript,
common-updater-scripts,
curl,
gnugrep,
coreutils,
}:
let
pnameBase = "sublime-merge";
packageAttribute = "sublime-merge${lib.optionalString dev "-dev"}";
binaries = [ "sublime_merge" crashHandlerBinary "git-credential-sublime" "ssh-askpass-sublime" ];
binaries = [
"sublime_merge"
crashHandlerBinary
"git-credential-sublime"
"ssh-askpass-sublime"
];
primaryBinary = "sublime_merge";
primaryBinaryAliases = [ "smerge" ];
crashHandlerBinary = if lib.versionAtLeast buildVersion "2086" then "crash_handler" else "crash_reporter";
downloadUrl = arch: "https://download.sublimetext.com/sublime_merge_build_${buildVersion}_${arch}.tar.xz";
primaryBinaryAliases = [
"smerge"
];
crashHandlerBinary =
if lib.versionAtLeast buildVersion "2086" then "crash_handler" else "crash_reporter";
downloadUrl =
arch: "https://download.sublimetext.com/sublime_merge_build_${buildVersion}_${arch}.tar.xz";
versionUrl = "https://www.sublimemerge.com/${if dev then "dev" else "download"}";
versionFile = builtins.toString ./default.nix;
@ -25,8 +56,12 @@ let
curl
];
redirects = [ "/usr/bin/pkexec=${pkexecPath}" "/bin/true=${coreutils}/bin/true" ];
in let
redirects = [
"/usr/bin/pkexec=${pkexecPath}"
"/bin/true=${coreutils}/bin/true"
];
in
let
binaryPackage = stdenv.mkDerivation rec {
pname = "${pnameBase}-bin";
version = buildVersion;
@ -35,13 +70,20 @@ in let
dontStrip = true;
dontPatchELF = true;
buildInputs = [ glib gtk3 ]; # for GSETTINGS_SCHEMAS_PATH
nativeBuildInputs = [ makeWrapper wrapGAppsHook ];
buildInputs = [
glib
# for GSETTINGS_SCHEMAS_PATH
gtk3
];
nativeBuildInputs = [
makeWrapper
wrapGAppsHook
];
buildPhase = ''
runHook preBuild
for binary in ${ builtins.concatStringsSep " " binaries }; do
for binary in ${builtins.concatStringsSep " " binaries}; do
patchelf \
--interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath ${lib.makeLibraryPath neededLibraries}:${libGL}/lib:${stdenv.cc.cc.lib}/lib${lib.optionalString stdenv.is64bit "64"} \
@ -96,7 +138,8 @@ in let
};
};
};
in stdenv.mkDerivation (rec {
in
stdenv.mkDerivation (rec {
pname = pnameBase;
version = buildVersion;
@ -104,12 +147,19 @@ in stdenv.mkDerivation (rec {
${primaryBinary} = binaryPackage;
nativeBuildInputs = [ makeWrapper ];
nativeBuildInputs = [
makeWrapper
];
installPhase = ''
installPhase =
''
mkdir -p "$out/bin"
makeWrapper "''$${primaryBinary}/${primaryBinary}" "$out/bin/${primaryBinary}"
'' + builtins.concatStringsSep "" (map (binaryAlias: "ln -s $out/bin/${primaryBinary} $out/bin/${binaryAlias}\n") primaryBinaryAliases) + ''
''
+ builtins.concatStringsSep "" (
map (binaryAlias: "ln -s $out/bin/${primaryBinary} $out/bin/${binaryAlias}\n") primaryBinaryAliases
)
+ ''
mkdir -p "$out/share/applications"
substitute "''$${primaryBinary}/${primaryBinary}.desktop" "$out/share/applications/${primaryBinary}.desktop" --replace "/opt/${primaryBinary}/${primaryBinary}" "${primaryBinary}"
for directory in ''$${primaryBinary}/Icon/*; do
@ -124,7 +174,13 @@ in stdenv.mkDerivation (rec {
let
script = writeShellScript "${packageAttribute}-update-script" ''
set -o errexit
PATH=${lib.makeBinPath [ common-updater-scripts curl gnugrep ]}
PATH=${
lib.makeBinPath [
common-updater-scripts
curl
gnugrep
]
}
versionFile=$1
latestVersion=$(curl -s ${versionUrl} | grep -Po '(?<=<p class="latest"><i>Version:</i> Build )([0-9]+)')
@ -141,7 +197,11 @@ in stdenv.mkDerivation (rec {
update-source-version "${packageAttribute}.${primaryBinary}" "$latestVersion" --file="$versionFile" --version-key=buildVersion --source-key="sources.$platform"
done
'';
in [ script versionFile ];
in
[
script
versionFile
];
};
meta = with lib; {
@ -150,6 +210,9 @@ in stdenv.mkDerivation (rec {
maintainers = with maintainers; [ zookatron ];
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
license = licenses.unfree;
platforms = [ "aarch64-linux" "x86_64-linux" ];
platforms = [
"aarch64-linux"
"x86_64-linux"
];
};
})

View File

@ -2,17 +2,18 @@
let
common = opts: callPackage (import ./common.nix opts);
in {
in
{
sublime-merge = common {
buildVersion = "2091";
aarch64sha256 = "dkPKuuzQQtL3eZlaAPeL7e2p5PCxroFRSp6Rw5wHODc=";
x64sha256 = "T5g6gHgl9xGytEOsh3VuB08IrbDvMu24o/1edCGmfd4=";
} {};
} { };
sublime-merge-dev = common {
buildVersion = "2092";
dev = true;
aarch64sha256 = "3QMDynXMVB4QVtM8EPbZ8I4m+5sEjzs8XN+jEoMaktM=";
x64sha256 = "S9E+wRvO41Eq+PLA/J+sjBIAn6yz715Wg9bKRW2Eobg=";
dev = true;
} {};
} { };
}