diff --git a/modules/homebrew.nix b/modules/homebrew.nix
index a0c97a9..2a130f0 100644
--- a/modules/homebrew.nix
+++ b/modules/homebrew.nix
@@ -1,5 +1,5 @@
# Created by: https://github.com/malob
-{ config, lib, pkgs, ... }:
+{ config, lib, options, pkgs, ... }:
with lib;
@@ -8,13 +8,6 @@ let
brewfileFile = pkgs.writeText "Brewfile" cfg.brewfile;
- brew-bundle-command = concatStringsSep " " (
- optional (!cfg.autoUpdate) "HOMEBREW_NO_AUTO_UPDATE=1"
- ++ [ "brew bundle --file='${brewfileFile}' --no-lock" ]
- ++ optional (cfg.cleanup == "uninstall" || cfg.cleanup == "zap") "--cleanup"
- ++ optional (cfg.cleanup == "zap") "--zap"
- );
-
# Brewfile creation helper functions -------------------------------------------------------------
mkBrewfileSectionString = heading: entries: optionalString (entries != [ ]) ''
@@ -67,6 +60,75 @@ let
# * lib/bundle/{brew,cask,tap}_installer.rb
# * spec/bundle/{brew,cask,tap}_installer_spec.rb
+ onActivationOptions = { config, ... }: {
+ options = {
+ cleanup = mkOption {
+ type = types.enum [ "none" "uninstall" "zap" ];
+ default = "none";
+ example = "uninstall";
+ description = ''
+ This option manages what happens to formulae installed by Homebrew, that aren't present in
+ the Brewfile generated by this module, during nix-darwin activation.
+
+ When set to "none" (the default), formulae not present in the generated
+ Brewfile are left installed.
+
+ When set to "uninstall", nix-darwin invokes
+ brew bundle [install] with the --cleanup flag. This
+ uninstalls all formulae not listed in generate Brewfile, i.e.,
+ brew uninstall is run for those formulae.
+
+ When set to "zap", nix-darwin invokes
+ brew bundle [install] with the --cleanup --zap
+ flags. This uninstalls all formulae not listed in the generated Brewfile, and if the
+ formula is a cask, removes all files associated with that cask. In other words,
+ brew uninstall --zap is run for all those formulae.
+
+ If you plan on exclusively using nix-darwin to manage formulae
+ installed by Homebrew, you probably want to set this option to
+ "uninstall" or "zap".
+ '';
+ };
+ autoUpdate = mkOption {
+ type = types.bool;
+ default = false;
+ description = ''
+ Whether to enable Homebrew to auto-update itself and all formulae during
+ nix-darwin activation. The default is false so that
+ repeated invocations of darwin-rebuild switch are idempotent.
+
+ Note that Homebrew auto-updates when it's been more then 5 minutes since it last updated.
+ '';
+ };
+ upgrade = mkOption {
+ type = types.bool;
+ default = false;
+ description = ''
+ Whether to enable Homebrew to upgrade outdated formulae and Mac App Store apps during
+ nix-darwin activation. The default is false so
+ that repeated invocations of darwin-rebuild switch are idempotent.
+ '';
+ };
+
+ brewBundleCmd = mkOption {
+ type = types.str;
+ visible = false;
+ internal = true;
+ readOnly = true;
+ };
+ };
+
+ config = {
+ brewBundleCmd = concatStringsSep " " (
+ optional (!config.autoUpdate) "HOMEBREW_NO_AUTO_UPDATE=1"
+ ++ [ "brew bundle --file='${brewfileFile}' --no-lock" ]
+ ++ optional (!config.upgrade) "--no-upgrade"
+ ++ optional (config.cleanup == "uninstall") "--cleanup"
+ ++ optional (config.cleanup == "zap") "--cleanup --zap"
+ );
+ };
+ };
+
tapOptions = { config, ... }: {
options = {
name = mkOption {
@@ -350,25 +412,20 @@ in
{
# Interface --------------------------------------------------------------------------------------
+ imports = [
+ (mkRenamedOptionModule [ "homebrew" "autoUpdate" ] [ "homebrew" "onActivation" "autoUpdate" ])
+ (mkRenamedOptionModule [ "homebrew" "cleanup" ] [ "homebrew" "onActivation" "cleanup" ])
+ ];
+
options.homebrew = {
enable = mkEnableOption ''
- configuring your Brewfile, and installing/updating the formulas therein via
+ configuring your Brewfile, and installing/updating the formulae therein via
the brew bundle command, using nix-darwin.
Note that enabling this option does not install Homebrew. See the Homebrew
website for installation instructions
'';
- autoUpdate = mkOption {
- type = types.bool;
- default = false;
- description = ''
- Whether to enable Homebrew to auto-update during nix-darwin
- activation. The default is false so that repeated invocations of
- darwin-rebuild switch are idempotent.
- '';
- };
-
brewPrefix = mkOption {
type = types.str;
default = if pkgs.stdenv.hostPlatform.isAarch64 then "/opt/homebrew/bin" else "/usr/local/bin";
@@ -383,31 +440,12 @@ in
'';
};
- cleanup = mkOption {
- type = types.enum [ "none" "uninstall" "zap" ];
- default = "none";
- example = "uninstall";
+ onActivation = mkOption {
+ type = types.submodule onActivationOptions;
+ default = { };
description = ''
- This option manages what happens to formulas installed by Homebrew, that aren't present in
- the Brewfile generated by this module.
-
- When set to "none" (the default), formulas not present in the generated
- Brewfile are left installed.
-
- When set to "uninstall", nix-darwin invokes
- brew bundle [install] with the --cleanup flag. This
- uninstalls all formulas not listed in generate Brewfile, i.e.,
- brew uninstall is run for those formulas.
-
- When set to "zap", nix-darwin invokes
- brew bundle [install] with the --cleanup --zap
- flags. This uninstalls all formulas not listed in the generated Brewfile, and if the
- formula is a cask, removes all files associated with that cask. In other words,
- brew uninstall --zap is run for all those formulas.
-
- If you plan on exclusively using nix-darwin to manage formulas installed
- by Homebrew, you probably want to set this option to "uninstall" or
- "zap".
+ Options for configuring the behavior of the brew bundle command that
+ nix-darwin runs during system activation.
'';
};
@@ -562,7 +600,7 @@ in
Note that you need to be signed into the Mac App Store for mas to
successfully install and upgrade applications, and that unfortunately apps removed from this
option will not be uninstalled automatically even if
- is set to "uninstall"
+ is set to "uninstall"
or "zap" (this is currently a limitation of Homebrew Bundle).
For more information on mas see:
@@ -608,6 +646,11 @@ in
# Implementation ---------------------------------------------------------------------------------
config = {
+
+ warnings = [
+ (mkIf (options.homebrew.autoUpdate.isDefined || options.homebrew.cleanup.isDefined) "The `homebrew' module no longer upgrades outdated formulae and apps by default during `nix-darwin' activation. To enable upgrading, set `homebrew.onActivation.upgrade = true'.")
+ ];
+
homebrew.brews =
optional (cfg.masApps != { }) "mas"
++ optional (cfg.whalebrews != [ ]) "whalebrew";
@@ -633,7 +676,7 @@ in
# Homebrew Bundle
echo >&2 "Homebrew bundle..."
if [ -f "${cfg.brewPrefix}/brew" ]; then
- PATH="${cfg.brewPrefix}":$PATH ${brew-bundle-command}
+ PATH="${cfg.brewPrefix}":$PATH ${cfg.onActivation.brewBundleCmd}
else
echo -e "\e[1;31merror: Homebrew is not installed, skipping...\e[0m" >&2
fi