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

treewide: Refactor packages to use darwin install binary package #293961

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
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
52 changes: 27 additions & 25 deletions pkgs/applications/misc/1password/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib, stdenv, fetchurl, fetchzip, autoPatchelfHook, installShellFiles, cpio, xar, _1password, testers }:
{ lib, stdenvNoCC, fetchurl, fetchzip, autoPatchelfHook, installShellFiles, _1password, testers, darwin }:

let
inherit (stdenv.hostPlatform) system;
inherit (stdenvNoCC.hostPlatform) system;
fetch = srcPlatform: hash: extension:
let
args = {
Expand All @@ -21,49 +21,36 @@ let
x86_64-darwin = aarch64-darwin;
};
platforms = builtins.attrNames sources;
mainProgram = "op";
in

stdenv.mkDerivation {
inherit pname version;
src =
if (builtins.elem system platforms) then
sources.${system}
else
throw "Source for ${pname} is not available for ${system}";

nativeBuildInputs = [ installShellFiles ] ++ lib.optional stdenv.isLinux autoPatchelfHook;

buildInputs = lib.optionals stdenv.isDarwin [ xar cpio ];

unpackPhase = lib.optionalString stdenv.isDarwin ''
xar -xf $src
zcat op.pkg/Payload | cpio -i
'';
nativeBuildInputs = [ installShellFiles ];

installPhase = ''
runHook preInstall
install -D ${mainProgram} $out/bin/${mainProgram}
install -D ${meta.mainProgram} $out/bin/${meta.mainProgram}
runHook postInstall
'';

postInstall = ''
HOME=$TMPDIR
installShellCompletion --cmd ${mainProgram} \
--bash <($out/bin/${mainProgram} completion bash) \
--fish <($out/bin/${mainProgram} completion fish) \
--zsh <($out/bin/${mainProgram} completion zsh)
installShellCompletion --cmd ${meta.mainProgram} \
--bash <($out/bin/${meta.mainProgram} completion bash) \
--fish <($out/bin/${meta.mainProgram} completion fish) \
--zsh <($out/bin/${meta.mainProgram} completion zsh)
'';

dontStrip = stdenv.isDarwin;

doInstallCheck = true;

installCheckPhase = ''
$out/bin/${mainProgram} --version
$out/bin/${meta.mainProgram} --version
'';

passthru.tests.version = testers.testVersion {
testers' = testers.testVersion {
package = _1password;
};

Expand All @@ -74,6 +61,21 @@ stdenv.mkDerivation {
maintainers = with maintainers; [ joelburget marsam ];
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
license = licenses.unfree;
inherit mainProgram platforms;
mainProgram = "op";
inherit platforms;
};
}

linux = stdenvNoCC.mkDerivation {
inherit pname version src installPhase postInstall doInstallCheck installCheckPhase meta;
nativeBuildInputs = nativeBuildInputs ++ [ autoPatchelfHook ];
passthru.tests.version = testers';
};

darwin' = darwin.installBinaryPackage {
inherit pname version src nativeBuildInputs installPhase postInstall doInstallCheck installCheckPhase meta;
passthru.tests.version = testers';
};
in
if stdenvNoCC.isDarwin
then darwin'
else linux
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
, fetchurl
, makeDesktopItem
, makeWrapper
, stdenv
, stdenvNoCC
, lib
, udev
, wrapGAppsHook
, cpio
, xar
, libdbusmenu
, alsa-lib
, mesa
, nss
, nspr
, systemd
, darwin
}:

let

inherit (stdenv.hostPlatform) system;
inherit (stdenvNoCC.hostPlatform) system;

throwSystem = throw "Unsupported system: ${system}";

Expand Down Expand Up @@ -69,7 +68,7 @@ let
hydraPlatforms = [];
};

linux = stdenv.mkDerivation rec {
linux = stdenvNoCC.mkDerivation rec {
inherit pname version meta;

src = fetchurl {
Expand Down Expand Up @@ -143,47 +142,18 @@ let
'';
};

darwin = stdenv.mkDerivation {
darwin' = darwin.installBinaryPackage {
inherit pname version meta;

src = fetchurl {
url = "https://github.com/wireapp/wire-desktop/releases/download/macos%2F${version}/Wire.pkg";
inherit hash;
};

buildInputs = [
cpio
xar
];

unpackPhase = ''
runHook preUnpack

xar -xf $src
cd com.wearezeta.zclient.mac.pkg

runHook postUnpack
'';

buildPhase = ''
runHook preBuild

cat Payload | gunzip -dc | cpio -i

runHook postBuild
'';

installPhase = ''
runHook preInstall

mkdir -p $out/Applications
cp -r Wire.app $out/Applications

runHook postInstall
'';
appName = "Wire.app";
};

in
if stdenv.isDarwin
then darwin
if stdenvNoCC.isDarwin
then darwin'
else linux
136 changes: 61 additions & 75 deletions pkgs/applications/networking/instant-messengers/zoom-us/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
, fetchurl
, pipewire
, makeWrapper
, xar
, cpio
, darwin
# Dynamic libraries
, alsa-lib
, atk
Expand Down Expand Up @@ -112,81 +111,10 @@ let
libkrb5
] ++ lib.optional (pulseaudioSupport) libpulseaudio);

in
stdenv.mkDerivation rec {
pname = "zoom";
version = versions.${system} or throwSystem;

src = srcs.${system} or throwSystem;

dontUnpack = stdenv.isLinux;
unpackPhase = lib.optionalString stdenv.isDarwin ''
xar -xf $src
zcat < zoomus.pkg/Payload | cpio -i
'';

nativeBuildInputs = [
makeWrapper
]
++ lib.optionals stdenv.isDarwin [
xar
cpio
];

installPhase = ''
runHook preInstall
${rec {
aarch64-darwin = ''
mkdir -p $out/Applications
cp -R zoom.us.app $out/Applications/
'';
# darwin steps same on both architectures
x86_64-darwin = aarch64-darwin;
x86_64-linux = ''
mkdir $out
tar -C $out -xf $src
mv $out/usr/* $out/
'';
}.${system} or throwSystem}
runHook postInstall
'';

postFixup = lib.optionalString stdenv.isLinux ''
# Desktop File
substituteInPlace $out/share/applications/Zoom.desktop \
--replace "Exec=/usr/bin/zoom" "Exec=$out/bin/zoom"

for i in aomhost zopen zoom ZoomLauncher; do
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/opt/zoom/$i
done

# ZoomLauncher sets LD_LIBRARY_PATH before execing zoom
# IPC breaks if the executable name does not end in 'zoom'
mv $out/opt/zoom/zoom $out/opt/zoom/.zoom
makeWrapper $out/opt/zoom/.zoom $out/opt/zoom/zoom \
--prefix LD_LIBRARY_PATH ":" ${libs}

rm $out/bin/zoom
# Zoom expects "zopen" executable (needed for web login) to be present in CWD. Or does it expect
# everybody runs Zoom only after cd to Zoom package directory? Anyway, :facepalm:
# Clear Qt paths to prevent tripping over "foreign" Qt resources.
# Clear Qt screen scaling settings to prevent over-scaling.
makeWrapper $out/opt/zoom/ZoomLauncher $out/bin/zoom \
--chdir "$out/opt/zoom" \
--unset QML2_IMPORT_PATH \
--unset QT_PLUGIN_PATH \
--unset QT_SCREEN_SCALE_FACTORS \
--prefix PATH : ${lib.makeBinPath [ coreutils glib.dev pciutils procps util-linux ]} \
--prefix LD_LIBRARY_PATH ":" ${libs}

# Backwards compatiblity: we used to call it zoom-us
ln -s $out/bin/{zoom,zoom-us}
'';

# already done
dontPatchELF = true;

passthru.updateScript = ./update.sh;
updateScript = ./update.sh;

meta = with lib; {
homepage = "https://zoom.us/";
Expand All @@ -197,4 +125,62 @@ stdenv.mkDerivation rec {
maintainers = with maintainers; [ danbst tadfisher ];
mainProgram = "zoom";
};
}

linux = stdenv.mkDerivation {
dontUnpack = true;
dontPatchELF = true; # already done

nativeBuildInputs = [ makeWrapper ];

installPhase = ''
runHook preInstall
mkdir $out
tar -C $out -xf $src
mv $out/usr/* $out/
runHook postInstall
'';

postFixup = lib.optionalString stdenv.isLinux ''
# Desktop File
substituteInPlace $out/share/applications/Zoom.desktop \
--replace "Exec=/usr/bin/zoom" "Exec=$out/bin/zoom"

for i in aomhost zopen zoom ZoomLauncher; do
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/opt/zoom/$i
done

# ZoomLauncher sets LD_LIBRARY_PATH before execing zoom
# IPC breaks if the executable name does not end in 'zoom'
mv $out/opt/zoom/zoom $out/opt/zoom/.zoom
makeWrapper $out/opt/zoom/.zoom $out/opt/zoom/zoom \
--prefix LD_LIBRARY_PATH ":" ${libs}

rm $out/bin/zoom
# Zoom expects "zopen" executable (needed for web login) to be present in CWD. Or does it expect
# everybody runs Zoom only after cd to Zoom package directory? Anyway, :facepalm:
# Clear Qt paths to prevent tripping over "foreign" Qt resources.
# Clear Qt screen scaling settings to prevent over-scaling.
makeWrapper $out/opt/zoom/ZoomLauncher $out/bin/zoom \
--chdir "$out/opt/zoom" \
--unset QML2_IMPORT_PATH \
--unset QT_PLUGIN_PATH \
--unset QT_SCREEN_SCALE_FACTORS \
--prefix PATH : ${lib.makeBinPath [ coreutils glib.dev pciutils procps util-linux ]} \
--prefix LD_LIBRARY_PATH ":" ${libs}

# Backwards compatiblity: we used to call it zoom-us
ln -s $out/bin/{zoom,zoom-us}
'';

passthru.updateScript = updateScript;
};

darwin' = darwin.installBinaryPackage {
inherit pname version src meta;
appName = "zoom.us.app";
passthru.updateScript = updateScript;
};
in
if stdenv.isDarwin
then darwin'
else linux
22 changes: 6 additions & 16 deletions pkgs/by-name/ho/hoppscotch/package.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ lib
, stdenv
, stdenvNoCC
, fetchurl
, appimageTools
, undmg
, darwin
, nix-update-script
}:

Expand All @@ -23,7 +23,7 @@ let
url = "https://github.com/hoppscotch/releases/releases/download/v${version}-1/Hoppscotch_linux_x64.AppImage";
hash = "sha256-MYQ7SRm+CUPIXROZxejbbZ0/wH+U5DQO4YGbE/HQAj8=";
};
}.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}");
}.${stdenvNoCC.system} or (throw "Unsupported system: ${stdenvNoCC.system}");

meta = {
description = "Open source API development ecosystem";
Expand All @@ -34,22 +34,12 @@ let
maintainers = with lib.maintainers; [ DataHearth ];
};
in
if stdenv.isDarwin then stdenv.mkDerivation
if stdenvNoCC.isDarwin then darwin.installBinaryPackage
{
inherit pname version src meta;

sourceRoot = ".";

nativeBuildInputs = [ undmg ];

installPhase = ''
runHook preInstall

mkdir -p "$out/Applications"
mv Hoppscotch.app $out/Applications/

runHook postInstall
'';
sourceRoot = "Hoppscotch";
appName = "Hoppscotch.app";
}
else appimageTools.wrapType2 {
inherit pname version src meta;
Expand Down
Loading
Loading