-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
darwin: installBinaryPackage init and refactoring of darwin apps #293498
base: master
Are you sure you want to change the base?
Changes from all commits
5cf386b
26d86e7
1624d72
abbdb9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,31 @@ | ||
{ lib | ||
, stdenvNoCC | ||
, fetchurl | ||
, _7zz | ||
, darwin | ||
}: | ||
|
||
stdenvNoCC.mkDerivation (finalAttrs: { | ||
darwin.installBinaryPackage rec { | ||
pname = "bartender"; | ||
version = "5.0.49"; | ||
|
||
src = fetchurl { | ||
name = "Bartender ${lib.versions.major finalAttrs.version}.dmg"; | ||
url = "https://www.macbartender.com/B2/updates/${builtins.replaceStrings [ "." ] [ "-" ] finalAttrs.version}/Bartender%20${lib.versions.major finalAttrs.version}.dmg"; | ||
url = "https://www.macbartender.com/B2/updates/${builtins.replaceStrings [ "." ] [ "-" ] version}/Bartender%20${lib.versions.major version}.dmg"; | ||
hash = "sha256-DOQLtdbwYFyRri3GBdjLfFNII65QJMvAQu9Be4ATBx0="; | ||
}; | ||
|
||
dontPatch = true; | ||
dontConfigure = true; | ||
dontBuild = true; | ||
dontFixup = true; | ||
|
||
nativeBuildInputs = [ _7zz ]; | ||
|
||
sourceRoot = "Bartender ${lib.versions.major finalAttrs.version}.app"; | ||
|
||
installPhase = '' | ||
runHook preInstall | ||
|
||
mkdir -p "$out/Applications/${finalAttrs.sourceRoot}" | ||
cp -R . "$out/Applications/${finalAttrs.sourceRoot}" | ||
|
||
runHook postInstall | ||
''; | ||
appName = "Bartender ${lib.versions.major version}.app"; | ||
|
||
meta = with lib; { | ||
description = "Take control of your menu bar"; | ||
longDescription = '' | ||
Bartender is an award-winning app for macOS that superpowers your menu bar, giving you total control over your menu bar items, what's displayed, and when, with menu bar items only showing when you need them. | ||
Bartender improves your workflow with quick reveal, search, custom hotkeys and triggers, and lots more. | ||
Bartender is an award-winning app for macOS that superpowers your menu | ||
bar, giving you total control over your menu bar items, what's displayed, | ||
and when, with menu bar items only showing when you need them. | ||
Bartender improves your workflow with quick reveal, search, custom | ||
hotkeys and triggers, and lots more. | ||
''; | ||
homepage = "https://www.macbartender.com"; | ||
changelog = "https://www.macbartender.com/Bartender${lib.versions.major finalAttrs.version}/release_notes/"; | ||
changelog = "https://www.macbartender.com/Bartender${lib.versions.major version}/release_notes/"; | ||
license = with licenses; [ unfree ]; | ||
sourceProvenance = with sourceTypes; [ binaryNativeCode ]; | ||
maintainers = with maintainers; [ stepbrobd ]; | ||
platforms = [ "aarch64-darwin" "x86_64-darwin" ]; | ||
}; | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,44 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ lib, stdenvNoCC, makeSetupHook, _7zz, libarchive }: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ appName ? "." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
, nativeBuildInputs ? [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
, sourceRoot ? "." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
If we do want one, it could be called |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
, ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}@args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
unpackDmgPkg = makeSetupHook { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name = "unpack-dmg-pkg"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
propagatedBuildInputs = [ _7zz libarchive ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} ./unpack-dmg-pkg.sh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
stdenvNoCC.mkDerivation (args // { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+3
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this, @ShamrockLee, I've included your suggestion locally, but need to refactor the treewide changes before pushing an update on this. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dontMakeSourcesWritable = args.dontMakeSourcesWritable or true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dontPatch = args.dontPatch or true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dontConfigure = args.dontConfigure or true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dontBuild = args.dontBuild or true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dontStrip = args.dontStrip or true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dontFixup = args.dontFixup or true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dontCheck = args.dontCheck or true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The attribute is called If we do need
to guarentee its availability. Attempt to determine if an attribute is available in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason I thought both existed, @ShamrockLee. Grep'ing through the packages around 80 use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @afh This comment slipped out of my radar. Thank you for your patience.
After some keyword searching inside VSCode, it seems most of the Searching with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once again an excellent analysis from you, @ShamrockLee 😃👍
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The proof turns out to be quite simple:
It would be helpful for people who use and maintain these packages. That said, I wonder whether those packages really need their install checks disabled if they build fine without. Feel free to tag the package maintainers in the PR description. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
doInstallCheck = args.doInstallCheck or false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+16
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sourceRoot = "${args.pname}/${sourceRoot}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Just give it a sensible default. (Replace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might be a bit more involved than it seems and possibly a more elegant way exists to solve what the current approach solves. Most of the binary sources unpack multiple files, a directory, or a one or more archive files (often named So my idea was to simple put all unpacked files into a directory named Have I been able to explain my thinking around this well? ──────────── There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That makes sense. Then, how about setting The current implementation will result in developer setting From the search result inside the Nixpkgs code base with regular expression I could only express my point of view instead of requesting a change, as I'm nither a committer nor a Darwin user. The design choice will be made by you and the committers. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nativeBuildInputs = [ unpackDmgPkg ] ++ nativeBuildInputs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
installPhase = args.installPhase or '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
runHook preInstall | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mkdir -p $out/Applications | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cp -R "${appName}" $out/Applications | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
runHook postInstall | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
installCheckPhase = args.installCheckPhase or null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
meta = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
platforms = lib.platforms.darwin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} // (args.meta or {}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# shellcheck shell=bash | ||
unpackCmdHooks+=(unpackDmgPkg) | ||
unpackDmgPkg() { | ||
case "$curSrc" in | ||
*.dmg) unpackDmg "$curSrc";; | ||
*.pkg) unpackPkg "$curSrc";; | ||
*) return 1 | ||
esac | ||
} | ||
|
||
unpackDmg() { | ||
_unpack "$1" "${2:-$pname}" | ||
} | ||
|
||
unpackPkg() { | ||
_unpack "$1" "${2:-$pname}" | ||
pushd "${2:-$pname}" | ||
# Extract files from Payload or Payload~ file contained in given pkg if any | ||
find . -name 'Payload*' -maxdepth 1 -print0 | xargs -0 -t -I % bsdtar -xf % | ||
popd | ||
} | ||
|
||
_unpack() { | ||
# Exclude */Applications files from extraction as they may | ||
# contain a dangerous link path, causing 7zz to error. | ||
# Exclude *com.apple.provenance xattr files from extraction as they | ||
# break the an application's signature and notarization. | ||
7zz x -bd -o"$2" -xr'!*/Applications' -xr'!*com.apple.provenance' "$1" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought it was preferred to use the finalAttrs pattern over rec, why switch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on my understanding,
mkDerivation
takes either an attrset or a function (thefinalAttrs
pattern) as argument.This PR introduces
installBinaryPackage
to simplify the process of packaging macOS apps and reduces the overuse ofmkDerivation
(code duplication in general). It takes an attrset as argument, i.e. thefinalAttrs
pattern is not applicable here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why most build helpers in Nixpkgs don't support fixed-point arguments (
finalAttrs: { ... }
) yet, is because of the challenge to handle technical debts inside existing build helpers -- arguments that cannot be passed directly tostdenv.mkDerivation
.The goal of #234651 is to introduce a way (
lib.extendMkDerivation
) to handle such arguments and bring fixed-point arguments support to existing build helpers. Even then, there are still efforts to bring fixed-point arguments support to build helpers likebuildRustPackage
(#194475) andbuildGoModule
(#225051).As a new build helper,
installBinaryPackage
could avoid such technical debt as a whole and support fixed-point attributes out of the box without the need of the WIPlib.extendMkDerivation
. We just need to make sure that everything is passed properly intostdenv.mkDerivation
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update:
Sorry @stepbrobd for my misunderstanding your point. You're right about the current implementation of
installBinaryPackage
handling only a plain attribute set.I just want to point out that such support is not impossible or unsuitable outside
stdenv.mkDerivation
. We only need to modify the implementation ofinstallBinaryPackage
a bit to support it.