2024-05-07 22:02:59 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
home-manager,
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}:
|
2024-02-29 14:53:34 +00:00
|
|
|
let
|
2024-05-07 22:02:59 +00:00
|
|
|
start-haven = pkgs.writeShellScriptBin "start-haven" (builtins.readFile ./start-haven.sh);
|
2024-05-19 18:33:15 +00:00
|
|
|
|
2024-05-24 03:50:42 +00:00
|
|
|
subdomains = [
|
|
|
|
config.secrets.services.airsonic.url
|
2024-05-24 21:33:37 +00:00
|
|
|
config.secrets.services.cache.url
|
2024-05-24 03:50:42 +00:00
|
|
|
config.secrets.services.forgejo.url
|
2024-05-24 15:56:23 +00:00
|
|
|
config.secrets.services.gremlin-lab.url
|
2024-05-19 18:33:15 +00:00
|
|
|
];
|
2024-02-29 14:53:34 +00:00
|
|
|
in
|
|
|
|
{
|
2024-05-07 22:02:59 +00:00
|
|
|
imports = [ ./hardware-configuration.nix ];
|
|
|
|
|
|
|
|
system.stateVersion = "24.05";
|
2024-02-29 14:53:34 +00:00
|
|
|
|
2024-05-07 22:02:59 +00:00
|
|
|
host = {
|
|
|
|
role = "server";
|
|
|
|
services = {
|
2024-05-21 00:52:57 +00:00
|
|
|
acme = {
|
|
|
|
enable = true;
|
2024-05-21 00:56:48 +00:00
|
|
|
defaultEmail = config.secrets.users.aires.email;
|
2024-05-21 00:52:57 +00:00
|
|
|
certs = {
|
|
|
|
"${config.secrets.networking.primaryDomain}" = {
|
|
|
|
dnsProvider = "namecheap";
|
|
|
|
extraDomainNames = subdomains;
|
|
|
|
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-21 13:22:03 +00:00
|
|
|
apcupsd = {
|
|
|
|
enable = true;
|
|
|
|
configText = builtins.readFile ./etc/apcupsd.conf;
|
|
|
|
};
|
2024-05-20 16:27:01 +00:00
|
|
|
airsonic = {
|
|
|
|
enable = true;
|
|
|
|
home = "/storage/services/airsonic-advanced";
|
|
|
|
};
|
2024-05-30 18:08:19 +00:00
|
|
|
autoUpgrade.pushUpdates = true;
|
2024-05-21 00:52:57 +00:00
|
|
|
boinc.enable = true;
|
2024-05-24 21:33:37 +00:00
|
|
|
cache = {
|
2024-05-25 15:07:10 +00:00
|
|
|
enable = false; # Disable for now
|
2024-05-24 21:33:37 +00:00
|
|
|
secretKeyFile = "/storage/services/nix-cache/cache-priv-key.pem";
|
|
|
|
};
|
2024-05-07 22:02:59 +00:00
|
|
|
duplicacy-web = {
|
|
|
|
enable = true;
|
|
|
|
autostart = false;
|
2024-05-22 15:05:20 +00:00
|
|
|
environment = "/storage/backups/settings/Haven";
|
2024-05-07 22:02:59 +00:00
|
|
|
};
|
2024-05-20 16:27:01 +00:00
|
|
|
forgejo = {
|
|
|
|
enable = true;
|
|
|
|
home = "/storage/services/forgejo";
|
|
|
|
};
|
2024-05-07 22:02:59 +00:00
|
|
|
msmtp.enable = true;
|
2024-05-21 00:52:57 +00:00
|
|
|
nginx = {
|
|
|
|
enable = true;
|
|
|
|
autostart = false;
|
|
|
|
virtualHosts = {
|
|
|
|
"${config.secrets.networking.primaryDomain}" = {
|
|
|
|
default = true;
|
|
|
|
enableACME = true; # Enable Let's Encrypt
|
|
|
|
locations."/" = {
|
|
|
|
# Catchall vhost, will redirect users to Forgejo
|
2024-05-22 19:39:57 +00:00
|
|
|
return = "301 https://${config.secrets.services.forgejo.url}";
|
2024-05-21 00:52:57 +00:00
|
|
|
};
|
|
|
|
};
|
2024-05-24 15:56:23 +00:00
|
|
|
"${config.secrets.services.gremlin-lab.url}" = {
|
|
|
|
useACMEHost = config.secrets.networking.primaryDomain;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://${config.secrets.services.gremlin-lab.ip}";
|
|
|
|
proxyWebsockets = true;
|
|
|
|
extraConfig = "proxy_ssl_server_name on;";
|
|
|
|
};
|
|
|
|
};
|
2024-05-21 00:52:57 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
ssh = {
|
|
|
|
enable = true;
|
|
|
|
ports = [ config.secrets.hosts.haven.ssh.port ];
|
|
|
|
};
|
2024-05-22 20:47:55 +00:00
|
|
|
virtualization = {
|
|
|
|
enable = true;
|
|
|
|
user = "aires";
|
|
|
|
};
|
2024-05-07 22:02:59 +00:00
|
|
|
};
|
2024-05-21 13:22:03 +00:00
|
|
|
users.aires = {
|
|
|
|
enable = true;
|
|
|
|
services.syncthing = {
|
2024-05-07 22:02:59 +00:00
|
|
|
enable = true;
|
2024-05-21 13:22:03 +00:00
|
|
|
autostart = false;
|
2024-05-07 22:02:59 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-02-29 14:53:34 +00:00
|
|
|
|
2024-05-21 00:52:57 +00:00
|
|
|
# TODO: VPN (Check out Wireguard)
|
2024-05-19 18:33:15 +00:00
|
|
|
|
2024-05-20 16:27:01 +00:00
|
|
|
# Add Haven's startup script
|
|
|
|
environment.systemPackages = [ start-haven ];
|
2024-05-19 18:33:15 +00:00
|
|
|
|
|
|
|
# Allow Haven to be a build target for other architectures (mainly ARM64)
|
|
|
|
boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
|
2024-05-30 14:04:14 +00:00
|
|
|
|
|
|
|
# Automatically update Flake configuration for other hosts to use
|
|
|
|
systemd.services."nixos-update-flake" = {
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = config.users.users.aires.name;
|
|
|
|
};
|
2024-05-30 18:08:19 +00:00
|
|
|
path = with pkgs; [
|
|
|
|
# Courtesy of https://discourse.nixos.org/t/how-to-use-other-packages-binary-in-systemd-service-configuration/14363
|
2024-05-30 16:19:07 +00:00
|
|
|
coreutils
|
|
|
|
gnutar
|
|
|
|
xz.bin
|
|
|
|
gzip
|
|
|
|
git
|
|
|
|
config.nix.package.out
|
|
|
|
openssh
|
|
|
|
];
|
2024-05-30 14:04:14 +00:00
|
|
|
script = ''
|
|
|
|
set -eu
|
2024-05-30 18:08:19 +00:00
|
|
|
cd ${config.secrets.nixConfigFolder}
|
2024-05-30 14:31:11 +00:00
|
|
|
git pull --recurse-submodules
|
2024-05-30 14:04:14 +00:00
|
|
|
nix flake update
|
|
|
|
git add flake.lock
|
2024-05-30 16:46:43 +00:00
|
|
|
git diff --quiet && git diff --staged --quiet || git commit -am "Update flake.lock" && git push # Courtesy of https://stackoverflow.com/a/40255467
|
2024-05-30 14:04:14 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers."nixos-update-flake-timer" = {
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "daily";
|
|
|
|
Persistent = "true";
|
|
|
|
Unit = "nixos-update-flake.service";
|
|
|
|
};
|
|
|
|
};
|
2024-04-01 16:30:07 +00:00
|
|
|
}
|