Skip to content

Commit

Permalink
add support for installing vscode extensions via brew
Browse files Browse the repository at this point in the history
  • Loading branch information
fcjr committed Dec 15, 2024
1 parent a35b08d commit 88a4437
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
28 changes: 23 additions & 5 deletions modules/homebrew.nix
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,10 @@ in
[website](https://brew.sh) for installation instructions.
Use the [](#opt-homebrew.brews), [](#opt-homebrew.casks),
[](#opt-homebrew.masApps), and [](#opt-homebrew.whalebrews) options
to list the Homebrew formulae, casks, Mac App Store apps, and Docker containers you'd like to
install. Use the [](#opt-homebrew.taps) option, to make additional formula
repositories available to Homebrew. This module uses those options (along with the
[](#opt-homebrew.masApps), [](#opt-homebrew.whalebrews), [](#opt-homebrew.vscode) options
to list the Homebrew formulae, casks, Mac App Store apps, Docker containers and Visual Studio
Code Extensions you'd like to install. Use the [](#opt-homebrew.taps) option, to make additional
formula repositories available to Homebrew. This module uses those options (along with the
[](#opt-homebrew.caskArgs) options) to generate a Brewfile that
{command}`nix-darwin` passes to the {command}`brew bundle` command during
system activation.
Expand Down Expand Up @@ -734,6 +734,21 @@ in
'';
};

vscode = mkOption {
type = with types; listOf str;
default = [ ];
example = [ "golang.go" ];
description = ''
List of Visual Studio Code extensions to install using `code --install-extension`.
When this option is used, `"visual-studio-code"` is automatically added to
[](#opt-homebrew.casks).
For more information on {command}`code` see:
[VSCode Extension Marketplace](https://code.visualstudio.com/docs/editor/extension-marketplace).
'';
};

extraConfig = mkOption {
type = types.lines;
default = "";
Expand Down Expand Up @@ -768,6 +783,8 @@ in
optional (cfg.masApps != { }) "mas"
++ optional (cfg.whalebrews != [ ]) "whalebrew";

homebrew.casks = optional (cfg.vscode != [ ]) "visual-studio-code";

homebrew.brewfile =
"# Created by `nix-darwin`'s `homebrew` module\n\n"
+ mkBrewfileSectionString "Taps" cfg.taps
Expand All @@ -778,6 +795,7 @@ in
+ mkBrewfileSectionString "Mac App Store apps"
(mapAttrsToList (n: id: ''mas "${n}", id: ${toString id}'') cfg.masApps)
+ mkBrewfileSectionString "Docker containers" (map (v: ''whalebrew "${v}"'') cfg.whalebrews)
+ mkBrewfileSectionString "Visual Studio Code extensions" (map (v: ''vscode "${v}"'') cfg.vscode)
+ optionalString (cfg.extraConfig != "") ("# Extra config\n" + cfg.extraConfig);

environment.variables = mkIf cfg.enable cfg.global.homebrewEnvironmentVariables;
Expand All @@ -786,7 +804,7 @@ in
# Homebrew Bundle
echo >&2 "Homebrew bundle..."
if [ -f "${cfg.brewPrefix}/brew" ]; then
PATH="${cfg.brewPrefix}":$PATH ${cfg.onActivation.brewBundleCmd}
PATH="${cfg.brewPrefix}":/opt/homebrew/bin:$PATH ${cfg.onActivation.brewBundleCmd}
else
echo -e "\e[1;31merror: Homebrew is not installed, skipping...\e[0m" >&2
fi
Expand Down
7 changes: 7 additions & 0 deletions tests/homebrew.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ in
"whalebrew/wget"
];

homebrew.vscode = [
"golang.go"
];

test = ''
bf=${lib.escapeShellArg config.homebrew.brewfile}
Expand Down Expand Up @@ -97,5 +101,8 @@ in
echo "checking whalebrew entries in Brewfile" >&2
${mkTest "whalebrew/wget" ''whalebrew "whalebrew/wget"''}
echo "checking vscode entries in Brewfile" >&2
${mkTest "golang.go" ''vscode "golang.go"''}
'';
}

0 comments on commit 88a4437

Please sign in to comment.