1
0
Fork 0
nix-configuration/hosts/Haven/default.nix

145 lines
3.9 KiB
Nix
Raw Normal View History

{
pkgs,
home-manager,
lib,
config,
...
}:
2024-02-29 09:53:34 -05:00
let
start-haven = pkgs.writeShellScriptBin "start-haven" (builtins.readFile ./start-haven.sh);
subdomains = map (subdomain: subdomain + ".${config.secrets.networking.primaryDomain}") [
"code"
"music"
];
2024-02-29 09:53:34 -05:00
in
{
imports = [ ./hardware-configuration.nix ];
system.stateVersion = "24.05";
system.autoUpgrade.enable = lib.mkForce false;
2024-02-29 09:53:34 -05:00
host = {
role = "server";
apps.development.kubernetes.enable = true;
services = {
apcupsd.enable = true;
airsonic = {
enable = true;
domain = config.secrets.networking.primaryDomain;
home = "/storage/services/airsonic-advanced";
};
duplicacy-web = {
enable = true;
autostart = false;
environment = "${config.users.users.aires.home}";
};
forgejo = {
enable = true;
domain = config.secrets.networking.primaryDomain;
home = "/storage/services/forgejo";
};
msmtp.enable = true;
};
users = {
aires = {
enable = true;
services.syncthing = {
enable = true;
autostart = false;
};
};
media.enable = true;
};
};
2024-02-29 09:53:34 -05:00
# TLS certificate renewal via Let's Encrypt
security.acme = {
acceptTerms = true;
2024-05-20 09:37:30 -04:00
defaults.email = "${config.secrets.users.aires.email}";
certs."${config.secrets.networking.primaryDomain}" = {
dnsProvider = "namecheap";
extraDomainNames = subdomains;
2024-05-20 09:37:30 -04:00
webroot = null; # Required in order to prevent a failed assertion
credentialFiles = {
"NAMECHEAP_API_USER_FILE" = "${pkgs.writeText "namecheap-api-user" ''
${config.secrets.networking.namecheap.api.user}
''}";
"NAMECHEAP_API_KEY_FILE" = "${pkgs.writeText "namecheap-api-key" ''
${config.secrets.networking.namecheap.api.key}
''}";
};
};
2024-05-17 18:18:47 -04:00
};
# /var/lib/acme/.challenges must be writable by the ACME user
# and readable by the Nginx user. The easiest way to achieve
# this is to add the Nginx user to the ACME group.
users.users.nginx.extraGroups = [ "acme" ];
2024-05-17 18:18:47 -04:00
services = {
nginx = {
enable = true;
2024-02-29 09:53:34 -05:00
# Use recommended settings per https://nixos.wiki/wiki/Nginx#Hardened_setup_with_TLS_and_HSTS_preloading
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedTlsSettings = true;
virtualHosts = {
# Base URL: make sure we've got Let's Encrypt running challenges here, and all other requests going to HTTPS
"${config.secrets.networking.primaryDomain}" = {
default = true;
enableACME = true;
2024-05-20 09:37:30 -04:00
# Catchall vhost, will Redirect users to Forgejo
locations."/" = {
2024-05-20 09:37:30 -04:00
return = "301 https://code.${config.secrets.networking.primaryDomain}";
};
};
};
};
# Enable BOINC (distributed research computing)
boinc = {
enable = true;
package = pkgs.boinc-headless;
dataDir = "/var/lib/boinc";
extraEnvPackages = [ pkgs.ocl-icd ];
};
# Enable SSH
openssh = {
enable = true;
ports = [ config.secrets.hosts.haven.ssh.port ];
settings = {
2024-05-20 09:37:30 -04:00
# require public key authentication and disable root logins
PasswordAuthentication = false;
KbdInteractiveAuthentication = false;
PubkeyAuthentication = true;
2024-05-20 09:37:30 -04:00
PermitRootLogin = "no";
};
};
# TODO: VPN (Check out Wireguard)
};
2024-02-29 09:53:34 -05:00
# Nginx: Disable autostart, and start sub-services first.
systemd.services.nginx.wantedBy = lib.mkForce [ ];
# Open ports
networking.firewall = {
enable = true;
allowedTCPPorts = [
80
443
];
};
# Add Haven's startup script
environment.systemPackages = [ start-haven ];
# Allow Haven to be a build target for other architectures (mainly ARM64)
boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
}