Skip to content

Commit

Permalink
Support nix-darwin system-wide activation
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaofengli committed Mar 3, 2025
1 parent a82c55b commit 96b4688
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@
# that automatically selects the correct prefix based on the architecture.
# Use `arch -x86_64 brew` to install X86-64 packages.

{ pkgs, lib, config, ... }:
{ pkgs, lib, config, options, ... }:
let
inherit (lib) types;

# When this file exists under $HOMEBREW_PREFIX or a specific
# tap, it means it's managed by us.
nixMarker = ".managed_by_nix_darwin";

# nix-darwin is migrating away from user activation in
# <https://github.com/LnL7/nix-darwin/pull/1341>.
# Before this PR, nix-darwin's homebrew activation was run as part
# of user activation (system.activationScripts.userScript) which is
# removed.
hasSystemWideActivation = options.system ? primaryUser;

cfg = config.nix-homebrew;

tools = pkgs.callPackage ../pkgs { };
Expand Down Expand Up @@ -493,11 +500,14 @@ in {

environment.systemPackages = [ brewLauncher ];
system.activationScripts = {
# We set up a new system activation step that sets up Homebrew
extraUserActivation.text = lib.mkAfter ''
# Set up the Homebrew prefixes before nix-darwin's homebrew
# activation takes place.
homebrew.text = lib.mkBefore ''
${config.system.activationScripts.setup-homebrew.text}
'';
setup-homebrew.text = ''
setup-homebrew.text = if hasSystemWideActivation then ''
${setupHomebrew}
'' else ''
sudo ${setupHomebrew}
'';
};
Expand Down

0 comments on commit 96b4688

Please sign in to comment.