Skip to content

brew bundle with masApps fails during nix-darwin activation — "Unable to install" even when apps are already installed #1221

@Shabashe

Description

@Shabashe

Configuration

mas ▁▁▁▁ 6.0.1
slice ▁▁ arm64
slices ▁ arm64
dist ▁▁▁ homebrew/core/mas
origin ▁ https://github.com/mas-cli/mas.git
swift ▁▁ 6.2.4 (swiftlang-6.2.4.1.4 clang-1700.6.4.2)
driver ▁ 1.127.15
store ▁▁ US
region ▁ US
macos ▁▁ 26.4 (25E246)
mac ▁▁▁▁ Macmini9,1
cpu ▁▁▁▁ Apple M1
arch ▁▁▁ arm64

Bug description

When using nix-darwin with the homebrew.masApps option, brew bundle is invoked during system activation (via sudo darwin-rebuild switch --flake ...). The masApps entries consistently fail with:

Error: Unable to install <AppName>. mas installation failed.

This happens even when the apps are already installed and up to date. Running mas install <id> directly in a user terminal works fine and correctly reports Warning: Already installed <AppName> (<id>).

Steps to reproduce

  1. Install nix-darwin with the nix-homebrew module
  2. Add masApps entries to the homebrew configuration in flake.nix:
homebrew = {
  enable = true;
  brews = [ "mas" ];
  masApps = {
    "Xcode" = 497799835;
    "Logic" = 634148309;
    "Final" = 424389933;
  };
};
  1. Run sudo darwin-rebuild switch --flake ~/.config/nix-darwin
  2. Observe the activation output:
Using cloudmounter
Using ipfs-desktop
Using betterdisplay
Using cameracontroller
Using vcam
Error: Unable to install Final app. mas installation failed.

The error appears for one or more of the masApps entries on every activation.

  1. Verify mas install works directly:
$ mas install 424389933
Warning: Already installed Final Cut Pro (424389933)

Expected behavior

brew bundle should succeed for masApps entries when the apps are already installed, similar to how mas install correctly handles this case when run directly.

Actual behavior

brew bundle reports mas installation failed during nix-darwin activation, even for already-installed apps.

Analysis

The likely cause is a session mismatch: nix-darwin runs brew bundle under sudo during system activation. The installd / App Store service requires the logged-in user's session context. When brew bundle invokes mas under sudo, the connection to the installation service fails because the root session cannot talk to the user-session installd.

Running mas install directly in a user terminal (same user, same session) works without issue.

Workaround

Comment out masApps in the nix-darwin flake and manage Mac App Store apps manually via the App Store or by running mas install directly. The cleanup = "zap" option in nix-darwin's homebrew module only affects brews, casks, and taps — it does not uninstall MAS apps.

Possibly related

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions