dockutil: refactor to build from source on aarch64

This commit is contained in:
Alexis Hildebrandt 2024-03-03 15:47:41 +01:00
parent 1e8685d341
commit 453aff31c6
3 changed files with 120 additions and 25 deletions

@ -1,36 +1,99 @@
{ lib, stdenv, fetchurl, libarchive, p7zip }:
stdenv.mkDerivation (finalAttrs: {
{ lib
, stdenv
, stdenvNoCC
, fetchFromGitHub
, fetchurl
, swift
, swiftpm
, swiftpm2nix
, swiftPackages
, darwin
, libarchive
, p7zip
# Building from source on x86_64 fails (among other things) due to:
# error: cannot load underlying module for 'Darwin'
, fromSource ? (stdenv.system != "x86_64-darwin")
}:
let
generated = swiftpm2nix.helpers ./generated;
pname = "dockutil";
version = "3.1.3";
src = fetchurl {
url =
"https://github.com/kcrawford/dockutil/releases/download/${finalAttrs.version}/dockutil-${finalAttrs.version}.pkg";
hash = "sha256-9g24Jz/oDXxIJFiL7bU4pTh2dcORftsAENq59S0/JYI=";
};
dontBuild = true;
nativeBuildInputs = [ libarchive p7zip ];
unpackCmd = "7z x -so $src | bsdtar -x";
installPhase = ''
runHook preInstall
mkdir -p $out/bin
mkdir -p $out/usr/local/bin
install -Dm755 local/bin/dockutil -t $out/usr/local/bin
ln -rs $out/usr/local/bin/dockutil $out/bin/dockutil
runHook postInstall
'';
meta = with lib; {
description = "Tool for managing dock items";
homepage = "https://github.com/kcrawford/dockutil";
license = licenses.asl20;
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
maintainers = with maintainers; [ tboerger ];
mainProgram = "dockutil";
platforms = platforms.darwin;
};
})
buildFromSource = swiftPackages.stdenv.mkDerivation (finalAttrs: {
inherit pname version meta;
src = fetchFromGitHub {
owner = "kcrawford";
repo = "dockutil";
rev = finalAttrs.version;
hash = "sha256-mmk4vVZhq4kt05nI/dDM1676FDWyf4wTSwY2YzqKsLU=";
};
postPatch = ''
# Patch sources so that they build with Swift CoreFoundation
# which differs ever so slightly from Apple's implementation.
substituteInPlace Sources/DockUtil/DockUtil.swift \
--replace-fail "URL(filePath:" \
"URL(fileURLWithPath:" \
--replace-fail "path(percentEncoded: false)" \
"path"
'';
nativeBuildInputs = [ swift swiftpm ];
buildInputs = with darwin.apple_sdk.frameworks; [ Cocoa ];
configurePhase = generated.configure;
installPhase = ''
runHook preInstall
install -Dm755 .build/${stdenv.hostPlatform.darwinArch}-apple-macosx/release/dockutil -t $out/bin
runHook postInstall
'';
});
installBinary = stdenvNoCC.mkDerivation (finalAttrs: {
inherit pname version;
src = fetchurl {
url = "https://github.com/kcrawford/dockutil/releases/download/${finalAttrs.version}/dockutil-${finalAttrs.version}.pkg";
hash = "sha256-9g24Jz/oDXxIJFiL7bU4pTh2dcORftsAENq59S0/JYI=";
};
dontPatch = true;
dontConfigure = true;
dontBuild = true;
nativeBuildInputs = [ libarchive p7zip ];
unpackPhase = ''
7z x $src
bsdtar -xf Payload~
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
install -Dm755 usr/local/bin/dockutil -t $out/bin
runHook postInstall
'';
meta = meta // {
sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
};
});
in
if fromSource
then buildFromSource
else installBinary

@ -0,0 +1,7 @@
# This file was generated by swiftpm2nix.
{
workspaceStateFile = ./workspace-state.json;
hashes = {
"swift-argument-parser" = "1fpdgivmwdszggvx0ligs3vidv9kpp9777v649hs8w7vpcifc2ji";
};
}

@ -0,0 +1,25 @@
{
"object": {
"artifacts": [],
"dependencies": [
{
"basedOn": null,
"packageRef": {
"identity": "swift-argument-parser",
"kind": "remoteSourceControl",
"location": "https://github.com/apple/swift-argument-parser.git",
"name": "swift-argument-parser"
},
"state": {
"checkoutState": {
"revision": "82905286cc3f0fa8adc4674bf49437cab65a8373",
"version": "1.1.1"
},
"name": "sourceControlCheckout"
},
"subpath": "swift-argument-parser"
}
]
},
"version": 6
}