2024-04-22 18:35:50 +00:00
|
|
|
{
|
|
|
|
modulesPath,
|
|
|
|
lib,
|
2024-04-22 21:01:38 +00:00
|
|
|
config,
|
2024-04-22 21:09:00 +00:00
|
|
|
inputs,
|
2024-05-02 23:43:48 +00:00
|
|
|
pkgs,
|
2024-04-22 18:35:50 +00:00
|
|
|
...
|
|
|
|
}: {
|
|
|
|
imports = [
|
|
|
|
"${modulesPath}/virtualisation/amazon-image.nix"
|
2024-04-22 21:09:00 +00:00
|
|
|
inputs.nixos-sensible.nixosModules.zram
|
2024-04-22 18:35:50 +00:00
|
|
|
../../nixos/profiles/server
|
|
|
|
./anti-feature.nix
|
|
|
|
];
|
|
|
|
|
|
|
|
time.timeZone = "Asia/Tokyo";
|
|
|
|
boot.loader.grub.device = lib.mkForce "/dev/nvme0n1";
|
|
|
|
system.stateVersion = "23.11";
|
2024-04-22 21:01:38 +00:00
|
|
|
|
2024-05-02 23:43:48 +00:00
|
|
|
# WORKAROUND:
|
|
|
|
systemd.services."print-host-key".enable = false;
|
|
|
|
|
|
|
|
### Secrets
|
|
|
|
sops.secrets = builtins.mapAttrs (_name: value: value // {sopsFile = ./secrets.yaml;}) {
|
|
|
|
"hysteria/auth".restartUnits = ["hysteria.service"];
|
|
|
|
"searx/environment".restartUnits = ["searx.service"];
|
2024-04-22 21:01:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
sops.templates."hysteria.yaml".content = ''
|
2024-04-22 21:08:04 +00:00
|
|
|
tls:
|
|
|
|
cert: /run/credentials/hysteria.service/cert
|
|
|
|
key: /run/credentials/hysteria.service/key
|
2024-04-22 21:01:38 +00:00
|
|
|
|
2024-04-22 21:08:04 +00:00
|
|
|
masquerade:
|
|
|
|
type: proxy
|
|
|
|
proxy:
|
2024-05-02 23:43:48 +00:00
|
|
|
url: http://localhost/
|
2024-04-22 21:01:38 +00:00
|
|
|
|
|
|
|
${config.sops.placeholder."hysteria/auth"}
|
|
|
|
'';
|
|
|
|
|
2024-05-02 23:43:48 +00:00
|
|
|
### Services
|
|
|
|
networking.firewall.allowedUDPPorts = [443]; # h3 hysteria -> caddy
|
|
|
|
networking.firewall.allowedTCPPorts = [80 443]; # caddy
|
|
|
|
|
2024-05-04 08:12:36 +00:00
|
|
|
systemd.tmpfiles.settings = {
|
|
|
|
"10-www" = {
|
|
|
|
"/var/www/robots/robots.txt".C.argument = toString ./robots.txt;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-02 23:43:48 +00:00
|
|
|
services.caddy = {
|
|
|
|
enable = true;
|
2024-05-04 08:12:36 +00:00
|
|
|
configFile = ./Caddyfile;
|
2024-05-02 23:43:48 +00:00
|
|
|
};
|
2024-04-22 21:01:38 +00:00
|
|
|
|
|
|
|
services.hysteria = {
|
|
|
|
enable = true;
|
|
|
|
configFile = config.sops.templates."hysteria.yaml".path;
|
|
|
|
credentials = [
|
2024-05-02 23:43:48 +00:00
|
|
|
# FIXME: remove hardcoded path
|
|
|
|
"cert:/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/ny4.dev/ny4.dev.crt"
|
|
|
|
"key:/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/ny4.dev/ny4.dev.key"
|
2024-04-22 21:01:38 +00:00
|
|
|
];
|
|
|
|
};
|
2024-05-02 23:43:48 +00:00
|
|
|
|
|
|
|
# `journalctl -u murmur.service | grep Password`
|
|
|
|
services.murmur = {
|
|
|
|
enable = true;
|
|
|
|
openFirewall = true;
|
|
|
|
bandwidth = 128000;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.searx = {
|
|
|
|
enable = true;
|
|
|
|
package = pkgs.searxng;
|
|
|
|
environmentFile = config.sops.secrets."searx/environment".path;
|
|
|
|
settings = {
|
|
|
|
general.contact_url = "mailto:guanran928@outlook.com";
|
|
|
|
search.autocomplete = "google";
|
|
|
|
server = {
|
|
|
|
port = 8100;
|
|
|
|
secret_key = "@SEARX_SECRET@";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.wastebin = {
|
|
|
|
enable = true;
|
|
|
|
settings.WASTEBIN_ADDRESS_PORT = "127.0.0.1:8200";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.uptime-kuma = {
|
|
|
|
enable = true;
|
|
|
|
settings.PORT = "8300";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.ntfy-sh = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
base-url = "https://ntfy.ny4.dev";
|
|
|
|
listen-http = "127.0.0.1:8400";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
### Prevents me from bankrupt
|
|
|
|
# https://fmk.im/p/shutdown-aws/
|
|
|
|
services.vnstat.enable = true;
|
|
|
|
systemd.services."no-bankrupt" = {
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
path = with pkgs; [coreutils gawk vnstat systemd];
|
|
|
|
script = ''
|
|
|
|
TRAFF_TOTAL=1900
|
|
|
|
TRAFF_USED=$(vnstat --oneline b | awk -F ';' '{print $11}')
|
|
|
|
CHANGE_TO_GB=$(($TRAFF_USED / 1073741824))
|
|
|
|
|
|
|
|
if [ $CHANGE_TO_GB -gt $TRAFF_TOTAL ]; then
|
|
|
|
shutdown -h now
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
systemd.timers."no-bankrupt" = {
|
|
|
|
timerConfig.OnCalendar = "*:0:0"; # Check every hour
|
|
|
|
};
|
2024-04-22 18:35:50 +00:00
|
|
|
}
|