Setup NixOS Server on Oracle Cloud
oci session authenticate #authenticate and create a profile "terraform"
terraform init
# for dev environment
terraform workspace new dev
terraform workspace select dev
# for prod environment
terraform workspace new prod
terraform workspace select prod
# for getting a general compute instance(ubuntu)
terraform apply
# cleanup
terraform destroy
# for converting the created instance into nixos directly, creating ansible inventory file with terraform and Dynamically update DNS records at NameCheap
terraform apply '-var=setup=true' '-var=rebuild=true' '-var=nixos_flake=github:<username>/<repo>/<branch>#<machine>' '-var=ddns=true' '-var=namecheap_api_key=<namecheap_api_key>' '-var=domain=<domain>' '-var=subdomains="*,@"'
# Run solo modules
terraform apply -target=module.ansible #First step always as rest use the inventory.ini file generated as config
terraform apply -target=module.setup '-var=setup=true'
# Note for below to work you will have to enable Dynamic DNS at NameCheap and create the "*,@" subdomains as 'A + Dynamic DNS Record'
terraform apply -target=module.ddns '-var=ddns=true' '-var=namecheap_api_key=<namecheap_api_key>' '-var=domain=<domain>' '-var=subdomains="*,@"'
# For rebuilding
terraform apply -target=module.rebuild '-var=rebuild=true' '-var=nixos_flake=github:<username>/<repo>/<branch>#<machine>' #Can be used by OCI auth may timeout if it takes time
# Better approach
nixos-rebuild --target-host root@<instance_ip> switch --flake 'github:<username>/<repo>/<branch>#<machine>' --fast --impure --refresh
- Modify
terraform.tfvars
andvariables.tf
files as per the need/account
# Authentication
tenancy_ocid = "<your_tenacy_ocid>"
# Compartment
compartment_ocid = "<your_compartment_ocid>"
# ssh keys
ssh_public_key = "<absolute_path_to_your_public_key>"
ssh_private_key = "<absolute_path_to_your_private_key>"
- Setting '-var=<module_name>=true' is needed for 'terraform apply' to work solo in a clean way for default OS instance
- By default ingress rules for port 22, 80, 443 are added