ingress/configuration.nix

143 lines
3.5 KiB
Nix
Raw Normal View History

{
lib,
config,
pkgs,
2024-09-01 09:24:32 +00:00
modulesPath,
...
2024-08-22 18:48:15 +00:00
}:
let
2024-08-23 20:03:47 +00:00
ngx_http_geoip2_module = pkgs.stdenv.mkDerivation {
2024-08-22 18:48:15 +00:00
name = "ngx_http_geoip2_module-a28ceff";
src = pkgs.fetchgit {
url = "https://github.com/leev/ngx_http_geoip2_module";
rev = "445df24ef3781e488cee3dfe8a1e111997fc1dfe";
sha256 = "1h2xkxpb2nk4r3pkbzgas5rbl95i59jpa59rh94x2hyzxmzrzvv8";
};
installPhase = ''
mkdir $out
cp *.c config $out/
'';
fixupPhase = "";
};
2024-08-31 18:30:08 +00:00
instance = builtins.fromJSON (builtins.readFile "/etc/tjo.cloud/meta.json");
2024-08-22 18:48:15 +00:00
in
{
2024-08-25 15:47:41 +00:00
system.stateVersion = "24.05";
2024-09-01 09:24:32 +00:00
## FROM infrastructure/proxmox.tjo.cloud/configuration.nix
# Couldn't figure out the import to work.
2024-08-31 18:30:08 +00:00
imports = [
2024-09-01 09:24:32 +00:00
"${toString modulesPath}/profiles/qemu-guest.nix"
];
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
autoResize = true;
fsType = "ext4";
};
fileSystems."/boot" = {
device = "/dev/disk/by-label/ESP";
fsType = "vfat";
};
boot.growPartition = true;
boot.kernelParams = [ "console=ttyS0" ];
boot.loader.systemd-boot.enable = true;
boot.loader.timeout = 0;
services.qemuGuest.enable = true;
services.cloud-init = {
enable = true;
network.enable = true;
settings = lib.mkOptionDefault {
datasource = {
NoCloud = { };
ConfigDrive = { };
};
};
};
networking.useNetworkd = true;
nix.settings.experimental-features = [
"nix-command"
"flakes"
2024-08-31 18:30:08 +00:00
];
2024-09-01 09:24:32 +00:00
environment.systemPackages = [ pkgs.nginx ];
## END FROM
2024-08-31 18:30:08 +00:00
nix.nixPath = [ "nixos-config=/etc/tjo.cloud/configuration.nix" ];
2024-09-01 09:24:32 +00:00
system.autoUpgrade = {
enable = true;
dates = "06:00";
randomizedDelaySec = "45min";
};
2024-08-31 18:30:08 +00:00
# NETWORK
2024-08-25 15:47:41 +00:00
networking.hostName = instance.name;
networking.domain = instance.domain;
2024-08-21 21:00:23 +00:00
# USER MANAGEMENT
2024-08-24 10:13:05 +00:00
security.sudo.wheelNeedsPassword = false;
2024-08-21 21:00:23 +00:00
nix.settings.trusted-users = [ "nixos" ];
2024-08-22 18:48:15 +00:00
users.users.nixos = {
isNormalUser = true;
2024-08-24 10:13:05 +00:00
password = "hunter2";
2024-08-22 18:48:15 +00:00
extraGroups = [ "wheel" ];
2024-08-25 15:47:41 +00:00
openssh.authorizedKeys.keys = instance.ssh_keys;
2024-08-22 18:48:15 +00:00
};
2024-08-23 20:03:47 +00:00
# SSH
2024-08-21 21:00:23 +00:00
services.openssh = {
enable = true;
settings.PasswordAuthentication = false;
settings.KbdInteractiveAuthentication = false;
settings.PermitRootLogin = "no";
};
2024-08-23 20:03:47 +00:00
# TAILSCALE
services.tailscale = {
enable = true;
2024-08-31 18:30:08 +00:00
authKeyFile = "/etc/tjo.cloud/secrets/tailscale.com/authkey";
2024-08-24 22:15:57 +00:00
extraUpFlags = [
"--ssh"
"--accept-routes"
];
2024-08-23 20:03:47 +00:00
};
2024-08-24 22:15:57 +00:00
systemd.services.qemu-guest-agent.after = [ "tailscaled-autoconnect.service" ];
systemd.services.qemu-guest-agent.requires = [ "tailscaled-autoconnect.service" ];
2024-08-23 20:03:47 +00:00
# FIREWALL
networking.firewall = {
enable = true;
trustedInterfaces = [ "tailscale0" ];
allowedUDPPorts = [ config.services.tailscale.port ];
2024-08-24 10:13:05 +00:00
allowedTCPPorts = [
22
80
443
];
2024-08-23 20:03:47 +00:00
};
2024-08-21 21:00:23 +00:00
# NGINX
2024-08-22 18:48:15 +00:00
services.nginx = {
enable = true;
package = pkgs.nginx.overrideAttrs (oldAttrs: {
configureFlags = oldAttrs.configureFlags ++ [ "--add-module=${ngx_http_geoip2_module}" ];
buildInputs = oldAttrs.buildInputs ++ [ pkgs.libmaxminddb ];
});
};
# WEBHOOK
# TODO: we will have multiple instances of these,
# should they somehow broadcast changes to eachother?
# Should this be a GO service instead? With some raft mechanism?
# At that point, we could also switch from nginx to envoy or something...
services.webhook = {
enable = true;
port = 9000;
hooks = {
test = {
execute-command = "echo 'test'";
};
};
};
}