From ee735ee782fdacbc3922d5d5b41fef4662a42498 Mon Sep 17 00:00:00 2001 From: Brian Nelson Date: Sun, 8 Nov 2026 11:55:45 -0500 Subject: [PATCH] Working nix-darwin config from this Mac --- archive-installs.nix | 45 +++++++++++++++++++++++ cli-tools.nix | 32 +++++++++++++++++ configuration.nix | 65 +++++++++++++++++++++++++++++++++ flake.lock | 85 ++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 26 ++++++++++++++ mac-settings.nix | 64 +++++++++++++++++++++++++++++++++ pkg-installs.nix | 33 +++++++++++++++++ 7 files changed, 350 insertions(+) create mode 100644 archive-installs.nix create mode 100644 cli-tools.nix create mode 100644 configuration.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 mac-settings.nix create mode 100644 pkg-installs.nix diff --git a/archive-installs.nix b/archive-installs.nix new file mode 100644 index 0000000..40062e3 --- /dev/null +++ b/archive-installs.nix @@ -0,0 +1,45 @@ +{ pkgs, lib, ... }: + +let + stampDir = "/usr/local/share/nix-pkg-stamps"; + + apps = [ + { + name = "removemacai-app"; + app = "RemoveMacAI.app"; + url = "https://github.com/omlahore/RemoveMacAI/releases/download/v1.1.4/RemoveMacAI.zip"; + sha256 = "2063d4dc7e0b41b15cebcd9e1b9807b04615b96e3e23db35cbd1196be3c96bee"; + } + ]; + + appScript = a: + let + src = pkgs.fetchurl { inherit (a) url sha256; }; + in '' + stamp="${stampDir}/${a.name}" + want="${src}" + if [ "$(cat "$stamp" 2>/dev/null)" != "$want" ]; then + echo "installing ${a.name}..." + tmp=$(mktemp -d) + if /usr/bin/unzip -q "$want" -d "$tmp"; then + if [ -d "$tmp/${a.app}" ]; then + rm -rf "/Applications/${a.app}" + /usr/bin/ditto "$tmp/${a.app}" "/Applications/${a.app}" + mkdir -p "${stampDir}" + echo "$want" > "$stamp" + else + echo "${a.name}: ${a.app} not found in zip, skipping" + fi + else + echo "${a.name}: could not unzip, skipping" + fi + rm -rf "$tmp" + fi + ''; +in +{ + system.activationScripts.postActivation.text = + lib.concatStringsSep "\n" ( + (map appScript apps) + ); +} diff --git a/cli-tools.nix b/cli-tools.nix new file mode 100644 index 0000000..d215a5a --- /dev/null +++ b/cli-tools.nix @@ -0,0 +1,32 @@ +{ pkgs, ... }: + +{ + environment.shellAliases = { + yt = "yt-dlp"; + ll = "ls -la"; + }; + + environment.etc."gitconfig".text = '' + [user] + name = Brian Nelson + email = brian@briannelson.dev + [init] + defaultBranch = main + ''; + + environment.etc."yt-dlp.conf".text = '' + -o /Users/briannelson/Downloads/yt-dlp/%(title)s.%(ext)s + --no-mtime + --restrict-filenames + --embed-thumbnail + --embed-metadata + --format "bestvideo[height<=1080]+bestaudio/best[height<=1080]" + --merge-output-format mp4 + ''; + + system.activationScripts.postActivation.text = '' + if [ -x /opt/homebrew/bin/defaultbrowser ]; then + sudo -u briannelson /opt/homebrew/bin/defaultbrowser librewolf || echo "could not set deffault browser, skipping" + fi + ''; +} diff --git a/configuration.nix b/configuration.nix new file mode 100644 index 0000000..0d0fc60 --- /dev/null +++ b/configuration.nix @@ -0,0 +1,65 @@ +{ pkgs, ... }: + +{ + imports = [ + ./cli-tools.nix + ./mac-settings.nix + ./pkg-installs.nix + ./archive-installs.nix + ]; + + nixpkgs.hostPlatform = "aarch64-darwin"; + + nix.settings.experimental-features = "nix-command flakes"; + + system.stateVersion = 6; + system.primaryUser = "briannelson"; + + environment.systemPackages = with pkgs; [ + exif + exiftool + ffmpeg + flac + git + helix + librewolf + tea + yt-dlp + ]; + + homebrew = { + enable = true; + onActivation = { + autoUpdate = true; + cleanup = "none"; + }; + + brews = [ + "bun" + "defaultbrowser" + "harper" + "nicotine-plus" + "rust" + "ykman" + ]; + + casks = [ + "bitwarden" + "cap" + "discord" + "docker-desktop" + "harper-desktop" + "libreoffice" + "nextcloud" + "obsidian" + "protonvpn" + "rustdesk" + "signal" + "task-manager-tmog" + "twingate" + "vlc" + "vscodium" + "firefox" + ]; + }; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ee3aa92 --- /dev/null +++ b/flake.lock @@ -0,0 +1,85 @@ +{ + "nodes": { + "brew-src": { + "flake": false, + "locked": { + "lastModified": 1793000687, + "narHash": "sha256-8mCor0DDjNhi+0e+FllfqiMABujBl+/RxYW+wgMpcto=", + "owner": "Homebrew", + "repo": "brew", + "rev": "c6069d2a943b71b0a90d91fc1ac93cb9c1634dcc", + "type": "github" + }, + "original": { + "owner": "Homebrew", + "ref": "7.0.11", + "repo": "brew", + "type": "github" + } + }, + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1792800221, + "narHash": "sha256-53jIZEWNh96irEXhsMZFoNhLJgGSU3nYl1i4wFQHAsU=", + "owner": "nix-darwin", + "repo": "nix-darwin", + "rev": "d31953cf55f9027a56e9be938daf5db8c5655663", + "type": "github" + }, + "original": { + "owner": "nix-darwin", + "ref": "nix-darwin-26.05", + "repo": "nix-darwin", + "type": "github" + } + }, + "nix-homebrew": { + "inputs": { + "brew-src": "brew-src" + }, + "locked": { + "lastModified": 1793543863, + "narHash": "sha256-oDYLVD8KGT/M57c8HziYSSj0le4wCyA+jZ7+/qUS91M=", + "owner": "zhaofengli", + "repo": "nix-homebrew", + "rev": "52bc87da3f30c2261a6d1cfef3c892097b53daeb", + "type": "github" + }, + "original": { + "owner": "zhaofengli", + "repo": "nix-homebrew", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1793976852, + "narHash": "sha256-bWDN3JZcE9ovYoaD0/6WYbMtXYpUu0vd5onpK0pc/SE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "57f1c8965649ce5bcac5118a0d2e41f1fbdc56e5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-26.05-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nix-darwin": "nix-darwin", + "nix-homebrew": "nix-homebrew", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..28cc09b --- /dev/null +++ b/flake.nix @@ -0,0 +1,26 @@ +{ + description = "Brian's macOS nix-darwin configuration"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-26.05-darwin"; + nix-darwin.url = "github:nix-darwin/nix-darwin/nix-darwin-26.05"; + nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; + nix-homebrew.url = "github:zhaofengli/nix-homebrew"; + }; + + outputs = inputs@{ self, nix-darwin, nixpkgs, nix-homebrew, ... }: { + darwinConfigurations."Brians-MacBook-Air" = nix-darwin.lib.darwinSystem { + modules = [ + ./configuration.nix + nix-homebrew.darwinModules.nix-homebrew + { + nix-homebrew = { + enable = true; + enableRosetta = true; + user = "briannelson"; + }; + } + ]; + }; + }; +} diff --git a/mac-settings.nix b/mac-settings.nix new file mode 100644 index 0000000..36bf87a --- /dev/null +++ b/mac-settings.nix @@ -0,0 +1,64 @@ +{ ... }: + +{ + system.defaults = { + NSGlobalDomain = { + AppleEnableSwipeNavigateWithScrolls = true; + AppleIconAppearanceTheme = "RegularDark"; + AppleInterfaceStyle = "Dark"; + NSDocumentSaveNewDocumentsToCloud = false; + NSNavPanelExpandedStateForSaveMode = true; + NSNavPanelExpandedStateForSaveMode2 = true; + "com.apple.trackpad.enableSecondaryClick" = true; + }; + + controlcenter = { + AirDrop = true; + Bluetooth = true; + Sound = true; + }; + + dock = { + autohide = true; + largesize = 40; + magnification = true; + mineffect = "scale"; + minimize-to-application = true; + # This is all an example of how to set the apps in the Dock. + # The key is to remember to update this before rebuilding. + # I may move this item to another file to keep things clean. + # persistent-apps = [ + # { + # app = "/Applications/Safari.app"; + # } + # { + # spacer = { + # small = true; + # }; + # } + # { + # folder = "/System/Applications/Utilities"; + # } + # { + # file = "/User/example/Downloads/test.csv"; + # } + # ] + wvous-br-corner = 11; # Launchpad or Apps + wvous-tl-corner = 13; # lock screen + }; + + finder = { + AppleShowAllExtensions = true; + AppleShowAllFiles = true; + FXPreferredViewStyle = "clmv"; + ShowPathbar = true; + }; + + magicmouse.MouseButtonMode = "TwoButton"; + + trackpad = { + TrackpadPinch = true; + TrackpadRightClick = true; + }; + }; +} diff --git a/pkg-installs.nix b/pkg-installs.nix new file mode 100644 index 0000000..3fb8342 --- /dev/null +++ b/pkg-installs.nix @@ -0,0 +1,33 @@ +{ pkgs, lib, ... }: + +let + # Add one entry per program you want to install from a .pkg file + pkgInstalls = [ + { + name = "cupsadmin"; + url = "https://github.com/kfattic/cupsadmin/releases/download/v1.4.1/cupsadmin-1.4.1.pkg"; + hash = "sha256-DyIyDYSjAlcU7ivyfldMapIZw5nczEBXfnLicnK6k7Y="; + } + ]; + + installScript = p: + let + src = pkgs.fetchurl { inherit (p) url hash; }; + in '' + stamp="/usr/local/share/nix-pkg-stamps/${p.name}" + want="${src}" + if [ "$(cat "$stamp" 2>/dev/null)" != "$want" ]; then + echo "installing ${p.name}..." + if /usr/sbin/installer -pkg "$want" -target /; then + mkdir -p /usr/local/share/nix-pkg-stamps + echo "$want" > "$stamp" + else + echo "${p.name} install failed, skipping" + fi + fi + ''; +in +{ + system.activationScripts.postActivation.text = + lib.concatMapStringsSep "\n" installScript pkgInstalls; +}