Skip to content

Instantly share code, notes, and snippets.

@steinybot
Last active January 26, 2022 20:50
Show Gist options
  • Save steinybot/085ef82571f4416506388c6a1e58637a to your computer and use it in GitHub Desktop.
Save steinybot/085ef82571f4416506388c6a1e58637a to your computer and use it in GitHub Desktop.
New MacBook Setup

New MacBook Setup

For the automated setup run:

sh <(curl -L https://gist.githubusercontent.com/steinybot/085ef82571f4416506388c6a1e58637a/raw/9d71a417534813082fd02a4820eff92420c45040/bootstrap.sh)

For the manual setup follow the steps below:

Install Nix

Install Nix

Setup NIX_PATH

Something dumb happens with Nix where on non-NixOS OSes the NIX_PATH is not set (which is fine). There is a default defined in eval.cc but for whatever reason it doesn't work.

See NixOS/nixpkgs#149791 and nix-community/home-manager#2564.

To workaround this:

  1. Add this to ~/.bash_profile:

    [[ -f "${HOME}/.export" ]] && source "${HOME}/.export"
    
  2. Add this to ~/.zshenv:

    [[ -f "${HOME}/.export" ]] && source "${HOME}/.export"
    
  3. Add this to ~/.export:

    # Set NIX_PATH explicitly to work around https://github.com/NixOS/nixpkgs/issues/149791.
    # The path is the same as the default when NIX_PATH is not set (https://github.com/NixOS/nix/blob/master/src/libexpr/eval.cc).
    NIX_STATE_DIR="/nix/var/nix"
    export NIX_PATH="${NIX_PATH:-${HOME}/.nix-defexpr/channels:nixpkgs=${NIX_STATE_DIR}/profiles/per-user/root/channels/nixpkgs:${NIX_STATE_DIR}/profiles/per-user/root/channels}"
    

Add Channels

nix-channel --add https://github.com/LnL7/nix-darwin/archive/master.tar.gz darwin
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
nix-channel --update

Install nix-darwin module

Backup your previous /etc/nix/nix.conf file:

sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.backup

Install nix-darwin module:

nix-shell '<darwin>' -A install
darwin-rebuild switch

Install Home Manager

Install Home Manager:

nix-shell '<home-manager>' -A install
home-manager switch
#!/usr/bin/env sh
# This script bootstraps a new macOS machine.
{ # Prevent execution if this script was only partially downloaded.
# Install Nix.
# See https://nixos.org/download.html#nix-install-macos.
#sh <(curl -L https://nixos.org/nix/install)
# Continue the rest of the install in a new shell.
sh <(curl -L https://gist.githubusercontent.com/steinybot/085ef82571f4416506388c6a1e58637a/raw/a399a08de29dc188c23b07b28cd2ba5e12b08c56/setup.sh)
} # End of wrapping.
#!/usr/bin/env sh
# This script continues the bootstrap setup of a new macOS machine.
{ # Prevent execution if this script was only partially downloaded.
echo hello
} # End of wrapping.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment