2024-02-23 19:57:21 +08:00
|
|
|
{
|
|
|
|
lib,
|
2024-05-24 00:15:10 +08:00
|
|
|
config,
|
2024-08-11 18:08:41 +08:00
|
|
|
pkgs,
|
2024-02-23 19:57:21 +08:00
|
|
|
...
|
2024-08-25 23:02:35 +08:00
|
|
|
}:
|
|
|
|
{
|
2024-02-13 12:01:59 +08:00
|
|
|
imports = [
|
|
|
|
# OS
|
2024-08-24 16:10:54 +08:00
|
|
|
../../nixos/profiles/sing-box
|
2024-02-13 12:01:59 +08:00
|
|
|
|
|
|
|
# Hardware
|
|
|
|
./hardware-configuration.nix
|
|
|
|
./anti-feature.nix
|
2024-08-11 18:08:41 +08:00
|
|
|
|
|
|
|
# Services
|
2024-08-16 16:49:03 +08:00
|
|
|
./services/jellyfin.nix
|
2024-08-11 18:08:41 +08:00
|
|
|
./services/mastodon.nix
|
2024-08-16 16:49:03 +08:00
|
|
|
./services/matrix.nix
|
2024-08-11 18:08:41 +08:00
|
|
|
./services/minecraft.nix
|
2024-08-16 16:49:03 +08:00
|
|
|
./services/samba.nix
|
2024-08-31 07:51:49 +08:00
|
|
|
./services/transmission.nix
|
2024-02-13 12:01:59 +08:00
|
|
|
];
|
|
|
|
|
2024-04-22 22:34:20 +08:00
|
|
|
boot.loader.efi.canTouchEfiVariables = true;
|
|
|
|
boot.loader.systemd-boot.enable = true;
|
2024-08-31 08:00:40 +08:00
|
|
|
networking.hostName = "pek0";
|
2024-08-12 15:25:36 +08:00
|
|
|
system.stateVersion = "24.05";
|
2024-02-13 12:01:59 +08:00
|
|
|
|
2024-11-22 17:16:04 +08:00
|
|
|
# error: 1 dependencies of derivation '/nix/store/42rdjw63xw8asrfbczy0skrx8485n75i-linux-6.12-modules.drv' failed to build
|
|
|
|
boot.kernelPackages = lib.mkForce pkgs.linuxPackages_6_11;
|
|
|
|
|
2024-12-14 12:48:43 +08:00
|
|
|
users.users."root" = {
|
|
|
|
hashedPasswordFile = config.sops.secrets."hashed-passwd".path;
|
|
|
|
};
|
|
|
|
|
2025-01-18 16:20:44 +08:00
|
|
|
# tty
|
|
|
|
console = {
|
|
|
|
earlySetup = true;
|
|
|
|
keyMap = "dvorak";
|
|
|
|
};
|
|
|
|
|
2024-05-24 00:15:10 +08:00
|
|
|
######## Secrets
|
2024-08-25 23:02:35 +08:00
|
|
|
sops.secrets = lib.mapAttrs (_name: value: value // { sopsFile = ./secrets.yaml; }) {
|
2024-10-01 00:15:02 +08:00
|
|
|
"hashed-passwd" = {
|
|
|
|
neededForUsers = true;
|
|
|
|
};
|
2024-08-09 17:46:45 +08:00
|
|
|
"synapse/secret" = {
|
2024-08-25 23:02:35 +08:00
|
|
|
restartUnits = [ "matrix-synapse.service" ];
|
2024-08-09 17:46:45 +08:00
|
|
|
owner = config.systemd.services.matrix-synapse.serviceConfig.User;
|
|
|
|
};
|
|
|
|
"synapse/oidc" = {
|
2024-08-25 23:02:35 +08:00
|
|
|
restartUnits = [ "matrix-synapse.service" ];
|
2024-08-09 17:46:45 +08:00
|
|
|
owner = config.systemd.services.matrix-synapse.serviceConfig.User;
|
|
|
|
};
|
|
|
|
"mastodon/environment" = {
|
2024-08-25 23:02:35 +08:00
|
|
|
restartUnits = [ "mastodon-web.service" ];
|
2024-08-09 17:46:45 +08:00
|
|
|
};
|
|
|
|
"cloudflared/secret" = {
|
2024-11-07 14:58:07 +08:00
|
|
|
restartUnits = [ "cloudflared-tunnel-b73805e7-a8a9-49db-8c9f-aae52c406635.service" ];
|
2024-08-25 23:02:35 +08:00
|
|
|
owner =
|
2024-11-07 14:58:07 +08:00
|
|
|
config.systemd.services."cloudflared-tunnel-b73805e7-a8a9-49db-8c9f-aae52c406635".serviceConfig.User;
|
2024-05-24 00:15:10 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2025-01-05 02:36:46 +08:00
|
|
|
networking = {
|
|
|
|
useNetworkd = true;
|
|
|
|
useDHCP = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.network.networks.ethernet = {
|
|
|
|
matchConfig.Name = [
|
|
|
|
"en*"
|
|
|
|
"eth*"
|
|
|
|
];
|
|
|
|
DHCP = "yes";
|
|
|
|
};
|
|
|
|
|
2024-02-16 17:07:56 +08:00
|
|
|
services.tailscale = {
|
|
|
|
enable = true;
|
|
|
|
openFirewall = true;
|
|
|
|
};
|
2024-02-16 00:58:18 +08:00
|
|
|
|
2024-06-21 15:18:05 +08:00
|
|
|
services.cloudflared = {
|
2024-05-24 00:15:10 +08:00
|
|
|
enable = true;
|
2024-11-07 14:58:07 +08:00
|
|
|
tunnels."b73805e7-a8a9-49db-8c9f-aae52c406635" = {
|
|
|
|
credentialsFile = config.sops.secrets."cloudflared/secret".path;
|
|
|
|
default = "http_status:404";
|
2024-12-14 12:48:43 +08:00
|
|
|
ingress = lib.genAttrs [ "jellyfin.ny4.dev" "mastodon.ny4.dev" "matrix.ny4.dev" "pek0.ny4.dev" ] (
|
|
|
|
_: "http://localhost"
|
|
|
|
);
|
2024-05-24 00:15:10 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-31 10:15:09 +08:00
|
|
|
services.caddy.enable = true;
|
|
|
|
services.caddy.settings.apps.http.servers.srv0 = {
|
|
|
|
listen = [ ":80" ];
|
|
|
|
trusted_proxies = {
|
|
|
|
ranges = [
|
|
|
|
"192.168.0.0/16"
|
|
|
|
"172.16.0.0/12"
|
|
|
|
"10.0.0.0/8"
|
|
|
|
"127.0.0.1/8"
|
|
|
|
"fd00::/8"
|
|
|
|
"::1"
|
|
|
|
];
|
|
|
|
source = "static";
|
2024-06-21 15:18:05 +08:00
|
|
|
};
|
2024-08-31 10:15:09 +08:00
|
|
|
trusted_proxies_strict = 1;
|
2024-06-21 15:18:05 +08:00
|
|
|
};
|
|
|
|
|
2024-09-07 15:24:37 +08:00
|
|
|
systemd.services."caddy".serviceConfig.SupplementaryGroups = [
|
|
|
|
"mastodon"
|
|
|
|
"matrix-synapse"
|
|
|
|
];
|
2024-05-24 00:15:10 +08:00
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
2024-08-11 21:26:31 +08:00
|
|
|
package = pkgs.postgresql_16;
|
2024-05-24 00:15:10 +08:00
|
|
|
settings = {
|
|
|
|
max_connections = 200;
|
|
|
|
shared_buffers = "4GB";
|
|
|
|
effective_cache_size = "12GB";
|
|
|
|
maintenance_work_mem = "1GB";
|
|
|
|
checkpoint_completion_target = 0.9;
|
|
|
|
wal_buffers = "16MB";
|
|
|
|
default_statistics_target = 100;
|
2024-08-11 21:26:31 +08:00
|
|
|
random_page_cost = 1.1;
|
2024-05-24 00:15:10 +08:00
|
|
|
effective_io_concurrency = 200;
|
|
|
|
work_mem = "5242kB";
|
|
|
|
huge_pages = "off";
|
|
|
|
min_wal_size = "1GB";
|
|
|
|
max_wal_size = "4GB";
|
|
|
|
max_worker_processes = 8;
|
|
|
|
max_parallel_workers_per_gather = 4;
|
|
|
|
max_parallel_workers = 8;
|
|
|
|
max_parallel_maintenance_workers = 4;
|
|
|
|
};
|
|
|
|
initialScript = pkgs.writeText "synapse-init.sql" ''
|
|
|
|
CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'synapse';
|
|
|
|
CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse"
|
|
|
|
TEMPLATE template0
|
|
|
|
LC_COLLATE = "C"
|
|
|
|
LC_CTYPE = "C";
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresqlBackup = {
|
|
|
|
enable = true;
|
|
|
|
location = "/var/lib/backup/postgresql";
|
|
|
|
compression = "zstd";
|
|
|
|
startAt = "weekly";
|
|
|
|
};
|
2024-02-13 12:01:59 +08:00
|
|
|
}
|