dustinlyons / nixos-config

General purpose Nix configuration for macOS / NixOS with starter templates + step-by-step guides ✨
BSD 3-Clause "New" or "Revised" License
1.79k stars 113 forks source link

Using "homebrew.onActivation.cleanup" to make Homebrew Cask installation part declarative? #84

Closed victorhooi closed 5 months ago

victorhooi commented 5 months ago

I just edited some packages in ~/nixos-config/modules/darwin/casks.nix, and realised that if I commented out a package, it didn't get uninstalled.

Anyway, I did some naive Googling (e.g. this article), and it seems the option I want is homebrew.onActivation.cleanup.

Does it make sense to make homebrew.onActivation.cleanup = "uninstall", (or = "zap") the default?

Or at least call it out in the README as a suggestion?

Also - it might be helpful to briefly mention in the README about enabling Full Disk Access around that point. WDYT?

==> Dispatching zap stanza
Error: Unable to remove some files. Please enable Full Disk Access for your terminal under System Settings → Privacy & Security → Full Disk Access.
Uninstalled 1 cask
Uninstalling mas... (7 files, 951.5KB)
Uninstalled 1 formula
Error: Refusing to untap homebrew/cask because it contains the following installed formulae or casks:
discord
docker
visual-studio-code
visual-studio-code@insiders
zoom
Setting up the Dock...
dustinlyons commented 5 months ago

It's a good idea to mention this and have it available to the user, but setting it as default could possibly be intrusive if the user doesn't realize it and accidentally removes an app they really need. Although the config is declarative, under the hood it will be imperative mac terminal commands that do the installing/uninstalling, sometimes undocumented things happen, break, etc.

My preference is reformat my Mac from time to time if I feel like I need to.

Anyway, I think we add this commented line to the config

# onActivation.cleanup = "uninstall";

in the areas that need it under templates/starter and templates/starter-with-secrets.

Feel free to add this there and open a PR, or I can get to it eventually.

dustinlyons commented 5 months ago

Merged this as part of your PR. Thanks!