Lots more updates
Also begin adding rust building capabilities to be able to write rust binaries for some commands.
This commit is contained in:
parent
624508dd14
commit
dd1cfa79e7
52 changed files with 2509 additions and 150 deletions
|
@ -19,8 +19,8 @@ in
|
|||
domain = if hostname == cfg then null else (lib.strings.removePrefix "${hostname}." cfg);
|
||||
in
|
||||
{
|
||||
networking.hostName = hostname;
|
||||
networking.domain = domain;
|
||||
networking.hostName = lib.mkForce hostname;
|
||||
networking.domain = lib.mkForce domain;
|
||||
boot.kernel.sysctl = {
|
||||
"kernel.hostname" = cfg;
|
||||
};
|
||||
|
|
|
@ -6,12 +6,8 @@
|
|||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.khscodes.terraform-hetzner;
|
||||
cfg = config.khscodes.hetzner-instance;
|
||||
fqdn = config.khscodes.fqdn;
|
||||
hostPkgs = import inputs.nixpkgs {
|
||||
system = pkgs.buildPlatform.system;
|
||||
overlays = [ inputs.self.overlays.bitwarden-cli ];
|
||||
};
|
||||
firewallTcpRules = lib.lists.map (p: {
|
||||
direction = "in";
|
||||
protocol = "tcp";
|
||||
|
@ -41,7 +37,6 @@ let
|
|||
};
|
||||
firewallRules = firewallTcpRules ++ firewallUdpRules ++ firewallIcmpRules ++ cfg.extraFirewallRules;
|
||||
firewallEnable = config.networking.firewall.enable;
|
||||
mapRdns = cfg.mapRdns;
|
||||
tldFromFqdn =
|
||||
fqdn:
|
||||
let
|
||||
|
@ -53,8 +48,8 @@ let
|
|||
lib.strings.removePrefix "${builtins.head split}." fqdn;
|
||||
in
|
||||
{
|
||||
options.khscodes.terraform-hetzner = {
|
||||
enable = lib.mkEnableOption "enables generating a terraform config";
|
||||
options.khscodes.hetzner-instance = {
|
||||
enable = lib.mkEnableOption "enables generating a opentofu config";
|
||||
dnsNames = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
description = "DNS names for the server";
|
||||
|
@ -72,7 +67,7 @@ in
|
|||
"bitwarden"
|
||||
"vault"
|
||||
];
|
||||
description = "Whether to load terraform secrets from Bitwarden or Vault";
|
||||
description = "Whether to load opentofu secrets from Bitwarden or Vault";
|
||||
default = "vault";
|
||||
};
|
||||
datacenter = lib.mkOption {
|
||||
|
@ -146,95 +141,102 @@ in
|
|||
labels = {
|
||||
app = fqdn;
|
||||
};
|
||||
config = inputs.terranix.lib.terranixConfiguration {
|
||||
system = pkgs.hostPlatform.system;
|
||||
modules = [
|
||||
(
|
||||
{ config, ... }:
|
||||
{
|
||||
imports = [
|
||||
inputs.self.terranixModules.cloudflare
|
||||
inputs.self.terranixModules.hcloud
|
||||
];
|
||||
config = {
|
||||
terraform.backend.s3 = {
|
||||
bucket = "bw-terraform";
|
||||
key = cfg.bucket.key;
|
||||
region = "auto";
|
||||
endpoints = {
|
||||
s3 = "https://477b394a6a545699445c40953e40f00b.r2.cloudflarestorage.com";
|
||||
};
|
||||
use_path_style = true;
|
||||
skip_credentials_validation = true;
|
||||
skip_region_validation = true;
|
||||
skip_metadata_api_check = true;
|
||||
skip_requesting_account_id = true;
|
||||
skip_s3_checksum = true;
|
||||
modules = [
|
||||
(
|
||||
{ config, ... }:
|
||||
{
|
||||
imports = [
|
||||
inputs.self.terranixModules.cloudflare
|
||||
inputs.self.terranixModules.hcloud
|
||||
];
|
||||
config = {
|
||||
terraform.backend.s3 = {
|
||||
bucket = "bw-terraform";
|
||||
key = cfg.bucket.key;
|
||||
region = "auto";
|
||||
endpoints = {
|
||||
s3 = "https://477b394a6a545699445c40953e40f00b.r2.cloudflarestorage.com";
|
||||
};
|
||||
use_path_style = true;
|
||||
skip_credentials_validation = true;
|
||||
skip_region_validation = true;
|
||||
skip_metadata_api_check = true;
|
||||
skip_requesting_account_id = true;
|
||||
skip_s3_checksum = true;
|
||||
};
|
||||
|
||||
khscodes.hcloud.data.ssh_key.khs = {
|
||||
name = "ca.kaareskovgaard.net";
|
||||
};
|
||||
khscodes.hcloud.enable = true;
|
||||
khscodes.hcloud.server.compute = {
|
||||
inherit (cfg) server_type datacenter;
|
||||
inherit labels;
|
||||
name = fqdn;
|
||||
initial_image = "debian-12";
|
||||
rdns = fqdn;
|
||||
ssh_keys = [ config.khscodes.hcloud.output.data.ssh_key.khs.id ];
|
||||
};
|
||||
khscodes.cloudflare = {
|
||||
khscodes.hcloud.data.ssh_key.khs = {
|
||||
name = "ca.kaareskovgaard.net";
|
||||
};
|
||||
khscodes.hcloud.enable = true;
|
||||
khscodes.hcloud.server.compute = {
|
||||
inherit (cfg) server_type datacenter;
|
||||
inherit labels;
|
||||
name = fqdn;
|
||||
initial_image = "debian-12";
|
||||
rdns = fqdn;
|
||||
ssh_keys = [ config.khscodes.hcloud.output.data.ssh_key.khs.id ];
|
||||
};
|
||||
khscodes.cloudflare = {
|
||||
enable = true;
|
||||
dns = {
|
||||
enable = true;
|
||||
dns = {
|
||||
enable = true;
|
||||
zone_name = tldFromFqdn fqdn;
|
||||
aRecords = [
|
||||
{
|
||||
inherit fqdn;
|
||||
content = config.khscodes.hcloud.output.server.compute.ipv4_address;
|
||||
}
|
||||
];
|
||||
aaaaRecords = [
|
||||
{
|
||||
inherit fqdn;
|
||||
content = config.khscodes.hcloud.output.server.compute.ipv6_address;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
resource.hcloud_firewall.fw = lib.mkIf firewallEnable {
|
||||
inherit labels;
|
||||
name = fqdn;
|
||||
apply_to = {
|
||||
server = config.khscodes.hcloud.output.server.compute.id;
|
||||
};
|
||||
rule = firewallRules;
|
||||
};
|
||||
output.ipv4_address = {
|
||||
value = config.khscodes.hcloud.output.server.compute.ipv4_address;
|
||||
sensitive = false;
|
||||
};
|
||||
|
||||
output.ipv6_address = {
|
||||
value = config.khscodes.hcloud.output.server.compute.ipv6_address;
|
||||
sensitive = false;
|
||||
zone_name = tldFromFqdn fqdn;
|
||||
aRecords = [
|
||||
{
|
||||
inherit fqdn;
|
||||
content = config.khscodes.hcloud.output.server.compute.ipv4_address;
|
||||
}
|
||||
];
|
||||
aaaaRecords = [
|
||||
{
|
||||
inherit fqdn;
|
||||
content = config.khscodes.hcloud.output.server.compute.ipv6_address;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
];
|
||||
};
|
||||
resource.hcloud_firewall.fw = lib.mkIf firewallEnable {
|
||||
inherit labels;
|
||||
name = fqdn;
|
||||
apply_to = {
|
||||
server = config.khscodes.hcloud.output.server.compute.id;
|
||||
};
|
||||
rule = firewallRules;
|
||||
};
|
||||
output.ipv4_address = {
|
||||
value = config.khscodes.hcloud.output.server.compute.ipv4_address;
|
||||
sensitive = false;
|
||||
};
|
||||
|
||||
output.ipv6_address = {
|
||||
value = config.khscodes.hcloud.output.server.compute.ipv6_address;
|
||||
sensitive = false;
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
];
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
{
|
||||
assertion = config.khscodes.fqdn != null;
|
||||
message = "Must set config.khscodes.fqdn when using terraform";
|
||||
message = "Must set config.khscodes.fqdn when using opentofu";
|
||||
}
|
||||
];
|
||||
|
||||
khscodes.terraform-hetzner.output = config;
|
||||
khscodes.provisioning.pre = {
|
||||
modules = modules;
|
||||
secretsSource = cfg.secretsSource;
|
||||
variablesNeeded = [
|
||||
"TF_VAR_cloudflare_token"
|
||||
"TF_VAR_cloudflare_email"
|
||||
"AWS_ACCESS_KEY_ID"
|
||||
"AWS_SECRET_ACCESS_KEY"
|
||||
"TF_VAR_hcloud_api_token"
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
1
nix/modules/nixos/opentofu-openbao/default.nix
Normal file
1
nix/modules/nixos/opentofu-openbao/default.nix
Normal file
|
@ -0,0 +1 @@
|
|||
{ pkgs, ... }: { }
|
63
nix/modules/nixos/provisioning/default.nix
Normal file
63
nix/modules/nixos/provisioning/default.nix
Normal file
|
@ -0,0 +1,63 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
inputs,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.khscodes.provisioning;
|
||||
provisioning = {
|
||||
modules = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.anything;
|
||||
description = "Modules used to bring up the needed resources";
|
||||
default = [ ];
|
||||
};
|
||||
secretsSource = lib.mkOption {
|
||||
type = lib.types.enum [
|
||||
"vault"
|
||||
"bitwarden"
|
||||
];
|
||||
description = "Where to get the secrets for the provisioning from";
|
||||
default = "vault";
|
||||
};
|
||||
variablesNeeded = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
description = "Needed environment variables for the provisioning";
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.khscodes.provisioning = {
|
||||
pre = provisioning;
|
||||
post = provisioning;
|
||||
preConfig = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
description = "The generated config for the pre provisioning, if any was specified";
|
||||
};
|
||||
postConfig = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
description = "The generated config for the post provisioning, if any was specified";
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
khscodes.provisioning.preConfig =
|
||||
if lib.lists.length cfg.pre.modules > 0 then
|
||||
inputs.terranix.lib.terranixConfiguration {
|
||||
system = pkgs.hostPlatform.system;
|
||||
modules = cfg.pre.modules;
|
||||
}
|
||||
else
|
||||
null;
|
||||
khscodes.provisioning.postConfig =
|
||||
if lib.lists.length cfg.post.modules > 0 then
|
||||
inputs.terranix.lib.terranixConfiguration {
|
||||
system = pkgs.hostPlatform.system;
|
||||
modules = cfg.post.modules;
|
||||
}
|
||||
else
|
||||
null;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue