mirror of
https://github.com/LnL7/nix-darwin.git
synced 2024-12-15 17:51:01 +00:00
Create submodule for activation related homebrew
options
* Adds `homebrew.onActivation` submodule. * Moves `homebrew.autoUpdate` to `homebrew.onActivation.autoUpdate`. * Moves `homebrew.cleanup` to `homebrew.onActivation.clean`. * Adds new option `homebrew.onActivation.upgrade`.
This commit is contained in:
parent
55e198cf5a
commit
b547a7acb0
1 changed files with 88 additions and 45 deletions
|
@ -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 <command>nix-darwin</command> activation.
|
||||
|
||||
When set to <literal>"none"</literal> (the default), formulae not present in the generated
|
||||
Brewfile are left installed.
|
||||
|
||||
When set to <literal>"uninstall"</literal>, <command>nix-darwin</command> invokes
|
||||
<command>brew bundle [install]</command> with the <command>--cleanup</command> flag. This
|
||||
uninstalls all formulae not listed in generate Brewfile, i.e.,
|
||||
<command>brew uninstall</command> is run for those formulae.
|
||||
|
||||
When set to <literal>"zap"</literal>, <command>nix-darwin</command> invokes
|
||||
<command>brew bundle [install]</command> with the <command>--cleanup --zap</command>
|
||||
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,
|
||||
<command>brew uninstall --zap</command> is run for all those formulae.
|
||||
|
||||
If you plan on exclusively using <command>nix-darwin</command> to manage formulae
|
||||
installed by Homebrew, you probably want to set this option to
|
||||
<literal>"uninstall"</literal> or <literal>"zap"</literal>.
|
||||
'';
|
||||
};
|
||||
autoUpdate = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to enable Homebrew to auto-update itself and all formulae during
|
||||
<command>nix-darwin</command> activation. The default is <literal>false</literal> so that
|
||||
repeated invocations of <command>darwin-rebuild switch</command> 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
|
||||
<command>nix-darwin</command> activation. The default is <literal>false</literal> so
|
||||
that repeated invocations of <command>darwin-rebuild switch</command> 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 <command>brew bundle</command> command, using <command>nix-darwin</command>.
|
||||
|
||||
Note that enabling this option does not install Homebrew. See the Homebrew
|
||||
<link xlink:href="https://brew.sh">website</link> for installation instructions
|
||||
'';
|
||||
|
||||
autoUpdate = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to enable Homebrew to auto-update during <command>nix-darwin</command>
|
||||
activation. The default is <literal>false</literal> so that repeated invocations of
|
||||
<command>darwin-rebuild switch</command> 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 <literal>"none"</literal> (the default), formulas not present in the generated
|
||||
Brewfile are left installed.
|
||||
|
||||
When set to <literal>"uninstall"</literal>, <command>nix-darwin</command> invokes
|
||||
<command>brew bundle [install]</command> with the <command>--cleanup</command> flag. This
|
||||
uninstalls all formulas not listed in generate Brewfile, i.e.,
|
||||
<command>brew uninstall</command> is run for those formulas.
|
||||
|
||||
When set to <literal>"zap"</literal>, <command>nix-darwin</command> invokes
|
||||
<command>brew bundle [install]</command> with the <command>--cleanup --zap</command>
|
||||
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,
|
||||
<command>brew uninstall --zap</command> is run for all those formulas.
|
||||
|
||||
If you plan on exclusively using <command>nix-darwin</command> to manage formulas installed
|
||||
by Homebrew, you probably want to set this option to <literal>"uninstall"</literal> or
|
||||
<literal>"zap"</literal>.
|
||||
Options for configuring the behavior of the <command>brew bundle</command> command that
|
||||
<command>nix-darwin</command> runs during system activation.
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -562,7 +600,7 @@ in
|
|||
Note that you need to be signed into the Mac App Store for <command>mas</command> to
|
||||
successfully install and upgrade applications, and that unfortunately apps removed from this
|
||||
option will not be uninstalled automatically even if
|
||||
<option>homebrew.cleanup</option> is set to <literal>"uninstall"</literal>
|
||||
<option>homebrew.onActivation.cleanup</option> is set to <literal>"uninstall"</literal>
|
||||
or <literal>"zap"</literal> (this is currently a limitation of Homebrew Bundle).
|
||||
|
||||
For more information on <command>mas</command> 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
|
||||
|
|
Loading…
Reference in a new issue