Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snowsql: Add support for darwin platforms #320328

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions pkgs/applications/misc/snowsql/darwin.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
lib,
stdenvNoCC,
fetchurl,
unzip,
cpio,
gzip,
unar,
zlib,
version,
meta,
pname,
}:
stdenvNoCC.mkDerivation (finalAttrs: {
inherit pname version meta;
dontStrip = true;

src = fetchurl {
url = "https://sfc-repo.snowflakecomputing.com/snowsql/bootstrap/${lib.versions.majorMinor finalAttrs.version}/darwin_${stdenvNoCC.hostPlatform.darwinArch}/snowsql-${finalAttrs.version}-darwin_${stdenvNoCC.hostPlatform.darwinArch}.pkg";
sha256 =
if stdenvNoCC.isAarch64
then "acb2096b87466f0fdbff544d9f64feafc23cbee1bdf963e84b9658511ade9536"
else "9727c07fc11b1d8adf4a4eb0b5b996d82cd3d9da191a86f4c7b772726f8e5e92";
};

nativeBuildInputs = [
unar
cpio
unzip
gzip
zlib
];

unpackPhase = ''
unar $src
'';

buildPhase = ''
cd *snowsql-${finalAttrs.version}-darwin_${stdenvNoCC.hostPlatform.darwinArch}
cat snowsql-darwin.pkg/Payload | gzip -d | cpio -idmv
unzip SnowSQL.app/Contents/MacOS/snowsql-${finalAttrs.version}-darwin_${stdenvNoCC.hostPlatform.darwinArch}.zip -d zipped-content
'';

installPhase = ''
mkdir -p $out/bin
cp -r zipped-content/* $out/bin/
'';
})
53 changes: 15 additions & 38 deletions pkgs/applications/misc/snowsql/default.nix
Original file line number Diff line number Diff line change
@@ -1,49 +1,26 @@
{ lib
, stdenv
, fetchurl
, rpmextract
, patchelf
, makeWrapper
, openssl
, libxcrypt-legacy
{
stdenvNoCC,
callPackage,
lib,
}:

stdenv.mkDerivation rec {
let
pname = "snowsql";
version = "1.3.0";

src = fetchurl {
url = "https://sfc-repo.snowflakecomputing.com/snowsql/bootstrap/${lib.versions.majorMinor version}/linux_x86_64/snowflake-snowsql-${version}-1.x86_64.rpm";
sha256 = "sha256-KKCCj+pIwWhuzOuxljQ8Y11mAwD/GONspbXuPAMBdhE=";
};

nativeBuildInputs = [ rpmextract makeWrapper ];

libPath = lib.makeLibraryPath [ openssl libxcrypt-legacy ];

buildCommand = ''
mkdir -p $out/bin/
cd $out
rpmextract $src
rm -R usr/bin
mv usr/* $out
rmdir usr

${patchelf}/bin/patchelf \
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
lib64/snowflake/snowsql/snowsql

makeWrapper $out/lib64/snowflake/snowsql/snowsql $out/bin/snowsql \
--set LD_LIBRARY_PATH "${libPath}":"${placeholder "out"}"/lib64/snowflake/snowsql \
'';

meta = with lib; {
description = "Command line client for the Snowflake database";
homepage = "https://www.snowflake.com";
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
license = licenses.unfree;
maintainers = with maintainers; [ andehen ];
platforms = [ "x86_64-linux" ];
platforms = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
mainProgram = "snowsql";
};
}
in
if stdenvNoCC.isDarwin then
callPackage ./darwin.nix { inherit pname version meta; }
else
callPackage ./linux.nix { inherit pname version meta; }
51 changes: 51 additions & 0 deletions pkgs/applications/misc/snowsql/linux.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
lib,
stdenv,
andehen marked this conversation as resolved.
Show resolved Hide resolved
fetchurl,
rpmextract,
makeWrapper,
openssl,
libxcrypt-legacy,
zlib,
version,
pname,
meta,
}:
stdenv.mkDerivation (finalAttrs: {
inherit pname version meta;
src = fetchurl {
url = "https://sfc-repo.snowflakecomputing.com/snowsql/bootstrap/${lib.versions.majorMinor finalAttrs.version}/linux_x86_64/snowflake-snowsql-${finalAttrs.version}-1.x86_64.rpm";
sha256 = "28a0828fea48c1686eccebb196343c635d660300ff18e36ca5b5ee3c03017611";
};

nativeBuildInputs = [
rpmextract
makeWrapper
];

unpackPhase = ''
rpmextract $src
'';

installPhase = ''
mkdir -p $out/{bin,lib}
mv usr/lib64/snowflake/snowsql/* $out/lib/
'';

libPath = lib.makeLibraryPath [
openssl
libxcrypt-legacy
zlib
];

preFixup = ''
patchelf \
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
$out/lib/snowsql
'';

postFixup = ''
makeWrapper $out/lib/snowsql $out/bin/snowsql \
--set LD_LIBRARY_PATH "${finalAttrs.libPath}":"$out/lib"
'';
})