homebrew: use brewBundleCmd also for system.checks
This commit is contained in:
parent
5138eaf896
commit
d8a6661f78
2 changed files with 23 additions and 21 deletions
|
|
@ -172,11 +172,11 @@ let
|
|||
'';
|
||||
};
|
||||
|
||||
brewBundleCmd = mkInternalOption { type = types.str; };
|
||||
brewBundleCmd = mkInternalOption { type = types.functionTo types.str; };
|
||||
};
|
||||
|
||||
config = {
|
||||
brewBundleCmd = concatStringsSep " " (
|
||||
brewBundleCmd = { onlyCheck }: concatStringsSep " " (
|
||||
[
|
||||
''PATH="${cfg.prefix}/bin:${lib.makeBinPath [ pkgs.mas ]}:$PATH"''
|
||||
"sudo"
|
||||
|
|
@ -185,13 +185,18 @@ let
|
|||
"--set-home"
|
||||
"env"
|
||||
]
|
||||
++ optional (!config.autoUpdate) "HOMEBREW_NO_AUTO_UPDATE=1"
|
||||
++ optional (onlyCheck || !config.autoUpdate) "HOMEBREW_NO_AUTO_UPDATE=1"
|
||||
++ mapAttrsToList (k: v: "${k}=${escapeShellArg v}") config.extraEnv
|
||||
++ [ "brew bundle --file='${brewfileFile}'" ]
|
||||
++ optional (!config.upgrade) "--no-upgrade"
|
||||
++ optional (config.cleanup == "uninstall") "--force-cleanup"
|
||||
++ optional (config.cleanup == "zap") "--zap --force-cleanup"
|
||||
++ config.extraFlags
|
||||
++ (
|
||||
if onlyCheck then
|
||||
[ "cleanup 2>&1" ]
|
||||
else
|
||||
optional (!config.upgrade) "--no-upgrade"
|
||||
++ optional (config.cleanup == "uninstall") "--force-cleanup"
|
||||
++ optional (config.cleanup == "zap") "--zap --force-cleanup"
|
||||
++ config.extraFlags
|
||||
)
|
||||
);
|
||||
};
|
||||
};
|
||||
|
|
@ -1003,14 +1008,7 @@ in
|
|||
system.checks.text = mkIf (cfg.enable && cfg.onActivation.cleanup == "check") ''
|
||||
if [ -f "${cfg.prefix}/bin/brew" ]; then
|
||||
homebrewCleanupExitCode=0
|
||||
homebrewCleanupResult=$(PATH="${cfg.prefix}/bin:${lib.makeBinPath [ pkgs.mas ]}:$PATH" \
|
||||
sudo \
|
||||
--preserve-env=PATH \
|
||||
--user=${escapeShellArg cfg.user} \
|
||||
--set-home \
|
||||
env HOMEBREW_NO_AUTO_UPDATE=1 \
|
||||
${concatStringsSep " " (mapAttrsToList (k: v: "${k}=${escapeShellArg v}") cfg.onActivation.extraEnv)} \
|
||||
brew bundle cleanup --file='${brewfileFile}' 2>&1) || homebrewCleanupExitCode=$?
|
||||
homebrewCleanupResult=$(${cfg.onActivation.brewBundleCmd { onlyCheck = true; }}) || homebrewCleanupExitCode=$?
|
||||
if [ "$homebrewCleanupExitCode" -eq 1 ]; then
|
||||
printf >&2 '\e[1;31merror: found Homebrew packages not listed in the Brewfile, aborting activation\e[0m\n'
|
||||
printf >&2 '%s\n' "$homebrewCleanupResult"
|
||||
|
|
@ -1032,7 +1030,7 @@ in
|
|||
# Homebrew Bundle
|
||||
echo >&2 "Homebrew bundle..."
|
||||
if [ -f "${cfg.prefix}/bin/brew" ]; then
|
||||
${cfg.onActivation.brewBundleCmd}
|
||||
${cfg.onActivation.brewBundleCmd { onlyCheck = false; }}
|
||||
else
|
||||
echo -e "\e[1;31merror: Homebrew is not installed, skipping...\e[0m" >&2
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue