/nix-config

Nix config (nix-darwin, home-manager, etc)

Primary LanguageNix

nix-config

nix-darwin, home-manager and dotfiles managed by nix.

Features

  • nix with nix flakes
  • nix-darwin
  • home-manager (via nix-darwin but could work as standalone too)
  • homebrew casks (via nix-darwin)
  • several dev-shells [WIP]

Machines

Host Hardware named after
Kare Apple Laptop Susan Kare
Hopper Apple Laptop Grace Hopper

My standard username is pw. All code will be placed in the ~/Documents/Code/weiland/ directory. Previously, all my code was stored in ~/src/weiland.

Installation

on a freshly clean mac machine

Setup machine

iCloud

During Setup:

  1. Login in to iCloud
  2. System Settings -> iCloud -> iCloud Drive: enable Desktop & Documents Folders.
  3. Disable Optimize Mac Storage for Documents (and later in Photos, too), so all data will be downloaded.

System Updates

Making sure system is up-to-date:

sudo softwareupdate --install --all --restart --verbose

Xcode and Developer Tools

Install command line developer tools:

xcode-select --install

Then, install Xcode from the App Store.

Now, accept the Xcode and SDK license:

sudo xcodebuild -license accept

And make sure Xcode runs:

sudo xcodebuild -runFirstLaunch

Open Xcode go to Preferences, open the Platforms tab and download iOS and VisioOS Simulators.

Install Rosetta

Actually, I try to avoid it, but looking at you AusweisApp.app

softwareupdate –install-rosetta

Code directories

Create code directory:

mkdir -p ~/Documents/Code/weiland
mkdir ~/Documents/Code/clones
mkdir ~/Documents/Code/tests
mkdir ~/Documents/Code/go

Clone this nix-config

On a new system, the file modes might be lost, and have to be fixed so the keys can be accessed:

chmod 600 ~/Documents/Configs/ssh/id_pw

Now we can clone. In order to prevent password prompts and because there is no ~/.ssh directory yet with key pairs, we start with a different key path:

GIT_SSH_COMMAND='ssh -i ~/Documents/Configs/ssh/id_pw -o IdentitiesOnly=yes' git clone git@github.com:weiland/nix-config.git ~/Documents/Code/weiland/nix-config
other ways to clone (if ssh keys or GitHub are already setup):
# using ssh (with default key in ~/.ssh)
git clone git@github.com:weiland/nix-config.git ~/Documents/Code/weiland/nix-config

# or using default (i.e. login to GitHub)
git clone https://github.com/weiland/nix-config.git ~/Documents/Code/weiland/nix-config
If there is no git ... (which is supposed to be there actually with ventura/sonoma and installed xcode dev-tools)

You can follow the next step and install nix and then you can create a nix shell with git installed temporarely:

nix run nixpkgs#git

# or via old nix-env command
nix-env -iA nixpkgs.git

And now cd into the newly cloned nix-config directory:

$ cd ~/Documents/Code/weiland/nix-config

Install nix package manager

Via the official nix installer:

sh <(curl -L https://nixos.org/nix/install)
Or using Determinate Nix Install / fish shell installation

Or using The Determinate Nix Installer, which performs well on mac (esp. after mac upgrades) and brings flake support by default:

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

If already in the fish shell:

sh (curl -L https://nixos.org/nix/install | psub)
Enable flakes via config file

Not needed when using my home-manager config (or the Determinate Nix installer).

mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf

Install Homebrew

It can run independently but is later controlled via nix-darwin.

bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

The brew command will ba available later after applying the home-manager settings.

Install mac with nix-darwin

This will apply the nix-darwin config and the home-manager config, so all mac default preferences will be set as well as all apps, tools and binaries will be installed.

# making sure to be in the right directory
cd ~/Documents/Code/weiland/nix-config

The following commands will install the host Hopper. Which can be replaced with any other hostname that exists in the ./hosts/ directory.

nix run --extra-experimental-features "nix-command flakes" nix-darwin -- switch --flake .#Hopper

You have to enter your sudo password (at least once, perhaps more often as longer it takes) and click on Allow when prompted.

Or if using flakes remotely:

TODO(weiland): Fix command below

nix flake --extra-experimental-features 'nix-command flakes' init -t github:weiland/nix-config#darwin

The next step is to restart the mac:

sudo reboot

Now nix-command and flakes are enabled by default, so --extra-experimental-features can be omitted.

Update / Rebuild

Run again:

nix run nix-darwin -- switch --flake .#Hopper

# for further times, one can use in any directory:
nix run nix-darwin -- switch --flake ~/.config/nix-darwin#Hopper

(Perhaps Full Disk Access is required. Enabled it in the Privacy & Security System Settings for the current Terminal.)

Finalisation / App Preferences

iterm

re-use config from data/iterm/

Set config:

$ defaults write com.googlecode.iterm2 PrefsCustomFolder "/Users/pw/Documents/Code/nix-config/data/iterm"

Alternatively:

  1. Open iterm2
  2. General -> Preferences -> check Load preferences from a custom folder or URL
  3. choose /Users/pw/Documents/Code/weiland/nix-config/data/iterm
  4. And don't overwrite the existing one.
  • Generally, allow Full Disk Access for iTerm in System Settings -> Privacy & Security
For pre Sonoma: If no directory can be selected, iterm has no access to the hard disk. This can be fixed by open `System Settings` -> Privacy & Security -> Hard Disk Access -> add _iterm2.app_.
Import a new colorscheme #### Use a different colorscheme

Set colorscheme:

open ~/Documents/Code/weiland/nix-config/data/iterm/Oceanic-Next.itermcolors

Open any other additional itermcolors-file.

Other colorschemes for iterm can be found at: https://iterm2colorschemes.com and should be downloaded to data/iterm/.

Jumpcut

  • Open & allow access (in Privacy & Security)

Rectangle

  • Open & allow access (in Privacy & Security) & choose recommended

Trackpad

  • Set Tracking Speed to Fast

Desktop & Dock

  • Click Wallpaper to reveal desktop to Only in Stage Manager

Set up fish shell

  • Import old fish history
[ -e ~/Documents/Backups/fish_history ] && cp ~/Documents/Backups/fish_history ~/.local/share/fish/fish_history
  • Import recenttracks.txt (or if new mv ~/Downloads/recenttracks-*.csv ~/.local/share/recenttracks.csv)
  • Optionally: import z history file as well (for the same host) ~/Library/Application\ Support/zoxide/db.zo

Import English Keyboard Layout with Umlauts

  • import keyboard layout
sudo cp -r data/keyboard_layout/ABC\ Extended\ German\ Umlauts.bundle /Library/Keyboard\ Layouts/
  • restart mac
  • System Settings -> Keyboard -> Input Sources -> Edit -> + -> Others

1Password

  • Allow Accessibility Settings (required for FF Browser extension to work)

Firefox Developer Edition

Internet Accounts / Mail

  • Login to email accounts

Fantastical

  • Login via Apple (try a few times)
  • add main calendar account.
  • turn off notification from other calendars
  • show calendar week numbers
  • uncheck Go to today after adding items in Advanced Settings 🤯

Finder Sidebar

  • Adjust items in Finder sidebar to: Recents, Documents, Applications, Downloads, home, TU Darmstadt
  • hide tags
  • Make sure filename extensions are shown.

Messages

  • Edit -> Substitutions -> uncheck Emoji Substitutions
  • Start new messages from certain email (same goes for FaceTime)
To receive text messages on this mac device. On the iPhone: - Settings -> Messages -> Text Message Forwarding -> _Enable_ this Mac

Other apps

  • TestFlight: Download Element X
  • Element X: Login to matrix account & verify session
  • gh cli: gh auth login: choose GitHub.com, ssh and login via browser
  • Signal Beta: Login & sync
  • Telegram: Login
  • Discord: Login
  • Tealdeer: Update cache tldr --update
  • Ivory: login to all accounts (vis.social, chaos.social and det.social)
  • Reeder: Login and sync and Sort: Oldest first
  • Mela: Set the right Calendar and Reminders.
  • Dash: Download Elixir, Vue, Swift and Node docs
  • Sublime Text: Tools -> Install Package Control
  • Outlook: Login and set Trans Pride Theme
  • Slack: Login
  • Discord: Login
  • Spotify: Under Display Preferences, disable now-playing panel
  • Spotify: Disable the Song change notifications

Hosts

Siri / Voice

  • Download the good Siri Voices for VoiceOver etc (Dansk, Norsk, French, German and English)

Wallpapers and Screensavers

  • Choose nice views

Uninstall unused apps

  • Remove GarageBand and iMovie
  • System Settings -> General -> Storage -> Remove Audio lib (from Garage Band)

Apple Wallet

  • set up cards, address and hide email

Import files from other/old device

via ssh using rsync:
# copy with archive and compress option
rsync -avz -e ssh old@device.local:~/Downloads ~/Downloads

# copying web projects but skipping node modules
rsync -avz -e ssh old@device.local:~/src ~/src --exclude node_modules

Or use Finder for external hard drives or AirDrop.

Wrapping up

Disk encryption

should be turned on by default

  • System Settings -> Privacy & Security -> Turn On FileVault

  • Also, make sure that Find My Mac is enabled under Apple ID_ -> iCloud.

Time Machine

  • Make sure excluded paths are set (General -> Time Machine)
  • Plug in external hard drive and set the right volume

Testing and verification

  • system works after restart
  • fish is default shell in iTerm
  • git user is correct
  • git commits work
  • git push via ssh work

Updates

Keeping nix and their friends up to date

# in nix-config directory
nix flake update

# from somewhere else
nix flake update --flake ~/Documents/Code/weiland/nix-config

Housekeeping

Code formatting

Formatting nix files:

nix fmt # using nixfmt-rfc-style

Backup for a new machine

  • Downloads and Desktop are empty
  • Documents and Photos are all synced (and uploaded)
  • sync Firefox (on another device, i.e. Phone, Tablet other computer) and Firefox Containers
  • backup fish history cp ~/.local/share/fish/fish_history ~/Documents/Backups
  • zoxide history (optional) cp ~/Library/Application\ Support/zoxide/db.zo ~/Documents/Backups
  • export crontab crontab -l >> ~/Documents/Backups/crontab
  • backup recenttracks cp ~/.local/share/recenttracks.csv ~/Documents/Backups/recenttracks.csv (or download new one)
  • manually installed fonts (via Font Book)
  • PhotoBooth photos
  • VS Code settings and extensions
  • optional: leftover Screenshots (in ~/tmp)
  • make a full time machine backup
  • make sure everything in ~/Documents/Code/ is committed and all branches are pushed (including this nix-config repo)