I’m fairly new to Nix. Most of the challenges I ran into, I was able to solve myself. But I do have 1.5 issues with Brew
I’m running 15.1.1
flake.nix
{
description = "Example nix-darwin system flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nix-darwin.url = "github:LnL7/nix-darwin";
#nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-24.05";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew";
# Optional: Declarative tap management
homebrew-core = {
url = "github:homebrew/homebrew-core";
flake = false;
};
homebrew-cask = {
url = "github:homebrew/homebrew-cask";
flake = false;
};
homebrew-bundle = {
url = "github:homebrew/homebrew-bundle";
flake = false;
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-vscode-extensions = {
url = "github:nix-community/nix-vscode-extensions";
inputs.nixpkgs.follows = "nixpkgs";
};
# import the 1Password Shell Plugins Flake
_1password-shell-plugins.url = "github:1Password/shell-plugins";
};
outputs = inputs @ {
self,
nix-darwin,
nixpkgs,
nix-homebrew,
homebrew-core,
homebrew-cask,
homebrew-bundle,
home-manager,
nix-vscode-extensions,
...
}: let
overlays = [
(final: prev: {
vscode-extensions = inputs.nix-vscode-extensions.extensions.${prev.system};
})
];
configuration = {
pkgs,
config,
...
}: {
nixpkgs.overlays = overlays;
nixpkgs.config.allowUnfree = true;
environment.systemPackages = [
pkgs.neovim
pkgs.mkalias
pkgs.aldente
pkgs.git
pkgs._1password-cli
];
# Necessary for using flakes on this system.
nix.settings.experimental-features = "nix-command flakes";
# Garabage Collection to keep the system cleaner
nix.gc = {
automatic = true;
interval = {
Weekday = 0;
Hour = 4;
Minute = 0;
};
options = "--delete-older-than 30d";
};
imports = [
./modules/darwin-system-defaults.nix
];
# Set Git commit hash for darwin-version.
system.configurationRevision = self.rev or self.dirtyRev or null;
# $ darwin-rebuild changelog
system.stateVersion = 5;
# The platform the configuration will be used on.
nixpkgs.hostPlatform = "aarch64-darwin";
homebrew = {
enable = true;
onActivation = {
cleanup = "zap";
upgrade = true;
autoUpdate = true;
};
casks = [
"bartender"
"soundsource"
"selfcontrol"
"hammerspoon"
"microsoft-excel"
"microsoft-outlook"
"microsoft-teams"
"istat-menus"
"hazel"
"1password"
"karabiner-elements"
"ticktick"
"tailscale"
"bettermouse"
];
brews = [
"ollama"
"gollama"
];
masApps = {
"1Password for Safari" = 1569813296;
"1Bloker" = 1365531024;
Raindrop = 1549370672;
};
};
fonts.packages = [
pkgs.nerd-fonts.jetbrains-mono
pkgs.nerd-fonts.meslo-lg
];
system.activationScripts.applications.text = let
env = pkgs.buildEnv {
name = "system-applications";
paths = config.environment.systemPackages;
pathsToLink = "/Applications";
};
in
pkgs.lib.mkForce ''
# Set up applications.
echo "setting up /Applications..." >&2
rm -rf /Applications/Nix\ Apps
mkdir -p /Applications/Nix\ Apps
find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + |
while read -r src; do
app_name=$(basename "$src")
echo "copying $src" >&2
${pkgs.mkalias}/bin/mkalias "$src" "/Applications/Nix Apps/$app_name"
done
'';
};
in {
darwinConfigurations."maxbook-pro" = nix-darwin.lib.darwinSystem {
modules = [
configuration
nix-homebrew.darwinModules.nix-homebrew
{
nix-homebrew = {
# Install Homebrew under the default prefix
enable = true;
enableRosetta = false;
# User owning the Homebrew prefix
user = "USER"; #Changed for public
# Optional: Declarative tap management
taps = {
"homebrew/homebrew-core" = homebrew-core;
"homebrew/homebrew-cask" = homebrew-cask;
"homebrew/homebrew-bundle" = homebrew-bundle;
};
mutableTaps = false;
};
}
home-manager.darwinModules.home-manager
{
home-manager.backupFileExtension = "backup";
users.users.USER.home = "/Users/USEER";
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.USER = import ./home-manager/main-user.nix;
}
];
};
};
}
Updating
With casks apps, I ran twice into the situation that an update failed. Both of them were a bit of a hassle to debug.
Question:
Without starting philosophical debate: Leaving the updating to the apps wouldn’t be clean (none deterministic).
Would it be a solution, to install the apps via Brew the module (is that the correct therm?) and in some cases leave the updating to the apps themselves?
Unable to untap
During rebuilding Brew reports that it is unable to untap several casks. I started to just ignoring it. But that is never a good solution. Am I holding it wrong?
Error
Error: Refusing to untap homebrew/cask because it contains the following installed formulae or casks:
1password
bartender
hammerspoon
hazel
istat-menus
karabiner-elements
languagetool
microsoft-excel
microsoft-outlook
microsoft-teams
selfcontrol
soundsource
synology-drive
tailscale