mirror of
https://github.com/LnL7/nix-darwin.git
synced 2025-03-30 19:54:43 +00:00
Enable defining options for taps
using submodule
This commit is contained in:
parent
92da7697d1
commit
bd93329d6c
1 changed files with 83 additions and 24 deletions
|
@ -6,22 +6,27 @@ with lib;
|
||||||
let
|
let
|
||||||
cfg = config.homebrew;
|
cfg = config.homebrew;
|
||||||
|
|
||||||
brewfileSection = heading: type: entries: optionalString (entries != [])
|
mkBrewfileSectionString = heading: type: entries: optionalString (entries != []) ''
|
||||||
"# ${heading}\n" + (concatMapStrings (name: "${type} \"${name}\"\n") entries) + "\n";
|
# ${heading}
|
||||||
|
${concatMapStringsSep "\n" (v: v.brewfileLine or ''${type} "${v}"'') entries}
|
||||||
|
|
||||||
masBrewfileSection = entries: optionalString (entries != {}) (
|
'';
|
||||||
|
|
||||||
|
mkMasBrewfileSectionString = entries: optionalString (entries != {}) (
|
||||||
"# Mac App Store apps\n" +
|
"# Mac App Store apps\n" +
|
||||||
concatStringsSep "\n" (mapAttrsToList (name: id: ''mas "${name}", id: ${toString id}'') entries) +
|
concatStringsSep "\n" (mapAttrsToList (name: id: ''mas "${name}", id: ${toString id}'') entries) +
|
||||||
"\n"
|
"\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
brewfile = pkgs.writeText "Brewfile" (
|
brewfile = pkgs.writeText "Brewfile" (
|
||||||
brewfileSection "Taps" "tap" cfg.taps +
|
mkBrewfileSectionString "Taps" "tap" cfg.taps +
|
||||||
(if cfg.caskArgs.brewfileLine == null then "" else "# Arguments for all casks\n${cfg.caskArgs.brewfileLine}\n\n") +
|
mkBrewfileSectionString "Arguments for all casks" "cask_args"
|
||||||
brewfileSection "Brews" "brew" cfg.brews +
|
(optional (cfg.caskArgs.brewfileLine != null) cfg.caskArgs) +
|
||||||
brewfileSection "Casks" "cask" cfg.casks +
|
mkBrewfileSectionString "Brews" "brew" cfg.brews +
|
||||||
masBrewfileSection cfg.masApps +
|
mkBrewfileSectionString "Casks" "cask" cfg.casks +
|
||||||
brewfileSection "Docker containers" "whalebrew" cfg.whalebrews +
|
mkMasBrewfileSectionString cfg.masApps +
|
||||||
|
mkBrewfileSectionString "Docker containers" "whalebrew" cfg.whalebrews +
|
||||||
optionalString (cfg.extraConfig != "") ("# Extra config\n" + cfg.extraConfig)
|
optionalString (cfg.extraConfig != "") ("# Extra config\n" + cfg.extraConfig)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -54,6 +59,50 @@ let
|
||||||
default = null;
|
default = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mkBrewfileLineOption = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
visible = false;
|
||||||
|
internal = true;
|
||||||
|
readOnly = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
tapOptions = { config, ... }: {
|
||||||
|
options = {
|
||||||
|
name = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "homebrew/cask-fonts";
|
||||||
|
description = ''
|
||||||
|
When <option>clone_target</option> is unspecified, this is the name of a formula
|
||||||
|
repository to tap from GitHub using HTTPS. For example, <literal>"user/repo"</literal> will
|
||||||
|
tap https://github.com/user/homebrew-repo.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
clone_target = mkNullOrStrOption {
|
||||||
|
description = ''
|
||||||
|
Use this option to tap a formula repository from anywhere, using any transport protocol
|
||||||
|
that <command>git</command> handles. When <option>clone_target</option> is specified, taps
|
||||||
|
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 {
|
||||||
|
description = ''
|
||||||
|
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).
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
brewfileLine = mkBrewfileLineOption;
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
brewfileLine = ''tap "${config.name}"''
|
||||||
|
+ optionalString (config.clone_target != null) '', "${config.clone_target}"''
|
||||||
|
+ optionalString (config.force_auto_update != null)
|
||||||
|
", force_auto_update: ${boolToString config.force_auto_update}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# Sourced from https://docs.brew.sh/Manpage#global-cask-options
|
# Sourced from https://docs.brew.sh/Manpage#global-cask-options
|
||||||
# and valid values for `HOMEBREW_CASK_OPTS`.
|
# and valid values for `HOMEBREW_CASK_OPTS`.
|
||||||
caskArgsOptions = { config, ... }: {
|
caskArgsOptions = { config, ... }: {
|
||||||
|
@ -160,22 +209,17 @@ let
|
||||||
description = "Whether to disable linking of helper executables.";
|
description = "Whether to disable linking of helper executables.";
|
||||||
};
|
};
|
||||||
|
|
||||||
brewfileLine = mkOption {
|
brewfileLine = mkBrewfileLineOption;
|
||||||
type = types.nullOr types.str;
|
|
||||||
visible = false;
|
|
||||||
internal = true;
|
|
||||||
readOnly = true;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
configuredOptions = filterAttrs (_: v: v != null) (removeAttrs config [ "_module" "brewfileLine" ]);
|
configuredOptions = filterAttrs (_: v: v != null)
|
||||||
|
(removeAttrs config [ "_module" "brewfileLine" ]);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
brewfileLine =
|
brewfileLine =
|
||||||
if configuredOptions == {}
|
if configuredOptions == {} then null
|
||||||
then null
|
|
||||||
else "cask_args " + mkBrewfileLineOptionsListString configuredOptions;
|
else "cask_args " + mkBrewfileLineOptionsListString configuredOptions;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -266,10 +310,28 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
taps = mkOption {
|
taps = mkOption {
|
||||||
type = with types; listOf str;
|
type = with types; listOf (coercedTo str (name: { inherit name; }) (submodule tapOptions));
|
||||||
default = [];
|
default = [];
|
||||||
example = [ "homebrew/cask-fonts" ];
|
example = literalExpression ''
|
||||||
description = "Homebrew formula repositories to tap.";
|
# Adapted examples from https://github.com/Homebrew/homebrew-bundle#usage
|
||||||
|
[
|
||||||
|
# 'brew tap'
|
||||||
|
"homebrew/cask"
|
||||||
|
# 'brew tap' with custom Git URL and arguments
|
||||||
|
{
|
||||||
|
name = "user/tap-repo";
|
||||||
|
clone_target = "https://user@bitbucket.org/user/homebrew-tap-repo.git";
|
||||||
|
force_auto_update = true;
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Homebrew formula repositories to tap.
|
||||||
|
|
||||||
|
Taps defined as strings, e.g., <literal>"user/repo"</literal>, are a shorthand for:
|
||||||
|
|
||||||
|
<code>{ name = "user/repo"; }</code>
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
brews = mkOption {
|
brews = mkOption {
|
||||||
|
@ -338,9 +400,6 @@ in
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
default = "";
|
default = "";
|
||||||
example = ''
|
example = ''
|
||||||
# 'brew tap' with custom Git URL
|
|
||||||
tap "user/tap-repo", "https://user@bitbucket.org/user/homebrew-tap-repo.git"
|
|
||||||
|
|
||||||
# 'brew install --with-rmtp', 'brew services restart' on version changes
|
# 'brew install --with-rmtp', 'brew services restart' on version changes
|
||||||
brew "denji/nginx/nginx-full", args: ["with-rmtp"], restart_service: :changed
|
brew "denji/nginx/nginx-full", args: ["with-rmtp"], restart_service: :changed
|
||||||
# 'brew install', always 'brew services restart', 'brew link', 'brew unlink mysql' (if it is installed)
|
# 'brew install', always 'brew services restart', 'brew link', 'brew unlink mysql' (if it is installed)
|
||||||
|
|
Loading…
Add table
Reference in a new issue