Skip to content

darwin.installApplication + unpkg + unxar: init#147567

Draft
spease wants to merge 3 commits intoNixOS:masterfrom
spease:installApplication
Draft

darwin.installApplication + unpkg + unxar: init#147567
spease wants to merge 3 commits intoNixOS:masterfrom
spease:installApplication

Conversation

@spease
Copy link
Contributor

@spease spease commented Nov 27, 2021

Motivation for this change

Greatly improve ease-of-use for developing nix derivations on macOS, particularly with regards to desktop applications packaged in the typical conventions expected for non-store installation. This is intended to be an "easy path" that's as simple and minimal as possible - if someone wants to get fancy and deal with a nonstandard or more complex application, that is outside the scope of this.

This is intended to get used by as many packages as possible to rapidly increase the number of native macOS applications available under nix, perhaps even by nix newbies, so please be as critical as possible. Once merged, the interface and behavior should remain as static as possible, as later changes could require multiple packages to be refactored.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.
Example of usage
{ config, darwin }:

let
  systemLocale = config.i18n.defaultLocale or "en-US";
in
darwin.installApplication rec {
  pname = "Firefox";
  version = "94.0.2";

  url = "https://download-installer.cdn.mozilla.net/pub/firefox/releases/${version}/mac/${systemLocale}/Firefox%20${version}.dmg";
  sha256 = "Ud5k8HjzHgZOG3DxKVcbULXxHh6pHX6ymzkHkqOrGVk=";

  description = "The Firefox web browser";
  homepage = "https://www.mozilla.org/firefox";
  license = "mpl20";
  maintainers = [ "spease" ];
}
{ darwin }:

darwin.installApplication rec {
  pname = "divvy";
  version = "1.5.1";

  url = "https://mizage.com/downloads/Divvy_${version}.zip";
  sha256 = "0lwsz0ci3akd3r178h7gisjbdydcp3yv31qafqkhwksyildc88r8";

  description = "Click-and-drag popup grid window manager";
  homepage = "https://mizage.com/divvy";
  maintainers = [ "spease" ];
  license = "unfree";
}
{ darwin }:

darwin.installApplication rec {
  pname = "f.lux";
  version = "41.5";

  url = "https://justgetflux.com/mac/Flux${version}.zip";
  sha256 = "/7aSsJu7MOjnDsionAdu3oygBqvTuZB2DJIYrmZ7DPs=";

  description = "Reddens computer screen in the evening";
  homepage = "https://justgetflux.com/";
  maintainers = [ "spease" ];
  license = "free";
}
{ darwin, lib }:

darwin.installApplication rec {
  pname = "mountain-duck";
  version = "4.9.0.18884";

  url = "https://dist.mountainduck.io/Mountain%20Duck-${version}.zip";
  sha256 = "l4eFm5CxqVCeJZ4B2rLx57y4tlB5gI/E+nvfH4Ql92I=";

  description = "Lets you mount network storage as a disk";
  homepage = "https://mountainduck.io/";
  license = "unfree";
  maintainers = [ "spease" ];
}
{ darwin }:

darwin.installApplication rec {
  pname="signal-desktop";
  version="5.24.0";

  url="https://updates.signal.org/desktop/signal-desktop-mac-${version}.dmg";
  sha256="XEmK8Z4wuzfWd6YU8sNsTmKE+JzwF0EwhoKMCCoGKCM=";

  description="Private, simple, and secure messenger";
  homepage="https://www.signal.org/";
  license="free";
  maintainers="spease";
}

@ofborg ofborg bot added the 6.topic: darwin Running or building packages on Darwin label Nov 27, 2021
@spease spease force-pushed the installApplication branch from c835d68 to 0a8c91e Compare November 27, 2021 05:13
@spease spease changed the title darwin.installApplication + unpkg + unxar darwin.installApplication + unpkg + unxar: init Nov 27, 2021
@ofborg ofborg bot added 8.has: package (new) This PR adds a new package 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Nov 27, 2021
Comment on lines +3 to +4
xar --dump-header -f "${curSrc}" | grep -q "^magic:\s\+[0-9a-z]\+\s\+(OK)$"
[ $? -ne 0 ] && return 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't set -e be set in the stdenv and this cleanly fail?


Suggested change
xar --dump-header -f "${curSrc}" | grep -q "^magic:\s\+[0-9a-z]\+\s\+(OK)$"
[ $? -ne 0 ] && return 1
xar --dump-header -f "${curSrc}" | grep -q "^magic:\s\+[0-9a-z]\+\s\+(OK)$"
ret=$?
[ $ret -ne 0 ] && return $ret

I think we should preserve the exit code.


installPhase = ''
mkdir -p $out/bin
ln -s $(command -v xar) $out/bin/xar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ln -s $(command -v xar) $out/bin/xar
ln -s ${xar}/bin/xar $out/bin/xar

dir="$(mktemp -d)"
xar -xf "${curSrc}" -C "${dir}"
zcat ${dir}/*/Payload | cpio -idm --no-absolute-filenames
rm -rf --preserve-root "${dir}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rm -rf --preserve-root "${dir}"
rm -rf "$dir"

This should be the default and also mktemp should never output /.


installPhase = ''
mkdir -p $out/bin
ln -s $(command -v xar) $out/bin/xar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ln -s $(command -v xar) $out/bin/xar
ln -s ${xar}/bin/xar $out/bin/xar

description = description;
homepage = homepage;
license = licenses."${license}";
maintainers = forEach maintainers (x: maintainers."${maintainer}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not how this is normally done. Normally meta is just inherited as is or the inputs override some defaults.

Comment on lines +15 to +16
phases = [ "unpackPhase" "installPhase" ];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
phases = [ "unpackPhase" "installPhase" ];

Please disable unwanted phases with dontBuild = true;.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 19, 2022
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 20, 2024
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 20, 2024
@wegank wegank marked this pull request as draft March 20, 2024 22:47
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 4, 2024
@afh
Copy link
Member

afh commented Jul 10, 2024

I started on something very similar, @spease, see #293498, I'll have a closer look on the changes proposed here. Depending on the details maybe there's a "best-of-both-worlds" solution? 🙂

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 10, 2024
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 1, 2025
app=( ./*.app )
if [ ! -z "$app" ]; then
mkdir -p $out/Applications
mv -n "$app" $out/Applications/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I read this bash correctly, then app=( ./*.app ) creates an array of all application bundles, while mv -n "$app" $out/Applications/ will move just the first one over to $out/Applications

@nixpkgs-ci nixpkgs-ci bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: darwin Running or building packages on Darwin 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants