2023-12-05 03:36:26 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
2021-11-15 10:02:05 +00:00
|
|
|
{
|
|
|
|
imports = [
|
2023-12-12 04:25:06 +00:00
|
|
|
./selfprivacy-module.nix
|
2022-08-26 10:21:05 +00:00
|
|
|
./volumes.nix
|
2021-11-15 10:02:05 +00:00
|
|
|
./users.nix
|
|
|
|
./letsencrypt/acme.nix
|
|
|
|
./letsencrypt/resolve.nix
|
|
|
|
./webserver/nginx.nix
|
|
|
|
./webserver/memcached.nix
|
2023-11-18 15:26:47 +00:00
|
|
|
# ./resources/limits.nix
|
2021-11-15 10:02:05 +00:00
|
|
|
];
|
|
|
|
|
2023-11-20 21:23:28 +00:00
|
|
|
fileSystems."/".options = [ "noatime" ];
|
|
|
|
|
2023-12-16 05:39:22 +00:00
|
|
|
services.selfprivacy-api.enable = true;
|
|
|
|
|
2022-11-04 08:57:00 +00:00
|
|
|
services.redis.servers.sp-api = {
|
|
|
|
enable = true;
|
|
|
|
save = [
|
|
|
|
[
|
|
|
|
30
|
|
|
|
1
|
|
|
|
]
|
|
|
|
[
|
|
|
|
10
|
|
|
|
10
|
|
|
|
]
|
|
|
|
];
|
|
|
|
port = 0;
|
|
|
|
settings = {
|
|
|
|
notify-keyspace-events = "KEA";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-12-11 17:58:12 +00:00
|
|
|
services.do-agent.enable = if config.selfprivacy.server.provider == "digitalocean" then true else false;
|
2022-11-04 08:57:00 +00:00
|
|
|
|
2023-12-18 14:13:57 +00:00
|
|
|
boot.tmp.cleanOnBoot = true;
|
2021-11-15 10:02:05 +00:00
|
|
|
networking = {
|
2023-11-16 00:00:11 +00:00
|
|
|
hostName = config.selfprivacy.hostname;
|
2023-12-16 05:39:22 +00:00
|
|
|
domain = config.selfprivacy.domain;
|
2022-02-28 10:59:24 +00:00
|
|
|
usePredictableInterfaceNames = false;
|
2021-11-15 10:02:05 +00:00
|
|
|
firewall = {
|
2022-02-15 12:09:45 +00:00
|
|
|
allowedTCPPorts = lib.mkForce [ 22 25 80 143 443 465 587 993 4443 8443 ];
|
|
|
|
allowedUDPPorts = lib.mkForce [ 8443 10000 ];
|
2022-02-28 10:59:24 +00:00
|
|
|
extraCommands = ''
|
|
|
|
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
|
|
|
|
iptables --append FORWARD --in-interface vpn00 -j ACCEPT
|
|
|
|
'';
|
2021-11-15 10:02:05 +00:00
|
|
|
};
|
|
|
|
nameservers = [ "1.1.1.1" "1.0.0.1" ];
|
|
|
|
};
|
2023-11-16 00:00:11 +00:00
|
|
|
time.timeZone = config.selfprivacy.timezone;
|
2021-11-15 10:02:05 +00:00
|
|
|
i18n.defaultLocale = "en_GB.UTF-8";
|
2023-11-16 00:00:11 +00:00
|
|
|
users.users.root.openssh.authorizedKeys.keys = config.selfprivacy.ssh.rootKeys;
|
2021-11-15 10:02:05 +00:00
|
|
|
services.openssh = {
|
2023-11-16 00:00:11 +00:00
|
|
|
enable = config.selfprivacy.ssh.enable;
|
2023-12-18 14:13:57 +00:00
|
|
|
settings = {
|
|
|
|
PasswordAuthentication = config.selfprivacy.ssh.passwordAuthentication;
|
|
|
|
PermitRootLogin = "yes";
|
|
|
|
};
|
2021-11-15 10:02:05 +00:00
|
|
|
openFirewall = false;
|
|
|
|
};
|
|
|
|
programs.ssh = {
|
2021-11-19 15:53:28 +00:00
|
|
|
pubkeyAcceptedKeyTypes = [ "ssh-ed25519" "ssh-rsa" ];
|
|
|
|
hostKeyAlgorithms = [ "ssh-ed25519" "ssh-rsa" ];
|
2021-11-15 10:02:05 +00:00
|
|
|
};
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
git
|
2022-07-19 12:18:46 +00:00
|
|
|
jq
|
2021-11-15 10:02:05 +00:00
|
|
|
];
|
2023-11-18 01:53:08 +00:00
|
|
|
# consider environment.defaultPackages = lib.mkForce [];
|
2023-12-27 08:54:10 +00:00
|
|
|
# TODO is it needed?
|
2021-11-15 10:02:05 +00:00
|
|
|
environment.variables = {
|
2023-11-16 00:00:11 +00:00
|
|
|
DOMAIN = config.selfprivacy.domain;
|
2021-11-15 10:02:05 +00:00
|
|
|
};
|
2023-11-18 14:54:55 +00:00
|
|
|
documentation.enable = false; # no {man,info}-pages & docs, etc to save space
|
2023-12-27 07:37:59 +00:00
|
|
|
# (or create a systemd service with `ConditionFirstBoot=yes`?)
|
2023-12-16 05:39:22 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"# Completely remove remnants of NIXOS_LUSTRATE."
|
|
|
|
"R! /old-root"
|
|
|
|
];
|
2023-12-22 19:04:03 +00:00
|
|
|
system.stateVersion =
|
|
|
|
lib.mkIf (config.selfprivacy.stateVersion != null)
|
|
|
|
config.selfprivacy.stateVersion;
|
2022-07-19 12:18:46 +00:00
|
|
|
system.autoUpgrade = {
|
2023-11-16 00:00:11 +00:00
|
|
|
enable = config.selfprivacy.autoUpgrade.enable;
|
|
|
|
allowReboot = config.selfprivacy.autoUpgrade.allowReboot;
|
2022-07-19 12:18:46 +00:00
|
|
|
};
|
2021-11-15 10:02:05 +00:00
|
|
|
nix = {
|
2023-12-20 13:16:21 +00:00
|
|
|
channel.enable = false;
|
2023-11-18 01:53:08 +00:00
|
|
|
|
|
|
|
# daemonCPUSchedPolicy = "idle";
|
|
|
|
# daemonIOSchedClass = "idle";
|
|
|
|
# daemonIOSchedPriority = 7;
|
|
|
|
# this is superseded by nix.settings.auto-optimise-store.
|
|
|
|
# optimise.automatic = true;
|
|
|
|
|
2021-11-15 10:02:05 +00:00
|
|
|
gc = {
|
2023-12-05 00:41:35 +00:00
|
|
|
automatic = true; # TODO it's debatable, because of IO&CPU load
|
2021-11-15 10:02:05 +00:00
|
|
|
options = "--delete-older-than 7d";
|
|
|
|
};
|
|
|
|
};
|
2023-11-18 01:53:08 +00:00
|
|
|
nix.settings = {
|
|
|
|
sandbox = true;
|
|
|
|
experimental-features = [ "nix-command" "flakes" "repl-flake" ];
|
|
|
|
# auto-optimise-store = true;
|
|
|
|
|
|
|
|
# evaluation restrictions:
|
|
|
|
# restrict-eval = true;
|
|
|
|
# allowed-uris = [];
|
|
|
|
allow-dirty = false;
|
|
|
|
};
|
2022-08-26 10:21:05 +00:00
|
|
|
services.journald.extraConfig = "SystemMaxUse=500M";
|
2021-11-15 10:02:05 +00:00
|
|
|
boot.kernel.sysctl = {
|
2023-12-05 00:41:35 +00:00
|
|
|
"net.ipv4.ip_forward" = 1; # TODO why is it here by default, for VPN only?
|
2021-11-15 10:02:05 +00:00
|
|
|
};
|
2023-12-05 00:41:35 +00:00
|
|
|
# TODO must be configurable and determined at nixos-infect stage
|
2021-11-15 10:02:05 +00:00
|
|
|
swapDevices = [
|
|
|
|
{
|
|
|
|
device = "/swapfile";
|
|
|
|
priority = 0;
|
|
|
|
size = 2048;
|
|
|
|
}
|
|
|
|
];
|
2023-12-05 00:41:35 +00:00
|
|
|
# TODO why is sudo needed?
|
2021-11-15 10:02:05 +00:00
|
|
|
security = {
|
|
|
|
sudo = {
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
};
|
2023-11-23 07:09:49 +00:00
|
|
|
systemd.enableEmergencyMode = false;
|
|
|
|
systemd.coredump.enable = false;
|
2022-07-19 12:18:46 +00:00
|
|
|
}
|