2024-12-03 23:05:57 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
2024-12-06 18:04:47 +00:00
|
|
|
namespace,
|
2024-12-03 23:05:57 +00:00
|
|
|
...
|
|
|
|
}:
|
2024-07-06 16:50:45 +00:00
|
|
|
|
2024-09-04 14:39:03 +00:00
|
|
|
let
|
|
|
|
# Do not change this value! This tracks when NixOS was installed on your system.
|
|
|
|
stateVersion = "24.11";
|
|
|
|
hostName = "Hevana";
|
2024-05-19 18:33:15 +00:00
|
|
|
|
2024-09-04 14:39:03 +00:00
|
|
|
# Where to store service files
|
2024-06-19 18:00:17 +00:00
|
|
|
services-root = "/storage/services";
|
|
|
|
|
2024-10-26 15:56:09 +00:00
|
|
|
# Credentials for interacting with the Porkbun API
|
|
|
|
porkbunCredentials = {
|
|
|
|
"PORKBUN_API_KEY_FILE" = "${pkgs.writeText "porkbun-api-key" ''
|
2024-12-09 18:30:39 +00:00
|
|
|
${config.${namespace}.secrets.networking.porkbun.api.apiKey}
|
2024-06-25 18:27:58 +00:00
|
|
|
''}";
|
2024-10-26 15:56:09 +00:00
|
|
|
"PORKBUN_SECRET_API_KEY_FILE" = "${pkgs.writeText "porkbun-secret-api-key" ''
|
2024-12-09 18:30:39 +00:00
|
|
|
${config.${namespace}.secrets.networking.porkbun.api.secretKey}
|
2024-06-25 18:27:58 +00:00
|
|
|
''}";
|
|
|
|
};
|
2024-09-04 14:39:03 +00:00
|
|
|
|
2024-12-03 23:05:57 +00:00
|
|
|
/*
|
|
|
|
Add subdomains from enabled services to TLS certificate.
|
2024-12-04 14:25:00 +00:00
|
|
|
Checks for:
|
2024-12-03 23:05:57 +00:00
|
|
|
|
|
|
|
1. Services that aren't ACME
|
2024-12-04 14:25:00 +00:00
|
|
|
2. Services with the attribute "enable = true";
|
2024-12-03 23:05:57 +00:00
|
|
|
*/
|
|
|
|
serviceList = lib.attrsets.collect (
|
2024-12-04 14:25:00 +00:00
|
|
|
x: x != "acme" && (lib.attrsets.matchAttrs { enable = true; } x)
|
2024-12-06 18:04:47 +00:00
|
|
|
) config.${namespace}.services;
|
2024-12-09 18:30:39 +00:00
|
|
|
subdomains = (builtins.catAttrs "url" serviceList) ++ [
|
2024-12-20 17:54:12 +00:00
|
|
|
config.${namespace}.secrets.hosts.gremlin-lab.URI
|
2024-12-09 18:30:39 +00:00
|
|
|
];
|
2024-12-03 23:05:57 +00:00
|
|
|
|
2024-02-29 14:53:34 +00:00
|
|
|
in
|
|
|
|
{
|
2024-05-07 22:02:59 +00:00
|
|
|
imports = [ ./hardware-configuration.nix ];
|
|
|
|
|
2024-07-06 16:50:45 +00:00
|
|
|
system.stateVersion = stateVersion;
|
|
|
|
networking.hostName = hostName;
|
2024-02-29 14:53:34 +00:00
|
|
|
|
2024-09-04 14:39:03 +00:00
|
|
|
###*** Configure your system below this line. ***###
|
2024-09-08 17:42:01 +00:00
|
|
|
|
2024-11-22 17:47:18 +00:00
|
|
|
services = {
|
|
|
|
# Enable dynamic DNS with Porkbun
|
|
|
|
ddclient = {
|
|
|
|
enable = true;
|
|
|
|
configFile = pkgs.writeText "ddclient.conf" ''
|
|
|
|
use=web, web=checkip.dyndns.com/, web-skip='IP Address'
|
|
|
|
protocol=porkbun
|
2024-12-09 18:30:39 +00:00
|
|
|
apikey=${config.${namespace}.secrets.networking.porkbun.api.apiKey}
|
|
|
|
secretapikey=${config.${namespace}.secrets.networking.porkbun.api.secretKey}
|
|
|
|
*.${config.${namespace}.secrets.networking.domains.primary},*.${
|
|
|
|
config.${namespace}.secrets.networking.domains.blog
|
|
|
|
}
|
2024-11-22 17:47:18 +00:00
|
|
|
cache=/tmp/ddclient.cache
|
|
|
|
pid=/var/run/ddclient.pid
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# Monitor RAID drives using SMART
|
|
|
|
smartd.devices = [
|
|
|
|
{ device = "/dev/sda"; }
|
|
|
|
{ device = "/dev/sdb"; }
|
|
|
|
{ device = "/dev/sdc"; }
|
|
|
|
{ device = "/dev/sdd"; }
|
|
|
|
];
|
2024-11-01 16:51:11 +00:00
|
|
|
};
|
|
|
|
|
2024-12-02 18:08:35 +00:00
|
|
|
# Build Nix packages for other hosts.
|
|
|
|
# Runs every Saturday morning at 4 AM
|
|
|
|
systemd.services."build-hosts" = {
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = "aires";
|
|
|
|
};
|
2024-12-06 18:04:47 +00:00
|
|
|
path = config.${namespace}.corePackages;
|
2024-12-02 18:08:35 +00:00
|
|
|
script = ''
|
2024-12-09 18:30:39 +00:00
|
|
|
/run/current-system/sw/bin/nixos-operations-script --operation build --hostname Khanda --flake ${
|
|
|
|
config.${namespace}.secrets.nixConfigFolder
|
|
|
|
}
|
2024-12-02 18:08:35 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
systemd.timers."build-hosts" = {
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "Sat, 04:00";
|
|
|
|
Persistent = true;
|
|
|
|
Unit = "build-hosts.service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-04 14:39:03 +00:00
|
|
|
# Configure the system.
|
2024-12-06 18:04:47 +00:00
|
|
|
${namespace} = {
|
2024-09-04 14:39:03 +00:00
|
|
|
# Enable Secure Boot support.
|
2024-06-24 22:19:27 +00:00
|
|
|
bootloader = {
|
|
|
|
enable = true;
|
|
|
|
secureboot.enable = true;
|
|
|
|
tpm2.enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Change the default text editor. Options are "emacs", "nano", or "vim".
|
|
|
|
editor = "nano";
|
|
|
|
|
2024-09-04 14:39:03 +00:00
|
|
|
# Enable GPU support.
|
2024-06-24 17:08:18 +00:00
|
|
|
gpu.amd.enable = true;
|
2024-06-24 22:19:27 +00:00
|
|
|
|
2024-09-04 14:39:03 +00:00
|
|
|
# Enable support for primary RAID array
|
2024-09-17 14:42:09 +00:00
|
|
|
raid.storage = {
|
|
|
|
enable = true;
|
2024-12-09 18:30:39 +00:00
|
|
|
keyFile = config.${namespace}.secrets.devices.storage.keyFile.path;
|
|
|
|
mailAddr = config.${namespace}.secrets.users.aires.email;
|
2024-09-17 14:42:09 +00:00
|
|
|
};
|
2024-06-24 22:19:27 +00:00
|
|
|
|
2024-05-07 22:02:59 +00:00
|
|
|
services = {
|
2024-05-21 00:52:57 +00:00
|
|
|
acme = {
|
|
|
|
enable = true;
|
2024-12-09 18:30:39 +00:00
|
|
|
defaultEmail = config.${namespace}.secrets.users.aires.email;
|
2024-05-21 00:52:57 +00:00
|
|
|
certs = {
|
2024-12-09 18:30:39 +00:00
|
|
|
"${config.${namespace}.secrets.networking.domains.primary}" = {
|
2024-10-26 15:56:09 +00:00
|
|
|
dnsProvider = "porkbun";
|
2024-05-21 00:52:57 +00:00
|
|
|
extraDomainNames = subdomains;
|
|
|
|
webroot = null; # Required in order to prevent a failed assertion
|
2024-10-26 15:56:09 +00:00
|
|
|
credentialFiles = porkbunCredentials;
|
2024-05-21 00:52:57 +00:00
|
|
|
};
|
2024-12-09 18:30:39 +00:00
|
|
|
"${config.${namespace}.secrets.networking.domains.blog}" = {
|
2024-10-26 15:56:09 +00:00
|
|
|
dnsProvider = "porkbun";
|
2024-06-19 18:00:17 +00:00
|
|
|
webroot = null; # Required in order to prevent a failed assertion
|
2024-10-26 15:56:09 +00:00
|
|
|
credentialFiles = porkbunCredentials;
|
2024-06-19 18:00:17 +00:00
|
|
|
};
|
2024-05-21 00:52:57 +00:00
|
|
|
};
|
|
|
|
};
|
2024-05-21 13:22:03 +00:00
|
|
|
apcupsd = {
|
|
|
|
enable = true;
|
|
|
|
configText = builtins.readFile ./etc/apcupsd.conf;
|
|
|
|
};
|
2024-06-24 16:24:21 +00:00
|
|
|
autoUpgrade = {
|
2024-09-09 03:54:10 +00:00
|
|
|
enable = true;
|
|
|
|
pushUpdates = true; # Update automatically and push updates back up to Forgejo
|
2024-12-09 18:30:39 +00:00
|
|
|
configDir = config.${namespace}.secrets.nixConfigFolder;
|
2024-06-24 16:24:21 +00:00
|
|
|
onCalendar = "daily";
|
|
|
|
user = config.users.users.aires.name;
|
|
|
|
};
|
2024-12-02 02:01:53 +00:00
|
|
|
binary-cache = {
|
2024-12-02 16:26:29 +00:00
|
|
|
enable = true;
|
2024-12-02 02:01:53 +00:00
|
|
|
secretKeyFile = "${services-root}/nixos-binary-cache/certs/cache-priv-key.pem";
|
2024-12-09 18:30:39 +00:00
|
|
|
url = config.${namespace}.secrets.services.binary-cache.url;
|
2024-12-02 16:26:29 +00:00
|
|
|
auth = {
|
2024-12-09 18:30:39 +00:00
|
|
|
user = config.${namespace}.secrets.services.binary-cache.auth.username;
|
|
|
|
password = config.${namespace}.secrets.services.binary-cache.auth.password;
|
2024-12-02 16:26:29 +00:00
|
|
|
};
|
2024-12-02 02:01:53 +00:00
|
|
|
};
|
2024-09-14 20:05:10 +00:00
|
|
|
boinc = {
|
|
|
|
enable = false;
|
|
|
|
home = "${services-root}/boinc";
|
|
|
|
};
|
2024-05-07 22:02:59 +00:00
|
|
|
duplicacy-web = {
|
|
|
|
enable = true;
|
2024-09-04 14:39:03 +00:00
|
|
|
home = "/storage/backups/settings/Haven";
|
2024-05-07 22:02:59 +00:00
|
|
|
};
|
2024-05-20 16:27:01 +00:00
|
|
|
forgejo = {
|
|
|
|
enable = true;
|
2024-06-19 18:00:17 +00:00
|
|
|
home = "${services-root}/forgejo";
|
2024-12-09 18:30:39 +00:00
|
|
|
url = config.${namespace}.secrets.services.forgejo.url;
|
2024-05-20 16:27:01 +00:00
|
|
|
};
|
2024-09-04 14:39:03 +00:00
|
|
|
jellyfin = {
|
|
|
|
enable = true;
|
|
|
|
home = "${services-root}/jellyfin";
|
2024-12-09 18:30:39 +00:00
|
|
|
url = config.${namespace}.secrets.services.jellyfin.url;
|
2024-09-04 14:39:03 +00:00
|
|
|
};
|
2024-09-28 20:39:57 +00:00
|
|
|
languagetool = {
|
|
|
|
enable = true;
|
2024-12-09 18:30:39 +00:00
|
|
|
url = config.${namespace}.secrets.services.languagetool.url;
|
2024-09-28 21:15:39 +00:00
|
|
|
port = 8100;
|
2024-12-09 18:30:39 +00:00
|
|
|
auth.user = config.${namespace}.secrets.services.languagetool.auth.user;
|
|
|
|
auth.password = config.${namespace}.secrets.services.languagetool.auth.password;
|
2024-09-28 20:39:57 +00:00
|
|
|
ngrams.enable = true;
|
|
|
|
};
|
2024-09-15 18:39:26 +00:00
|
|
|
msmtp = {
|
|
|
|
enable = true;
|
|
|
|
accounts.default = {
|
2024-12-09 18:30:39 +00:00
|
|
|
host = config.${namespace}.secrets.services.msmtp.host;
|
|
|
|
user = config.${namespace}.secrets.services.msmtp.user;
|
|
|
|
password = config.${namespace}.secrets.services.msmtp.password;
|
2024-09-15 18:39:26 +00:00
|
|
|
auth = true;
|
|
|
|
tls = true;
|
|
|
|
tls_starttls = true;
|
|
|
|
port = 587;
|
2024-12-09 18:30:39 +00:00
|
|
|
from = "${config.networking.hostName}@${config.${namespace}.secrets.networking.domains.primary}";
|
2024-09-15 18:39:26 +00:00
|
|
|
};
|
|
|
|
aliases = {
|
|
|
|
text = ''
|
2024-12-09 18:30:39 +00:00
|
|
|
default: ${config.${namespace}.secrets.users.aires.email}
|
2024-09-15 18:39:26 +00:00
|
|
|
'';
|
|
|
|
mode = "0644";
|
|
|
|
};
|
|
|
|
};
|
2024-09-04 14:39:03 +00:00
|
|
|
netdata = {
|
|
|
|
enable = true;
|
|
|
|
type = "parent";
|
2024-12-09 18:30:39 +00:00
|
|
|
url = config.${namespace}.secrets.services.netdata.url;
|
2024-09-04 14:39:03 +00:00
|
|
|
auth = {
|
|
|
|
user = config.users.users.aires.name;
|
2024-12-09 18:30:39 +00:00
|
|
|
password = config.${namespace}.secrets.services.netdata.password;
|
|
|
|
apiKey = config.${namespace}.secrets.services.netdata.apiKey;
|
2024-09-04 14:39:03 +00:00
|
|
|
};
|
|
|
|
};
|
2024-05-21 00:52:57 +00:00
|
|
|
nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts = {
|
2024-12-09 18:30:39 +00:00
|
|
|
"${config.${namespace}.secrets.networking.domains.primary}" = {
|
2024-05-21 00:52:57 +00:00
|
|
|
default = true;
|
|
|
|
enableACME = true; # Enable Let's Encrypt
|
|
|
|
locations."/" = {
|
|
|
|
# Catchall vhost, will redirect users to Forgejo
|
2024-12-09 18:30:39 +00:00
|
|
|
return = "301 https://${config.${namespace}.secrets.services.forgejo.url}";
|
2024-05-21 00:52:57 +00:00
|
|
|
};
|
|
|
|
};
|
2024-12-09 18:30:39 +00:00
|
|
|
"${config.${namespace}.secrets.networking.domains.blog}" = {
|
|
|
|
useACMEHost = config.${namespace}.secrets.networking.domains.blog;
|
2024-06-19 18:00:17 +00:00
|
|
|
forceSSL = true;
|
2024-12-09 18:30:39 +00:00
|
|
|
root = "${services-root}/nginx/sites/${config.${namespace}.secrets.networking.domains.blog}";
|
2024-06-19 18:00:17 +00:00
|
|
|
};
|
2024-12-20 17:54:12 +00:00
|
|
|
"${config.${namespace}.secrets.hosts.gremlin-lab.URI}" = {
|
2024-12-09 18:30:39 +00:00
|
|
|
useACMEHost = config.${namespace}.secrets.networking.domains.primary;
|
2024-05-24 15:56:23 +00:00
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
2024-12-20 17:54:12 +00:00
|
|
|
proxyPass = "http://${config.${namespace}.secrets.hosts.gremlin-lab.IP}";
|
2024-05-24 15:56:23 +00:00
|
|
|
proxyWebsockets = true;
|
|
|
|
extraConfig = "proxy_ssl_server_name on;";
|
|
|
|
};
|
|
|
|
};
|
2024-05-21 00:52:57 +00:00
|
|
|
};
|
|
|
|
};
|
2024-09-11 00:14:40 +00:00
|
|
|
qbittorrent = {
|
|
|
|
enable = true;
|
|
|
|
home = "${services-root}/qbittorrent";
|
2024-12-09 18:30:39 +00:00
|
|
|
url = config.${namespace}.secrets.services.qbittorrent.url;
|
2024-09-13 15:25:39 +00:00
|
|
|
port = "8090";
|
|
|
|
vpn = {
|
|
|
|
enable = true;
|
2024-12-09 18:30:39 +00:00
|
|
|
privateKey = config.${namespace}.secrets.services.protonvpn.privateKey;
|
2024-10-28 17:40:55 +00:00
|
|
|
countries = [
|
|
|
|
"Switzerland"
|
|
|
|
"Netherlands"
|
|
|
|
];
|
2024-09-13 15:25:39 +00:00
|
|
|
};
|
2024-09-11 00:14:40 +00:00
|
|
|
};
|
2024-12-02 19:32:24 +00:00
|
|
|
rss = {
|
2024-12-05 21:02:14 +00:00
|
|
|
enable = false;
|
2024-12-02 19:32:24 +00:00
|
|
|
home = "${services-root}/freshrss";
|
2024-12-09 18:30:39 +00:00
|
|
|
url = config.${namespace}.secrets.services.rss.url;
|
|
|
|
auth = with config.${namespace}.secrets.services.rss.auth; {
|
2024-12-02 19:32:24 +00:00
|
|
|
user = user;
|
|
|
|
password = password;
|
|
|
|
};
|
|
|
|
};
|
2024-05-21 00:52:57 +00:00
|
|
|
ssh = {
|
|
|
|
enable = true;
|
2024-12-09 18:30:39 +00:00
|
|
|
ports = [ config.${namespace}.secrets.hosts.hevana.ssh.port ];
|
2024-05-21 00:52:57 +00:00
|
|
|
};
|
2024-11-24 16:38:09 +00:00
|
|
|
syncthing = {
|
|
|
|
enable = true;
|
|
|
|
home = "${services-root}/syncthing/aires";
|
|
|
|
user = "aires";
|
|
|
|
web = {
|
|
|
|
enable = true;
|
|
|
|
public = true;
|
|
|
|
};
|
|
|
|
};
|
2024-12-09 15:18:30 +00:00
|
|
|
tor = {
|
|
|
|
enable = true;
|
|
|
|
snowflake-proxy = {
|
|
|
|
enable = true;
|
|
|
|
capacity = 50;
|
|
|
|
};
|
|
|
|
};
|
2024-09-04 14:39:03 +00:00
|
|
|
virtualization.host = {
|
|
|
|
enable = true;
|
|
|
|
user = "aires";
|
|
|
|
vmBuilds = {
|
2024-06-25 18:13:15 +00:00
|
|
|
enable = true;
|
2024-09-04 14:39:03 +00:00
|
|
|
cores = 3;
|
|
|
|
ram = 4096;
|
2024-06-25 18:13:15 +00:00
|
|
|
};
|
2024-05-22 20:47:55 +00:00
|
|
|
};
|
2024-05-07 22:02:59 +00:00
|
|
|
};
|
2024-09-04 14:39:03 +00:00
|
|
|
|
2024-11-24 16:38:09 +00:00
|
|
|
users.aires.enable = true;
|
2024-05-07 22:02:59 +00:00
|
|
|
};
|
2024-04-01 16:30:07 +00:00
|
|
|
}
|