working with nixos-infect

This commit is contained in:
Adriano Caloiaro 2024-12-01 18:10:17 -07:00
parent 13684a8dbe
commit 5fe61acbac
No known key found for this signature in database
GPG key ID: C2BC56DE73CE3F75
10 changed files with 88 additions and 98 deletions

View file

@ -34,7 +34,7 @@ resource "hcloud_server" "nodes" {
name = "sfos-${count.index}"
image = "ubuntu-22.04" # This is the _initial_ OS installed on the nodes. NixOS is installed over this later
server_type = var.compute_provider_node_type
location = var.compute_provider_region
location = var.compute_provider_location
ssh_keys = [hcloud_ssh_key.admin.id]
labels = {
"sfos" : true
@ -72,7 +72,7 @@ resource "hcloud_server_network" "sfos_network" {
resource "hcloud_network_subnet" "private_subnet" {
network_id = hcloud_network.sfos_private.id
type = "cloud"
network_zone = "us-east" // See https://docs.hetzner.com/cloud/general/locations location names
network_zone = var.compute_provider_region
ip_range = var.internal_cidr_block
}

View file

@ -0,0 +1,4 @@
output "ip_addresses" {
value = hcloud_server.nodes.*.ipv4_address
}

View file

@ -33,6 +33,7 @@ resource "linode_instance" "sfos" {
label = "sfos-${count.index}"
tags = ["sfos"]
region = var.compute_provider_region
location = var.compute_provider_location
type = var.compute_provider_node_type
image = "linode/ubuntu22.04"
authorized_keys = [linode_sshkey.sfos_admin.ssh_key]

View file

@ -6,3 +6,6 @@ users:
shell: /bin/bash
ssh_authorized_keys:
- ${ admin_ssh_public_key }
runcmd:
- curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | PROVIDER=hetznercloud NIX_CHANNEL=nixos-23.05 bash 2>&1 | tee /tmp/infect.log

View file

@ -1,7 +1,7 @@
terraform {
backend "s3" {
bucket = "mycorp"
key = "sfos/sfos-cluster.tfstate"
key = "sfos/sfos-cluster-new2.tfstate"
region = "us-east-1"
endpoints = {
s3 = "https://us-east-1.linodeobjects.com"
@ -21,16 +21,13 @@ terraform {
}
}
provider "tailscale" {
api_key = "my_api_key"
tailnet = "example.com"
}
module "compute_provider" {
source = "./compute_providers/linode"
source = "./compute_providers/hetzner"
compute_provider_access_token = var.compute_provider_access_token
compute_provider_node_type = var.compute_provider_node_type
compute_provider_region = var.compute_provider_region
compute_provider_location = var.compute_provider_location
admin_ssh_public_key = var.admin_ssh_public_key
tailscale_auth_key = var.tailscale_auth_key
}

View file

@ -14,14 +14,6 @@
cleanOnBoot = true;
useTmpfs = true;
};
loader = {
efi.canTouchEfiVariables = true;
systemd-boot = {
enable = true;
configurationLimit = 20;
};
};
};
environment = {

View file

@ -7,34 +7,17 @@
./hardware-configuration.nix
./disko-config.nix
# ../../modules/common/qemu.nix
# ../common/base-system.nix
# ../../common/nix.nix
# ../common/podman.nix
# ../common/incus.nix
../common/base-system.nix
../../common/nix.nix
../common/podman.nix
../common/incus.nix
];
# boot.loader.grub.enable = true;
# boot.loader.systemd-boot.enable = lib.mkForce false;
# boot.loader.grub = {
# devices = ["/dev/sda"];
# extraEntries = ''
# search --set=root --fs-label disk-disk1-ESP
# '';
# };
# boot.loader.grub.device = "/dev/sda";
boot = {
supportedFilesystems = ["btrfs" "ntfs" "vfat" "ext4"];
loader.grub = {
enable = true;
forceInstall = true;
useOSProber = true;
# device = "/dev/sda";
extraGrubInstallArgs = ["--modules=nativedisk ahci pata part_gpt part_msdos diskfilter mdraid1x lvm ext2"];
fsIdentifier = "label";
# extraEntries = ''
# search --set=root --fs-label disk-disk1-ESP
# '';
device = "/dev/sda";
};
};
users.users.sfos = {
@ -62,10 +45,10 @@
};
};
services.openssh.enable = true;
# sfos.incus = {
# enable = true;
# admin-users = ["sfos"];
# };
sfos.incus = {
enable = true;
admin-users = ["sfos"];
};
services.tailscale.enable = true;
system.stateVersion = "24.05";
}

View file

@ -1,31 +1,31 @@
# Example to create a bios compatible gpt partition
{
disko.devices = {
disk = {
main = {
device = "/dev/sda";
type = "disk";
content = {
type = "gpt";
partitions = {
boot = {
size = "1M";
type = "EF02"; # for grub MBR
};
root = {
size = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
};
};
};
};
};
};
}
# {
# disko.devices = {
# disk = {
# main = {
# device = "/dev/sda";
# type = "disk";
# content = {
# type = "gpt";
# partitions = {
# boot = {
# size = "1M";
# type = "EF02"; # for grub MBR
# };
# root = {
# size = "100%";
# content = {
# type = "filesystem";
# format = "ext4";
# mountpoint = "/";
# };
# };
# };
# };
# };
# };
# };
# }
# {
# disko.devices = {
# disk = {
@ -129,34 +129,34 @@
# };
# };
# }
# {
# disko.devices = {
# disk = {
# sda = {
# device = "/dev/sda";
# type = "disk";
# content = {
# type = "table";
# format = "msdos";
# partitions = [
# {
# name = "root";
# part-type = "primary";
# start = "1M";
# end = "100%";
# bootable = true;
# content = {
# type = "filesystem";
# format = "ext4";
# mountpoint = "/";
# };
# }
# ];
# };
# };
# };
# };
# }
{
disko.devices = {
disk = {
sda = {
device = "/dev/sda";
type = "disk";
content = {
type = "table";
format = "msdos";
partitions = [
{
name = "root";
part-type = "primary";
start = "1M";
end = "100%";
bootable = true;
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
}
];
};
};
};
};
}
# {lib, ...}: {
# disko.devices = {
# disk.disk1 = {

View file

@ -35,6 +35,10 @@ variable "compute_provider_region" {
description = "Your compute provider's name for the region in which to provision nodes"
}
variable "compute_provider_location" {
description = "Your compute provider's name for the location inside the region in which to provision nodes"
}

View file

@ -15,8 +15,9 @@ TF_VAR_tailscale_auth_key=<TF_VAR_tailscale_auth_key>
# Access token for accessing your compute provider's provisioning API
# Below is hetzner
#export TF_VAR_compute_provider_access_token=<TF_VAR_compute_provider_access_token>
export TF_VAR_compute_provider_access_token=<TF_VAR_compute_provider_access_token>
# Linode
# export TF_VAR_compute_provider_access_token=<TF_VAR_compute_provider_access_token>
# The SSH public key of the admin user who is able to SSH into created nodes
export TF_VAR_admin_ssh_public_key=<TF_VAR_admin_ssh_public_key>
@ -28,10 +29,15 @@ export TF_VAR_admin_ssh_public_key=<TF_VAR_admin_ssh_public_key>
# The name your compute provider uses to refer to the type of compute resource/node you're creating, e.g Hetzner 'cpx21' for CPX21 server
# Linode types can be retrieved with: linode-cli linodes types
export TF_VAR_compute_provider_node_type=<TF_VAR_compute_provider_node_type>
#Linode
# export TF_VAR_compute_provider_node_type=<TF_VAR_compute_provider_node_type>
# The region in which to create compute nodes
export TF_VAR_compute_provider_region=<TF_VAR_compute_provider_region>
# The location in the region in which to create compute nodes
export TF_VAR_compute_provider_location=<TF_VAR_compute_provider_location>
# The CIDR block for the cluster's private subnet
# export TF_VAR_internal_cidr_block="10.0.1.0/24"