Skip to content

Commit

Permalink
refactor: consolidate homebrew config to own file, enable uninstall w…
Browse files Browse the repository at this point in the history
…ith untap fix (#4)

refactor: consolidate homebrew config to own file, enable uninstall with untap fix

- Consoldiate nix-darwin homebrew module and nix-homebrew in one
`modules/darwin/homebrew.nix file`
- Set uninstall to remove packages when they are removed from the config
- Fix nix-darwin untapping nix-homebrew by passing nix-homebrew taps to
nix-darwin homebrew module

homebrew: Add option to enable brew zsh integration

Make option to `enableZshIntegration`
Initializes brew with `/opt/homebrew/bin/brew shellenv`

homebrew: Add bash, fish, and nushell integration options

Fish, bash, and nushell are untested as of this commit
  • Loading branch information
AVGVSTVS96 authored Nov 17, 2024
1 parent beb4527 commit 858805f
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 57 deletions.
36 changes: 11 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,43 +81,29 @@
apps = nixpkgs.lib.genAttrs linuxSystems mkLinuxApps
// nixpkgs.lib.genAttrs darwinSystems mkDarwinApps;

darwinConfigurations = nixpkgs.lib.genAttrs darwinSystems
(system: darwin.lib.darwinSystem {
darwinConfigurations = nixpkgs.lib.genAttrs darwinSystems (
system: darwin.lib.darwinSystem {
inherit system;
specialArgs = { inherit variables inputs; };
modules = [
home-manager.darwinModules.home-manager
nix-homebrew.darwinModules.nix-homebrew
{
# TODO: Move to dedicated homebrew module incl. casks
nix-homebrew = {
user = variables.userName;
enable = true;
taps = {
"homebrew/homebrew-core" = homebrew-core;
"homebrew/homebrew-cask" = homebrew-cask;
"homebrew/homebrew-bundle" = homebrew-bundle;
};
mutableTaps = false;
autoMigrate = true;
};
}
./hosts/darwin
];
}
);
);

nixosConfigurations =
let
mkNixos = host: system: nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = { inherit variables inputs; };
modules = [
disko.nixosModules.disko
home-manager.nixosModules.home-manager
./hosts/${host}
];
};
inherit system;
specialArgs = { inherit variables inputs; };
modules = [
disko.nixosModules.disko
home-manager.nixosModules.home-manager
./hosts/${host}
];
};
in
{
"nixos-x86_64" = mkNixos "nixos" "x86_64-linux";
Expand Down
10 changes: 6 additions & 4 deletions hosts/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ in
{
imports = [
../../modules/darwin/home-manager.nix
../../modules/darwin/homebrew.nix
../../modules/shared/cachix
../../modules/shared
];
Expand All @@ -25,9 +26,8 @@ in
# Turn off NIX_PATH warnings now that we're using flakes
system.checks.verifyNixPath = false;

networking = {
inherit hostName localHostName;
};
# inherit sets options to the variable with the same name
networking = { inherit hostName localHostName; };

environment.systemPackages = with pkgs; [ git ];

Expand Down Expand Up @@ -60,7 +60,9 @@ in
tilesize = 48;
};

finder = { _FXShowPosixPathInTitle = false; };
finder = {
_FXShowPosixPathInTitle = false;
};

trackpad = {
Clicking = true;
Expand Down
28 changes: 0 additions & 28 deletions modules/darwin/casks.nix

This file was deleted.

122 changes: 122 additions & 0 deletions modules/darwin/homebrew.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{ variables, inputs, config, lib, ... }:
let
inherit (variables) userName;
inherit (inputs) homebrew-bundle homebrew-core homebrew-cask;
inherit (lib) mkIf mkEnableOption;
cfg = config.nix-homebrew;
in
{
options = {
# Homebrew shell integration, may be merged into nix-homebrew
# https://github.com/zhaofengli/nix-homebrew/pull/39
#
# TODO: PR merged, update and test using nix-darwin interactiveShellInit
# instead of home-manager shell config like in PR
#
nix-homebrew = {
enableZshIntegration = mkEnableOption "homebrew zsh integration" // {
default = false;
};
enableBashIntegration = mkEnableOption "homebrew bash integration" // {
default = false;
};
enableFishIntegration = mkEnableOption "homebrew fish integration" // {
default = false;
};
enableNushellIntegration = mkEnableOption "homebrew nushell integration" // {
default = false;
};
};
};

config = {
# nix-homebrew homebrew module
# Manages homebrew installation
nix-homebrew = {
user = userName;
enable = true;
enableZshIntegration = true;
taps = {
"homebrew/homebrew-core" = homebrew-core;
"homebrew/homebrew-cask" = homebrew-cask;
"homebrew/homebrew-bundle" = homebrew-bundle;
};
mutableTaps = false;
autoMigrate = true;
};

# Homebrew shell integration
home-manager.users.${userName}.programs = {
zsh.initExtra = mkIf cfg.enableZshIntegration ''
eval "$(${config.homebrew.brewPrefix}/brew shellenv)"
'';

bash.initExtra = mkIf cfg.enableBashIntegration ''
eval "$(${config.homebrew.brewPrefix}/brew shellenv)"
'';

fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
eval "$(${config.homebrew.brewPrefix}/brew shellenv)"
'';

# https://www.nushell.sh/book/configuration.html#homebrew
# https://reimbar.org/dev/nushell/
nushell.extraEnv = mkIf cfg.enableFishIntegration ''
# $env.PATH = ($env.PATH | split row (char esep) | prepend '/opt/homebrew/bin')
use std "path add"
path add /opt/homebrew/bin
'';
};

# nix-darwin homebrew module
# Manages homebrew packages
homebrew = {
enable = true;
onActivation.cleanup = "uninstall";

# Fixes nix-darwin trying to untap nix-homebrew taps when uninstall is set
# https://github.com/zhaofengli/nix-homebrew/issues/5
taps = builtins.attrNames config.nix-homebrew.taps;

casks = [
# Development Tools
# "homebrew/cask/docker"
# "visual-studio-code"
"visual-studio-code@insiders"

# Communication Tools
# "discord"
# "notion"
# "slack"
# "telegram"
# "zoom"

# Utility Tools
# "syncthing"

# Entertainment Tools
# "iina" # Video player

# Productivity Tools
"raycast"

# Browsers
"google-chrome"
# "arc" # Arc browser
];

# Mac App Store Apps
# These app IDs are from using the mas CLI app
# $ nix shell nixpkgs#mas
# $ mas search <app name>
#
# If you have previously added these apps to your Mac App Store profile (but not installed them on this system),
# you may receive an error message "Redownload Unavailable with This Apple ID".
# This message is safe to ignore. (https://github.com/dustinlyons/nixos-config/issues/83)
# masApps = {
# "1password" = 1333542190;
# "wireguard" = 1451685025;
# };
};
};
}

0 comments on commit 858805f

Please sign in to comment.