Skip to content

Instantly share code, notes, and snippets.

@hicksca
Created October 9, 2024 02:03
Show Gist options
  • Save hicksca/7bc67e44e40e62b314e5a8f9b88f3bd8 to your computer and use it in GitHub Desktop.
Save hicksca/7bc67e44e40e62b314e5a8f9b88f3bd8 to your computer and use it in GitHub Desktop.
Makefile for Orbstack nix machine config
orbctlPath := /usr/local/bin/orbctl
machineName := nix-automation-test
image := nixos:unstable
srcConfigDir := /Users/cah/code/github.com/dotfiles/nix
vmConfigDir := /etc/nixos
.PHONY: all createMachine removeMachine configureNixos
all: createMachine configureNixos
createMachine:
@if [ "$$(uname)" != "Darwin" ]; then \
echo "Error: This script is intended to run on macOS only."; \
exit 1; \
fi
@if command -v $(orbctlPath) >/dev/null 2>&1; then \
echo "Orbstack is installed."; \
else \
echo "Error: Orbstack (orbctl) is not installed."; \
exit 1; \
fi
@if $(orbctlPath) list | grep -q "$(machineName)"; then \
echo "Error: Machine $(machineName) already exists."; \
exit 1; \
else \
echo "Creating NixOS machine: $(machineName)..."; \
$(orbctlPath) create $(image) $(machineName); \
echo "Machine $(machineName) created successfully."; \
fi
removeMachine:
@if $(orbctlPath) list | grep -q "$(machineName)"; then \
echo "Removing machine: $(machineName)..."; \
$(orbctlPath) delete $(machineName) -f; \
echo "Machine $(machineName) removed successfully."; \
else \
echo "Error: Machine $(machineName) does not exist."; \
fi
configureNixos:
@echo "Running configuration on the VM using orbctl run..."
$(orbctlPath) run sudo rm -f $(vmConfigDir)/configuration.nix
$(orbctlPath) run sudo cp $(srcConfigDir)/* $(vmConfigDir)/
@echo "Applying NixOS configuration..."
$(orbctlPath) run sudo nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
$(orbctlPath) run sudo nix-channel --update
$(orbctlPath) run sudo nixos-rebuild switch
infocmp -x | ssh $(machineName)@orb -- tic -x -
@echo "NixOS configuration completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment