Last active
August 27, 2021 18:30
-
-
Save jrolfs/c367ffa852c3cc61429fb8295fc1a56a to your computer and use it in GitHub Desktop.
Machine bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
home := $${HOME} | |
shell := /bin/bash | |
nix := /nix/var/nix | |
nix_darwin := /run | |
brew := /opt/homebrew | |
key := id_ed25519 | |
public_key := .ssh/$(key).pub | |
github_key := .ssh/github.txt | |
github_remote_root := [email protected]:jrolfs | |
homeshick_remote := git://github.com/andsens/homeshick.git | |
neovim_remote := $(github_remote_root)/neovim.git | |
private_remote := $(github_remote_root)/private.git | |
macos_remote := $(github_remote_root)/macos.git | |
dot_remote := $(github_remote_root)/dot.git | |
homeshick_repo_root := .homesick/repos | |
homeshick_repo := $(homeshick_repo_root)/homeshick | |
neovim_repo := $(homeshick_repo_root)/neovim | |
private_repo := $(homeshick_repo_root)/private | |
macos_repo := $(homeshick_repo_root)/macos | |
dot_repo := $(homeshick_repo_root)/dot | |
link := .nixpkgs/darwin-configuration.nix | |
homeshick_runtime := source $(homeshick_repo)/homeshick.sh | |
# | |
# dotfile repos | |
main: $(nix_darwin) | |
$(link): $(dot_repo) $(macos_repo) $(neovim_repo) $(private_repo) | |
$(homeshick_runtime) && homeshick link | |
$(neovim_repo): $(homeshick_repo) | |
$(homeshick_runtime) && homeshick clone -b $(neovim_remote) | |
$(private_repo): $(homeshick_repo) | |
$(homeshick_runtime) && homeshick clone -b $(private_remote) | |
$(macos_repo): $(homeshick_repo) | |
$(homeshick_runtime) && homeshick clone -b $(macos_remote) | |
$(dot_repo): $(homeshick_repo) | |
$(homeshick_runtime) && homeshick clone -b $(dot_remote) | |
# | |
# homeshick | |
$(homeshick_repo): $(github_key) | |
git clone $(homeshick_remote) $(homeshick_repo) | |
# | |
# ssh key | |
$(github_key): $(public_key) | |
echo "pat:"; \ | |
read github_pat; \ | |
curl -H "Authorization: token $$github_pat" \ | |
-d "{ \"title\": \"bootstrap $$(hostname -s)\", \"key\": \"$$(cat $(public_key))\" }" \ | |
https://api.github.com/user/keys > $(github_key) | |
$(public_key): $(nix) | |
hostname=$$(hostname -s | tr '[:upper:]' '[:lower:]'); \ | |
ssh-keygen -t ed25519 -C "jamie.rolfs+bootstrap-$$[email protected]" | |
# | |
# Brew | |
$(brew): | |
/bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
# | |
# Nix | |
$(nix): $(brew) | |
curl -L https://nixos.org/nix/install | sh -s -- --darwin-use-unencrypted-nix-store-volume --daemon | |
$(nix_darwin): $(link) | |
sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.before-darwin | |
nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer | |
./result/bin/darwin-installer | |
# | |
# clean | |
clean: clean_nix_darwin clean_nix clean_brew clean_dot | |
echo "cleaned all." | |
clean_nix_darwin: | |
nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A uninstaller | |
./result/bin/darwin-uninstaller | |
clean_nix: | |
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist | |
sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist | |
sudo mv /etc/bashrc.backup-before-nix /etc/bashrc | |
sudo mv /etc/zshrc.backup-before-nix /etc/zshrc | |
sudo rm -rf /etc/nix /nix /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels /Users/jamie/.nix-profile /Users/jamie/.nix-defexpr /Users/jamie/.nix-channels | |
clean_brew: | |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" | |
clean_dot: | |
rm -rf .ssh | |
rm -rf .homesick | |
# | |
# placeholder targets | |
.phony: clean clean_dot clean_nix clean_nix_darwin clean_brew |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment