2020-12-08 02:14:48 +00:00
|
|
|
|
# Created by: https://github.com/malob
|
2022-08-24 20:07:19 +00:00
|
|
|
|
{ config, lib, options, pkgs, ... }:
|
2020-12-08 02:14:48 +00:00
|
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
|
|
let
|
2020-12-17 21:03:57 +00:00
|
|
|
|
cfg = config.homebrew;
|
2020-12-08 02:14:48 +00:00
|
|
|
|
|
2022-08-23 20:32:07 +00:00
|
|
|
|
brewfileFile = pkgs.writeText "Brewfile" cfg.brewfile;
|
2022-08-23 01:10:46 +00:00
|
|
|
|
|
2022-08-23 20:32:07 +00:00
|
|
|
|
# Brewfile creation helper functions -------------------------------------------------------------
|
2020-12-08 02:14:48 +00:00
|
|
|
|
|
2022-08-23 20:32:07 +00:00
|
|
|
|
mkBrewfileSectionString = heading: entries: optionalString (entries != [ ]) ''
|
|
|
|
|
# ${heading}
|
|
|
|
|
${concatMapStringsSep "\n" (v: v.brewfileLine or v) entries}
|
|
|
|
|
|
|
|
|
|
'';
|
2022-08-22 21:49:22 +00:00
|
|
|
|
|
|
|
|
|
mkBrewfileLineValueString = v:
|
|
|
|
|
if isInt v then toString v
|
|
|
|
|
else if isFloat v then strings.floatToString v
|
|
|
|
|
else if isBool v then boolToString v
|
|
|
|
|
else if isString v then ''"${v}"''
|
|
|
|
|
else if isAttrs v then "{ ${concatStringsSep ", " (mapAttrsToList (n: v': "${n}: ${mkBrewfileLineValueString v'}") v)} }"
|
|
|
|
|
else if isList v then "[${concatMapStringsSep ", " mkBrewfileLineValueString v}]"
|
|
|
|
|
else abort "The value: ${generators.toPretty v} is not a valid Brewfile value.";
|
|
|
|
|
|
|
|
|
|
mkBrewfileLineOptionsListString = attrs:
|
2022-08-23 20:32:07 +00:00
|
|
|
|
concatStringsSep ", " (mapAttrsToList (n: v: "${n}: ${v}") attrs);
|
|
|
|
|
|
|
|
|
|
|
2022-08-25 00:26:50 +00:00
|
|
|
|
# Option and submodule helper functions ----------------------------------------------------------
|
|
|
|
|
|
2022-08-22 21:49:22 +00:00
|
|
|
|
mkNullOrBoolOption = args: mkOption (args // {
|
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
|
default = null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mkNullOrStrOption = args: mkOption (args // {
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
|
|
|
|
});
|
|
|
|
|
|
2022-08-25 00:26:50 +00:00
|
|
|
|
mkInternalOption = args: mkOption (args // {
|
2022-08-23 01:10:46 +00:00
|
|
|
|
visible = false;
|
|
|
|
|
internal = true;
|
|
|
|
|
readOnly = true;
|
2022-08-25 00:26:50 +00:00
|
|
|
|
});
|
2022-08-23 01:10:46 +00:00
|
|
|
|
|
2022-08-23 20:32:07 +00:00
|
|
|
|
mkProcessedSubmodConfig = attrs: mapAttrs (_: mkBrewfileLineValueString)
|
|
|
|
|
(filterAttrsRecursive (n: v: n != "_module" && n != "brewfileLine" && v != null) attrs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Submodules -------------------------------------------------------------------------------------
|
|
|
|
|
# Option values and descriptions of Brewfile entries are sourced/derived from:
|
|
|
|
|
# * `brew` manpage: https://docs.brew.sh/Manpage
|
|
|
|
|
# * `brew bundle` source files (at https://github.com/Homebrew/homebrew-bundle/tree/9fffe077f1a5a722ed5bd26a87ed622e8cb64e0c):
|
|
|
|
|
# * lib/bundle/dsl.rb
|
|
|
|
|
# * lib/bundle/{brew,cask,tap}_installer.rb
|
|
|
|
|
# * spec/bundle/{brew,cask,tap}_installer_spec.rb
|
|
|
|
|
|
2022-08-24 20:07:19 +00:00
|
|
|
|
onActivationOptions = { config, ... }: {
|
|
|
|
|
options = {
|
|
|
|
|
cleanup = mkOption {
|
|
|
|
|
type = types.enum [ "none" "uninstall" "zap" ];
|
|
|
|
|
default = "none";
|
|
|
|
|
example = "uninstall";
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-24 20:07:19 +00:00
|
|
|
|
This option manages what happens to formulae installed by Homebrew, that aren't present in
|
2023-06-22 11:21:32 +00:00
|
|
|
|
the Brewfile generated by this module, during {command}`nix-darwin` system
|
2022-08-25 00:35:42 +00:00
|
|
|
|
activation.
|
2022-08-24 20:07:19 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
When set to `"none"` (the default), formulae not present in the generated
|
2022-08-24 20:07:19 +00:00
|
|
|
|
Brewfile are left installed.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
When set to `"uninstall"`, {command}`nix-darwin` invokes
|
|
|
|
|
{command}`brew bundle [install]` with the {command}`--cleanup` flag. This
|
2022-08-25 00:35:42 +00:00
|
|
|
|
uninstalls all formulae not listed in generated Brewfile, i.e.,
|
2023-06-22 11:21:32 +00:00
|
|
|
|
{command}`brew uninstall` is run for those formulae.
|
2022-08-24 20:07:19 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
When set to `"zap"`, {command}`nix-darwin` invokes
|
|
|
|
|
{command}`brew bundle [install]` with the {command}`--cleanup --zap`
|
2022-08-24 20:07:19 +00:00
|
|
|
|
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,
|
2023-06-22 11:21:32 +00:00
|
|
|
|
{command}`brew uninstall --zap` is run for all those formulae.
|
2022-08-24 20:07:19 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
If you plan on exclusively using {command}`nix-darwin` to manage formulae
|
2022-08-24 20:07:19 +00:00
|
|
|
|
installed by Homebrew, you probably want to set this option to
|
2023-06-22 11:21:32 +00:00
|
|
|
|
`"uninstall"` or `"zap"`.
|
2022-08-24 20:07:19 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
autoUpdate = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-24 20:07:19 +00:00
|
|
|
|
Whether to enable Homebrew to auto-update itself and all formulae during
|
2023-06-22 11:21:32 +00:00
|
|
|
|
{command}`nix-darwin` system activation. The default is `false`
|
|
|
|
|
so that repeated invocations of {command}`darwin-rebuild switch` are idempotent.
|
2022-08-24 20:07:19 +00:00
|
|
|
|
|
|
|
|
|
Note that Homebrew auto-updates when it's been more then 5 minutes since it last updated.
|
2022-08-25 00:35:42 +00:00
|
|
|
|
|
|
|
|
|
Although auto-updating is disabled by default during system activation, note that Homebrew
|
|
|
|
|
will auto-update when you manually invoke certain Homebrew commands. To modify this
|
2023-06-22 11:21:32 +00:00
|
|
|
|
behavior see [](#opt-homebrew.global.autoUpdate).
|
2023-09-11 17:58:08 +00:00
|
|
|
|
|
|
|
|
|
Implementation note: when disabled, this option sets the `HOMEBREW_NO_AUTO_UPDATE`
|
|
|
|
|
environment variable when {command}`nix-darwin` invokes {command}`brew bundle [install]`
|
|
|
|
|
during system activation.
|
2022-08-24 20:07:19 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
upgrade = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-24 20:07:19 +00:00
|
|
|
|
Whether to enable Homebrew to upgrade outdated formulae and Mac App Store apps during
|
2023-06-22 11:21:32 +00:00
|
|
|
|
{command}`nix-darwin` system activation. The default is `false`
|
|
|
|
|
so that repeated invocations of {command}`darwin-rebuild switch` are idempotent.
|
2023-09-11 17:58:08 +00:00
|
|
|
|
|
|
|
|
|
Implementation note: when disabled, {command}`nix-darwin` invokes
|
|
|
|
|
{command}`brew bundle [install]` with the {command}`--no-upgrade` flag during system
|
|
|
|
|
activation.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
extraFlags = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
default = [ ];
|
|
|
|
|
example = [ "--verbose" ];
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2023-09-11 17:58:08 +00:00
|
|
|
|
Extra flags to pass to {command}`brew bundle [install]` during {command}`nix-darwin`
|
|
|
|
|
system activation.
|
2022-08-24 20:07:19 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-25 00:26:50 +00:00
|
|
|
|
brewBundleCmd = mkInternalOption { type = types.str; };
|
2022-08-24 20:07:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
brewBundleCmd = concatStringsSep " " (
|
|
|
|
|
optional (!config.autoUpdate) "HOMEBREW_NO_AUTO_UPDATE=1"
|
2023-09-11 17:58:08 +00:00
|
|
|
|
++ [ "brew bundle --file='${brewfileFile}' --no-lock" ]
|
2022-08-24 20:07:19 +00:00
|
|
|
|
++ optional (!config.upgrade) "--no-upgrade"
|
|
|
|
|
++ optional (config.cleanup == "uninstall") "--cleanup"
|
|
|
|
|
++ optional (config.cleanup == "zap") "--cleanup --zap"
|
2023-09-11 17:58:08 +00:00
|
|
|
|
++ config.extraFlags
|
2022-08-24 20:07:19 +00:00
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-25 00:26:50 +00:00
|
|
|
|
globalOptions = { config, ... }: {
|
|
|
|
|
options = {
|
|
|
|
|
brewfile = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-25 00:26:50 +00:00
|
|
|
|
Whether to enable Homebrew to automatically use the Brewfile that this module generates in
|
2023-06-22 11:21:32 +00:00
|
|
|
|
the Nix store, when you manually invoke {command}`brew bundle`.
|
2022-08-25 00:26:50 +00:00
|
|
|
|
|
|
|
|
|
Enabling this option will change the default value of
|
2023-06-22 11:21:32 +00:00
|
|
|
|
[](#opt-homebrew.global.lockfiles) to `false` since, with
|
|
|
|
|
this option enabled, {command}`brew bundle [install]` will default to using the
|
2022-08-25 00:26:50 +00:00
|
|
|
|
Brewfile that this module generates in the Nix store, unless you explicitly point it at
|
2023-06-22 11:21:32 +00:00
|
|
|
|
another Brewfile using the `--file` flag. As a result, it will try to
|
2022-08-25 00:26:50 +00:00
|
|
|
|
write the lockfile in the Nix store, and complain that it can't (though the command will
|
|
|
|
|
run successfully regardless).
|
|
|
|
|
|
|
|
|
|
Implementation note: when enabled, this option sets the
|
2023-06-22 11:21:32 +00:00
|
|
|
|
`HOMEBREW_BUNDLE_FILE` environment variable to the path of the Brewfile
|
2022-08-25 00:26:50 +00:00
|
|
|
|
that this module generates in the Nix store, by adding it to
|
2023-06-22 11:21:32 +00:00
|
|
|
|
[](#opt-environment.variables).
|
2022-08-25 00:26:50 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
autoUpdate = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-25 00:26:50 +00:00
|
|
|
|
Whether to enable Homebrew to auto-update itself and all formulae when you manually invoke
|
2023-06-22 11:21:32 +00:00
|
|
|
|
commands like {command}`brew install`, {command}`brew upgrade`,
|
|
|
|
|
{command}`brew tap`, and {command}`brew bundle [install]`.
|
2022-08-25 00:26:50 +00:00
|
|
|
|
|
|
|
|
|
Note that Homebrew auto-updates when you manually invoke commands like the ones mentioned
|
|
|
|
|
above if it's been more then 5 minutes since it last updated.
|
|
|
|
|
|
|
|
|
|
You may want to consider disabling this option if you have
|
2023-06-22 11:21:32 +00:00
|
|
|
|
[](#opt-homebrew.onActivation.upgrade) enabled, and
|
|
|
|
|
[](#opt-homebrew.onActivation.autoUpdate) disabled, if you want to ensure that
|
|
|
|
|
your installed formulae will only be upgraded during {command}`nix-darwin` system
|
|
|
|
|
activation, after you've explicitly run {command}`brew update`.
|
2022-08-25 00:26:50 +00:00
|
|
|
|
|
|
|
|
|
Implementation note: when disabled, this option sets the
|
2023-06-22 11:21:32 +00:00
|
|
|
|
`HOMEBREW_NO_AUTO_UPDATE` environment variable, by adding it to
|
|
|
|
|
[](#opt-environment.variables).
|
2022-08-25 00:26:50 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
lockfiles = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = !config.brewfile;
|
|
|
|
|
defaultText = literalExpression "!config.homebrew.global.brewfile";
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-25 00:26:50 +00:00
|
|
|
|
Whether to enable Homebrew to generate lockfiles when you manually invoke
|
2023-06-22 11:21:32 +00:00
|
|
|
|
{command}`brew bundle [install]`.
|
2022-08-25 00:26:50 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
This option will default to `false` if
|
|
|
|
|
[](#opt-homebrew.global.brewfile) is enabled since, with that option enabled,
|
|
|
|
|
{command}`brew bundle [install]` will default to using the Brewfile that this
|
2022-08-25 00:26:50 +00:00
|
|
|
|
module generates in the Nix store, unless you explicitly point it at another Brewfile
|
2023-06-22 11:21:32 +00:00
|
|
|
|
using the `--file` flag. As a result, it will try to write the
|
2022-08-25 00:26:50 +00:00
|
|
|
|
lockfile in the Nix store, and complain that it can't (though the command will run
|
|
|
|
|
successfully regardless).
|
|
|
|
|
|
|
|
|
|
Implementation note: when disabled, this option sets the
|
2023-06-22 11:21:32 +00:00
|
|
|
|
`HOMEBREW_BUNDLE_NO_LOCK` environment variable, by adding it to
|
|
|
|
|
[](#opt-environment.variables).
|
2022-08-25 00:26:50 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# The `noLock` option was replaced by `lockfiles`. Due to `homebrew.global` being a submodule,
|
|
|
|
|
# we can't use `mkRemovedOptionModule`, so we leave this option definition here, and trigger
|
|
|
|
|
# and error message with an assertion below if it's set by the user.
|
|
|
|
|
noLock = mkOption { visible = false; default = null; };
|
|
|
|
|
|
|
|
|
|
homebrewEnvironmentVariables = mkInternalOption { type = types.attrs; };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
homebrewEnvironmentVariables = {
|
|
|
|
|
HOMEBREW_BUNDLE_FILE = mkIf config.brewfile "${brewfileFile}";
|
|
|
|
|
HOMEBREW_NO_AUTO_UPDATE = mkIf (!config.autoUpdate) "1";
|
|
|
|
|
HOMEBREW_BUNDLE_NO_LOCK = mkIf (!config.lockfiles) "1";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-23 01:10:46 +00:00
|
|
|
|
tapOptions = { config, ... }: {
|
|
|
|
|
options = {
|
|
|
|
|
name = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
example = "homebrew/cask-fonts";
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2023-06-22 11:21:32 +00:00
|
|
|
|
When {option}`clone_target` is unspecified, this is the name of a formula
|
|
|
|
|
repository to tap from GitHub using HTTPS. For example, `"user/repo"`
|
2022-08-23 20:32:07 +00:00
|
|
|
|
will tap https://github.com/user/homebrew-repo.
|
2022-08-23 01:10:46 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
clone_target = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 01:10:46 +00:00
|
|
|
|
Use this option to tap a formula repository from anywhere, using any transport protocol
|
2023-06-22 11:21:32 +00:00
|
|
|
|
that {command}`git` handles. When {option}`clone_target` is specified, taps
|
2022-08-23 01:10:46 +00:00
|
|
|
|
can be cloned from places other than GitHub and using protocols other than HTTPS, e.g.,
|
|
|
|
|
SSH, git, HTTP, FTP(S), rsync.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
force_auto_update = mkNullOrBoolOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 01:10:46 +00:00
|
|
|
|
Whether to auto-update the tap even if it is not hosted on GitHub. By default, only taps
|
|
|
|
|
hosted on GitHub are auto-updated (for performance reasons).
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-25 00:26:50 +00:00
|
|
|
|
brewfileLine = mkInternalOption { type = types.nullOr types.str; };
|
2022-08-23 01:10:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-08-23 20:32:07 +00:00
|
|
|
|
config =
|
|
|
|
|
let
|
|
|
|
|
sCfg = mkProcessedSubmodConfig config;
|
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
brewfileLine =
|
|
|
|
|
"tap ${sCfg.name}"
|
|
|
|
|
+ optionalString (sCfg ? clone_target) ", ${sCfg.clone_target}"
|
|
|
|
|
+ optionalString (sCfg ? force_auto_update)
|
|
|
|
|
", force_auto_update: ${sCfg.force_auto_update}";
|
|
|
|
|
};
|
2022-08-23 01:10:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-08-22 21:49:22 +00:00
|
|
|
|
# Sourced from https://docs.brew.sh/Manpage#global-cask-options
|
|
|
|
|
# and valid values for `HOMEBREW_CASK_OPTS`.
|
|
|
|
|
caskArgsOptions = { config, ... }: {
|
|
|
|
|
options = {
|
|
|
|
|
appdir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for Applications.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`/Applications`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
colorpickerdir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for Color Pickers.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`~/Library/ColorPickers`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
prefpanedir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for Preference Panes.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`~/Library/PreferencePanes`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
qlplugindir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for QuickLook Plugins.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`~/Library/QuickLook`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
mdimporterdir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for Spotlight Plugins.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`~/Library/Spotlight`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
dictionarydir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for Dictionaries.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`~/Library/Dictionaries`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
fontdir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for Fonts.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`~/Library/Fonts`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
servicedir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for Services.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`~/Library/Services`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
input_methoddir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for Input Methods.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`~/Library/Input Methods`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
internet_plugindir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for Internet Plugins.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`~/Library/Internet Plug-Ins`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
audio_unit_plugindir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for Audio Unit Plugins.
|
|
|
|
|
|
2022-08-25 00:35:42 +00:00
|
|
|
|
Homebrew's default is
|
2023-06-22 11:21:32 +00:00
|
|
|
|
{file}`~/Library/Audio/Plug-Ins/Components`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
vst_plugindir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for VST Plugins.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`~/Library/Audio/Plug-Ins/VST`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
vst3_plugindir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for VST3 Plugins.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`~/Library/Audio/Plug-Ins/VST3`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
screen_saverdir = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 20:32:07 +00:00
|
|
|
|
Target location for Screen Savers.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is {file}`~/Library/Screen Savers`.
|
2022-08-22 21:49:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
language = mkNullOrStrOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-22 21:49:22 +00:00
|
|
|
|
Comma-separated list of language codes to prefer for cask installation. The first matching
|
|
|
|
|
language is used, otherwise it reverts to the cask’s default language. The default value
|
|
|
|
|
is the language of your system.
|
|
|
|
|
'';
|
|
|
|
|
example = "zh-TW";
|
|
|
|
|
};
|
|
|
|
|
require_sha = mkNullOrBoolOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-25 00:35:42 +00:00
|
|
|
|
Whether to require cask(s) to have a checksum.
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is `false`.
|
2022-08-25 00:35:42 +00:00
|
|
|
|
'';
|
2022-08-22 21:49:22 +00:00
|
|
|
|
};
|
|
|
|
|
no_quarantine = mkNullOrBoolOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = "Whether to disable quarantining of downloads.";
|
2022-08-22 21:49:22 +00:00
|
|
|
|
};
|
|
|
|
|
no_binaries = mkNullOrBoolOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = "Whether to disable linking of helper executables.";
|
2022-08-22 21:49:22 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-08-25 00:26:50 +00:00
|
|
|
|
brewfileLine = mkInternalOption { type = types.nullOr types.str; };
|
2022-08-22 21:49:22 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config =
|
|
|
|
|
let
|
2022-08-23 20:32:07 +00:00
|
|
|
|
sCfg = mkProcessedSubmodConfig config;
|
2022-08-22 21:49:22 +00:00
|
|
|
|
in
|
|
|
|
|
{
|
2022-08-25 00:26:50 +00:00
|
|
|
|
brewfileLine =
|
|
|
|
|
if sCfg == { } then null
|
|
|
|
|
else "cask_args ${mkBrewfileLineOptionsListString sCfg}";
|
2022-08-22 21:49:22 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
2022-08-23 02:35:01 +00:00
|
|
|
|
|
|
|
|
|
brewOptions = { config, ... }: {
|
|
|
|
|
options = {
|
|
|
|
|
name = mkOption {
|
|
|
|
|
type = types.str;
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = "The name of the formula to install.";
|
2022-08-23 02:35:01 +00:00
|
|
|
|
};
|
|
|
|
|
args = mkOption {
|
|
|
|
|
type = with types; nullOr (listOf str);
|
|
|
|
|
default = null;
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Arguments flags to pass to {command}`brew install`. Values should not include the
|
|
|
|
|
leading `"--"`.
|
2022-08-23 02:35:01 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
conflicts_with = mkOption {
|
|
|
|
|
type = with types; nullOr (listOf str);
|
|
|
|
|
default = null;
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 02:35:01 +00:00
|
|
|
|
List of formulae that should be unlinked and their services stopped (if they are
|
|
|
|
|
installed).
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
restart_service = mkOption {
|
|
|
|
|
type = with types; nullOr (either bool (enum [ "changed" ]));
|
|
|
|
|
default = null;
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Whether to run {command}`brew services restart` for the formula and register it to
|
|
|
|
|
launch at login (or boot). If set to `"changed"`, the service will only
|
2022-08-23 20:32:07 +00:00
|
|
|
|
be restarted on version changes.
|
2022-08-23 02:35:01 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is `false`.
|
2022-08-23 02:35:01 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
start_service = mkNullOrBoolOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Whether to run {command}`brew services start` for the formula and register it to
|
2022-08-23 02:35:01 +00:00
|
|
|
|
launch at login (or boot).
|
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Homebrew's default is `false`.
|
2022-08-23 02:35:01 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
link = mkNullOrBoolOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-23 02:35:01 +00:00
|
|
|
|
Whether to link the formula to the Homebrew prefix. When this option is
|
2023-06-22 11:21:32 +00:00
|
|
|
|
`null`, Homebrew will use it's default behavior which is to link the
|
2022-08-23 20:32:07 +00:00
|
|
|
|
formula if it's currently unlinked and not keg-only, and to unlink the formula if it's
|
2022-08-23 02:35:01 +00:00
|
|
|
|
currently linked and keg-only.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-25 00:26:50 +00:00
|
|
|
|
brewfileLine = mkInternalOption { type = types.nullOr types.str; };
|
2022-08-23 02:35:01 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config =
|
|
|
|
|
let
|
2022-08-23 20:32:07 +00:00
|
|
|
|
sCfg = mkProcessedSubmodConfig config;
|
|
|
|
|
sCfgSubset = removeAttrs sCfg [ "name" "restart_service" ];
|
2022-08-23 02:35:01 +00:00
|
|
|
|
in
|
|
|
|
|
{
|
2022-08-23 20:32:07 +00:00
|
|
|
|
brewfileLine =
|
|
|
|
|
"brew ${sCfg.name}"
|
|
|
|
|
+ optionalString (sCfgSubset != { }) ", ${mkBrewfileLineOptionsListString sCfgSubset}"
|
2022-08-25 00:35:42 +00:00
|
|
|
|
# We need to handle the `restart_service` option seperately since it can be either a bool
|
|
|
|
|
# or `:changed` in the Brewfile.
|
2022-08-23 20:32:07 +00:00
|
|
|
|
+ optionalString (sCfg ? restart_service) (
|
|
|
|
|
", restart_service: " + (
|
|
|
|
|
if isBool config.restart_service then sCfg.restart_service
|
|
|
|
|
else ":${config.restart_service}"
|
|
|
|
|
)
|
2022-08-23 02:35:01 +00:00
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
};
|
2022-08-23 03:04:09 +00:00
|
|
|
|
|
2022-08-23 20:32:07 +00:00
|
|
|
|
caskOptions = { config, ... }: {
|
2022-08-23 03:04:09 +00:00
|
|
|
|
options = {
|
|
|
|
|
name = mkOption {
|
|
|
|
|
type = types.str;
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = "The name of the cask to install.";
|
2022-08-23 03:04:09 +00:00
|
|
|
|
};
|
|
|
|
|
args = mkOption {
|
|
|
|
|
type = types.nullOr (types.submodule caskArgsOptions);
|
|
|
|
|
default = null;
|
2022-08-25 00:35:42 +00:00
|
|
|
|
visible = "shallow"; # so that options from `homebrew.caskArgs` aren't repeated.
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Arguments passed to {command}`brew install --cask` when installing this cask. See
|
|
|
|
|
[](#opt-homebrew.caskArgs) for the available options.
|
2022-08-25 00:35:42 +00:00
|
|
|
|
'';
|
2022-08-23 03:04:09 +00:00
|
|
|
|
};
|
|
|
|
|
greedy = mkNullOrBoolOption {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-25 00:35:42 +00:00
|
|
|
|
Whether to always upgrade this cask regardless of whether it's unversioned or it updates
|
|
|
|
|
itself.
|
2022-08-23 03:04:09 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-25 00:26:50 +00:00
|
|
|
|
brewfileLine = mkInternalOption { type = types.nullOr types.str; };
|
2022-08-23 03:04:09 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-08-23 20:32:07 +00:00
|
|
|
|
config =
|
|
|
|
|
let
|
|
|
|
|
sCfg = mkProcessedSubmodConfig config;
|
|
|
|
|
sCfgSubset = removeAttrs sCfg [ "name" ];
|
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
brewfileLine =
|
|
|
|
|
"cask ${sCfg.name}"
|
|
|
|
|
+ optionalString (sCfgSubset != { }) ", ${mkBrewfileLineOptionsListString sCfgSubset}";
|
|
|
|
|
};
|
2022-08-23 03:04:09 +00:00
|
|
|
|
};
|
2020-12-08 02:14:48 +00:00
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
{
|
2022-08-23 20:32:07 +00:00
|
|
|
|
# Interface --------------------------------------------------------------------------------------
|
|
|
|
|
|
2022-08-24 20:07:19 +00:00
|
|
|
|
imports = [
|
|
|
|
|
(mkRenamedOptionModule [ "homebrew" "autoUpdate" ] [ "homebrew" "onActivation" "autoUpdate" ])
|
|
|
|
|
(mkRenamedOptionModule [ "homebrew" "cleanup" ] [ "homebrew" "onActivation" "cleanup" ])
|
|
|
|
|
];
|
|
|
|
|
|
2020-12-17 21:03:57 +00:00
|
|
|
|
options.homebrew = {
|
2024-04-14 21:02:32 +00:00
|
|
|
|
enable = mkEnableOption ''
|
2023-06-22 11:21:32 +00:00
|
|
|
|
{command}`nix-darwin` to manage installing/updating/upgrading Homebrew taps, formulae,
|
2022-08-25 00:35:42 +00:00
|
|
|
|
and casks, as well as Mac App Store apps and Docker containers, using Homebrew Bundle.
|
|
|
|
|
|
|
|
|
|
Note that enabling this option does not install Homebrew, see the Homebrew
|
2023-06-22 11:21:32 +00:00
|
|
|
|
[website](https://brew.sh) for installation instructions.
|
2022-08-25 00:35:42 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Use the [](#opt-homebrew.brews), [](#opt-homebrew.casks),
|
|
|
|
|
[](#opt-homebrew.masApps), and [](#opt-homebrew.whalebrews) options
|
2022-08-25 00:35:42 +00:00
|
|
|
|
to list the Homebrew formulae, casks, Mac App Store apps, and Docker containers you'd like to
|
2023-06-22 11:21:32 +00:00
|
|
|
|
install. Use the [](#opt-homebrew.taps) option, to make additional formula
|
2022-08-25 00:35:42 +00:00
|
|
|
|
repositories available to Homebrew. This module uses those options (along with the
|
2023-06-22 11:21:32 +00:00
|
|
|
|
[](#opt-homebrew.caskArgs) options) to generate a Brewfile that
|
|
|
|
|
{command}`nix-darwin` passes to the {command}`brew bundle` command during
|
2022-08-25 00:35:42 +00:00
|
|
|
|
system activation.
|
|
|
|
|
|
|
|
|
|
The default configuration of this module prevents Homebrew Bundle from auto-updating Homebrew
|
|
|
|
|
and all formulae, as well as upgrading anything that's already installed, so that repeated
|
2023-06-22 11:21:32 +00:00
|
|
|
|
invocations of {command}`darwin-rebuild switch` (without any change to the
|
2022-08-25 00:35:42 +00:00
|
|
|
|
configuration) are idempotent. You can modify this behavior using the options under
|
2023-06-22 11:21:32 +00:00
|
|
|
|
[](#opt-homebrew.onActivation).
|
2022-08-25 00:35:42 +00:00
|
|
|
|
|
|
|
|
|
This module also provides a few options for modifying how Homebrew commands behave when
|
2024-04-14 21:02:32 +00:00
|
|
|
|
you manually invoke them, under [](#opt-homebrew.global)'';
|
2020-12-08 02:14:48 +00:00
|
|
|
|
|
2021-03-06 12:12:19 +00:00
|
|
|
|
brewPrefix = mkOption {
|
|
|
|
|
type = types.str;
|
2022-01-18 00:07:09 +00:00
|
|
|
|
default = if pkgs.stdenv.hostPlatform.isAarch64 then "/opt/homebrew/bin" else "/usr/local/bin";
|
2022-08-23 20:32:07 +00:00
|
|
|
|
defaultText = literalExpression ''
|
|
|
|
|
if pkgs.stdenv.hostPlatform.isAarch64 then "/opt/homebrew/bin"
|
|
|
|
|
else "/usr/local/bin"
|
|
|
|
|
'';
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2023-06-22 11:21:32 +00:00
|
|
|
|
The path prefix where the {command}`brew` executable is located. This will be set to
|
2022-08-23 20:32:07 +00:00
|
|
|
|
the correct value based on your system's platform, and should only need to be changed if you
|
|
|
|
|
manually installed Homebrew in a non-standard location.
|
2021-03-06 12:12:19 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-24 20:07:19 +00:00
|
|
|
|
onActivation = mkOption {
|
|
|
|
|
type = types.submodule onActivationOptions;
|
|
|
|
|
default = { };
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Options for configuring the behavior of the {command}`brew bundle` command that
|
|
|
|
|
{command}`nix-darwin` runs during system activation.
|
2020-12-08 02:14:48 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-25 00:26:50 +00:00
|
|
|
|
global = mkOption {
|
|
|
|
|
type = types.submodule globalOptions;
|
|
|
|
|
default = { };
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-25 00:26:50 +00:00
|
|
|
|
Options for configuring the behavior of Homebrew commands when you manually invoke them.
|
2021-01-16 20:39:01 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
2020-12-31 00:42:31 +00:00
|
|
|
|
|
2020-12-08 02:14:48 +00:00
|
|
|
|
taps = mkOption {
|
2022-08-23 01:10:46 +00:00
|
|
|
|
type = with types; listOf (coercedTo str (name: { inherit name; }) (submodule tapOptions));
|
2022-08-23 20:32:07 +00:00
|
|
|
|
default = [ ];
|
2022-08-23 01:10:46 +00:00
|
|
|
|
example = literalExpression ''
|
|
|
|
|
# Adapted examples from https://github.com/Homebrew/homebrew-bundle#usage
|
|
|
|
|
[
|
2022-08-23 20:32:07 +00:00
|
|
|
|
# `brew tap`
|
2022-08-23 01:10:46 +00:00
|
|
|
|
"homebrew/cask"
|
2022-08-23 20:32:07 +00:00
|
|
|
|
|
|
|
|
|
# `brew tap` with custom Git URL and arguments
|
2022-08-23 01:10:46 +00:00
|
|
|
|
{
|
|
|
|
|
name = "user/tap-repo";
|
|
|
|
|
clone_target = "https://user@bitbucket.org/user/homebrew-tap-repo.git";
|
|
|
|
|
force_auto_update = true;
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
'';
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-25 00:35:42 +00:00
|
|
|
|
List of Homebrew formula repositories to tap.
|
2022-08-23 01:10:46 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Taps defined as strings, e.g., `"user/repo"`, are a shorthand for:
|
2022-08-23 01:10:46 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
`{ name = "user/repo"; }`
|
2022-08-23 01:10:46 +00:00
|
|
|
|
'';
|
2020-12-08 02:14:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-08-23 20:32:07 +00:00
|
|
|
|
caskArgs = mkOption {
|
|
|
|
|
type = types.submodule caskArgsOptions;
|
|
|
|
|
default = { };
|
|
|
|
|
example = literalExpression ''
|
|
|
|
|
{
|
|
|
|
|
appdir = "~/Applications";
|
|
|
|
|
require_sha = true;
|
|
|
|
|
}
|
|
|
|
|
'';
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Arguments passed to {command}`brew install --cask` for all casks listed in
|
|
|
|
|
[](#opt-homebrew.casks).
|
2022-08-25 00:35:42 +00:00
|
|
|
|
'';
|
2022-08-23 20:32:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-12-08 02:14:48 +00:00
|
|
|
|
brews = mkOption {
|
2022-08-23 02:35:01 +00:00
|
|
|
|
type = with types; listOf (coercedTo str (name: { inherit name; }) (submodule brewOptions));
|
2022-08-23 20:32:07 +00:00
|
|
|
|
default = [ ];
|
2022-08-23 02:35:01 +00:00
|
|
|
|
example = literalExpression ''
|
|
|
|
|
# Adapted examples from https://github.com/Homebrew/homebrew-bundle#usage
|
|
|
|
|
[
|
2022-08-23 20:32:07 +00:00
|
|
|
|
# `brew install`
|
2022-08-23 02:35:01 +00:00
|
|
|
|
"imagemagick"
|
2022-08-23 20:32:07 +00:00
|
|
|
|
|
|
|
|
|
# `brew install --with-rmtp`, `brew services restart` on version changes
|
2022-08-23 02:35:01 +00:00
|
|
|
|
{
|
|
|
|
|
name = "denji/nginx/nginx-full";
|
|
|
|
|
args = [ "with-rmtp" ];
|
|
|
|
|
restart_service = "changed";
|
|
|
|
|
}
|
2022-08-23 20:32:07 +00:00
|
|
|
|
|
|
|
|
|
# `brew install`, always `brew services restart`, `brew link`, `brew unlink mysql` (if it is installed)
|
2022-08-23 02:35:01 +00:00
|
|
|
|
{
|
|
|
|
|
name = "mysql@5.6";
|
|
|
|
|
restart_service = true;
|
|
|
|
|
link = true;
|
|
|
|
|
conflicts_with = [ "mysql" ];
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
'';
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-25 00:35:42 +00:00
|
|
|
|
List of Homebrew formulae to install.
|
2022-08-23 02:35:01 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Formulae defined as strings, e.g., `"imagemagick"`, are a shorthand for:
|
2022-08-23 02:35:01 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
`{ name = "imagemagick"; }`
|
2022-08-23 02:35:01 +00:00
|
|
|
|
'';
|
2020-12-08 02:14:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
casks = mkOption {
|
2022-08-23 03:04:09 +00:00
|
|
|
|
type = with types; listOf (coercedTo str (name: { inherit name; }) (submodule caskOptions));
|
2022-08-23 20:32:07 +00:00
|
|
|
|
default = [ ];
|
2022-08-23 03:04:09 +00:00
|
|
|
|
example = literalExpression ''
|
|
|
|
|
# Adapted examples from https://github.com/Homebrew/homebrew-bundle#usage
|
|
|
|
|
[
|
2022-08-23 20:32:07 +00:00
|
|
|
|
# `brew install --cask`
|
2022-08-23 03:04:09 +00:00
|
|
|
|
"google-chrome"
|
2022-08-23 20:32:07 +00:00
|
|
|
|
|
|
|
|
|
# `brew install --cask --appdir=~/my-apps/Applications`
|
2022-08-23 03:04:09 +00:00
|
|
|
|
{
|
|
|
|
|
name = "firefox";
|
|
|
|
|
args = { appdir = "~/my-apps/Applications"; };
|
|
|
|
|
}
|
2022-08-23 20:32:07 +00:00
|
|
|
|
|
2022-08-23 03:04:09 +00:00
|
|
|
|
# always upgrade auto-updated or unversioned cask to latest version even if already installed
|
|
|
|
|
{
|
|
|
|
|
name = "opera";
|
|
|
|
|
greedy = true;
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
'';
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2022-08-25 00:35:42 +00:00
|
|
|
|
List of Homebrew casks to install.
|
2022-08-23 03:04:09 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Casks defined as strings, e.g., `"google-chrome"`, are a shorthand for:
|
2022-08-23 03:04:09 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
`{ name = "google-chrome"; }`
|
2022-08-23 03:04:09 +00:00
|
|
|
|
'';
|
2020-12-08 02:14:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
masApps = mkOption {
|
2022-08-23 20:32:07 +00:00
|
|
|
|
type = types.attrsOf types.ints.positive;
|
|
|
|
|
default = { };
|
|
|
|
|
example = literalExpression ''
|
|
|
|
|
{
|
|
|
|
|
"1Password for Safari" = 1569813296;
|
|
|
|
|
Xcode = 497799835;
|
|
|
|
|
}
|
|
|
|
|
'';
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Applications to install from Mac App Store using {command}`mas`.
|
2020-12-08 02:14:48 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
When this option is used, `"mas"` is automatically added to
|
|
|
|
|
[](#opt-homebrew.brews).
|
2020-12-08 02:14:48 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
Note that you need to be signed into the Mac App Store for {command}`mas` to
|
2020-12-08 02:14:48 +00:00
|
|
|
|
successfully install and upgrade applications, and that unfortunately apps removed from this
|
|
|
|
|
option will not be uninstalled automatically even if
|
2023-06-22 11:21:32 +00:00
|
|
|
|
[](#opt-homebrew.onActivation.cleanup) is set to `"uninstall"`
|
|
|
|
|
or `"zap"` (this is currently a limitation of Homebrew Bundle).
|
2020-12-08 02:14:48 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
For more information on {command}`mas` see:
|
|
|
|
|
[github.com/mas-cli/mas](https://github.com/mas-cli/mas).
|
2020-12-08 02:14:48 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
whalebrews = mkOption {
|
|
|
|
|
type = with types; listOf str;
|
2022-08-23 20:32:07 +00:00
|
|
|
|
default = [ ];
|
2020-12-08 02:14:48 +00:00
|
|
|
|
example = [ "whalebrew/wget" ];
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = ''
|
2023-06-22 11:21:32 +00:00
|
|
|
|
List of Docker images to install using {command}`whalebrew`.
|
2020-12-08 02:14:48 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
When this option is used, `"whalebrew"` is automatically added to
|
|
|
|
|
[](#opt-homebrew.brews).
|
2020-12-08 02:14:48 +00:00
|
|
|
|
|
2023-06-22 11:21:32 +00:00
|
|
|
|
For more information on {command}`whalebrew` see:
|
|
|
|
|
[github.com/whalebrew/whalebrew](https://github.com/whalebrew/whalebrew).
|
2020-12-08 02:14:48 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
|
type = types.lines;
|
|
|
|
|
default = "";
|
|
|
|
|
example = ''
|
2020-12-08 19:42:15 +00:00
|
|
|
|
# 'brew cask install' only if '/usr/libexec/java_home --failfast' fails
|
|
|
|
|
cask "java" unless system "/usr/libexec/java_home --failfast"
|
2020-12-08 02:14:48 +00:00
|
|
|
|
'';
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = "Extra lines to be added verbatim to the bottom of the generated Brewfile.";
|
2020-12-08 02:14:48 +00:00
|
|
|
|
};
|
2022-08-23 20:32:07 +00:00
|
|
|
|
|
2022-08-25 00:26:50 +00:00
|
|
|
|
brewfile = mkInternalOption {
|
2022-08-23 20:32:07 +00:00
|
|
|
|
type = types.str;
|
2024-04-14 21:02:32 +00:00
|
|
|
|
description = "String reprensentation of the generated Brewfile useful for debugging.";
|
2022-08-23 20:32:07 +00:00
|
|
|
|
};
|
2020-12-08 02:14:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-08-23 20:32:07 +00:00
|
|
|
|
|
|
|
|
|
# Implementation ---------------------------------------------------------------------------------
|
|
|
|
|
|
2020-12-08 02:14:48 +00:00
|
|
|
|
config = {
|
2022-08-24 20:07:19 +00:00
|
|
|
|
|
2022-08-25 00:26:50 +00:00
|
|
|
|
assertions = [
|
|
|
|
|
# See comment above `homebrew.global.noLock` option declaration for why this is required.
|
|
|
|
|
{ assertion = cfg.global.noLock == null; message = "The option `homebrew.global.noLock' was removed, use `homebrew.global.lockfiles' in it's place."; }
|
|
|
|
|
];
|
|
|
|
|
|
2022-08-24 20:07:19 +00:00
|
|
|
|
warnings = [
|
2022-08-25 00:35:42 +00:00
|
|
|
|
(mkIf (options.homebrew.autoUpdate.isDefined || options.homebrew.cleanup.isDefined) "The `homebrew' module no longer upgrades outdated formulae and apps by default during `nix-darwin' system activation. To enable upgrading, set `homebrew.onActivation.upgrade = true'.")
|
2022-08-24 20:07:19 +00:00
|
|
|
|
];
|
|
|
|
|
|
2020-12-17 21:03:57 +00:00
|
|
|
|
homebrew.brews =
|
2022-08-23 20:32:07 +00:00
|
|
|
|
optional (cfg.masApps != { }) "mas"
|
|
|
|
|
++ optional (cfg.whalebrews != [ ]) "whalebrew";
|
|
|
|
|
|
|
|
|
|
homebrew.brewfile =
|
|
|
|
|
"# Created by `nix-darwin`'s `homebrew` module\n\n"
|
|
|
|
|
+ mkBrewfileSectionString "Taps" cfg.taps
|
|
|
|
|
+ mkBrewfileSectionString "Arguments for all casks"
|
|
|
|
|
(optional (cfg.caskArgs.brewfileLine != null) cfg.caskArgs)
|
|
|
|
|
+ mkBrewfileSectionString "Brews" cfg.brews
|
|
|
|
|
+ mkBrewfileSectionString "Casks" cfg.casks
|
|
|
|
|
+ mkBrewfileSectionString "Mac App Store apps"
|
|
|
|
|
(mapAttrsToList (n: id: ''mas "${n}", id: ${toString id}'') cfg.masApps)
|
|
|
|
|
+ mkBrewfileSectionString "Docker containers" (map (v: ''whalebrew "${v}"'') cfg.whalebrews)
|
|
|
|
|
+ optionalString (cfg.extraConfig != "") ("# Extra config\n" + cfg.extraConfig);
|
2020-12-08 02:14:48 +00:00
|
|
|
|
|
2022-08-25 00:26:50 +00:00
|
|
|
|
environment.variables = mkIf cfg.enable cfg.global.homebrewEnvironmentVariables;
|
2020-12-08 02:14:48 +00:00
|
|
|
|
|
2020-12-17 21:03:57 +00:00
|
|
|
|
system.activationScripts.homebrew.text = mkIf cfg.enable ''
|
2020-12-08 02:14:48 +00:00
|
|
|
|
# Homebrew Bundle
|
|
|
|
|
echo >&2 "Homebrew bundle..."
|
2021-03-06 12:12:19 +00:00
|
|
|
|
if [ -f "${cfg.brewPrefix}/brew" ]; then
|
2022-08-24 20:07:19 +00:00
|
|
|
|
PATH="${cfg.brewPrefix}":$PATH ${cfg.onActivation.brewBundleCmd}
|
2020-12-18 00:54:29 +00:00
|
|
|
|
else
|
|
|
|
|
echo -e "\e[1;31merror: Homebrew is not installed, skipping...\e[0m" >&2
|
|
|
|
|
fi
|
2020-12-08 02:14:48 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
}
|