nixos-config/modules/nixos/_private/suites/server.nix

117 lines
3.6 KiB
Nix
Raw Normal View History

2022-12-06 07:55:11 +00:00
# All of the settings related to server systems. Take note they cannot be used
2022-12-10 10:47:34 +00:00
# alongside the desktop profile since there are conflicting configurations
# between them.
{ config, lib, pkgs, ... }:
2022-11-29 13:05:42 +00:00
let
cfg = config.suites.server;
2022-11-29 13:05:42 +00:00
in
{
options.suites.server = {
2022-11-29 13:05:42 +00:00
enable = lib.mkEnableOption "server-related settings";
cleanup.enable = lib.mkEnableOption "cleanup service for the system";
auto-upgrade.enable = lib.mkEnableOption "unattended system upgrades";
2022-11-29 13:05:42 +00:00
};
config = lib.mkIf cfg.enable (lib.mkMerge [
{
assertions = lib.singleton {
2022-11-29 13:05:42 +00:00
assertion =
!config.suites.desktop.enable || !config.suites.server.enable;
2022-11-29 13:05:42 +00:00
message = ''
Desktop profile is also enabled. The profiles `desktop` and `server`
are mutually exclusive.
'';
};
2022-11-29 13:05:42 +00:00
# Set the time zone. We're making it easier to track by assigning a
# universal time zone and what could be more universal than the
# "Coordinated Universal Time" (which does not abbreviates to UTC, WTF?).
time.timeZone = lib.mkForce "UTC";
# Add the usual manpages because it is not installed by default
# apparently.
environment.systemPackages = with pkgs; [ man-pages ];
2022-11-29 13:05:42 +00:00
# Most servers will have to be accessed for debugging so it is here. But
# be sure to set the appropriate public keys for the users from that
# server.
services.openssh = {
enable = lib.mkDefault true;
2022-11-29 13:05:42 +00:00
settings = {
# Making it verbose for services such as fail2ban.
LogLevel = "VERBOSE";
2023-01-11 05:23:20 +00:00
# Both are good for hardening as it only requires the keyfiles.
PasswordAuthentication = false;
PermitRootLogin = "no";
};
2023-01-11 05:23:39 +00:00
};
2022-12-28 06:13:23 +00:00
# It is expected that server configurations should be complete
# service-wise so we're not allowing user database to be mutable.
users.mutableUsers = lib.mkForce false;
2022-12-28 06:13:23 +00:00
2022-11-29 13:05:42 +00:00
# Most of the servers will be deployed with outside access in mind so
# generate them certificates. Anything with a private network, ehh... so
# just set it off.
2022-12-06 07:55:11 +00:00
#
# Don't forget to set your certificates or set DNS-related options for
# this.
2022-11-29 13:05:42 +00:00
security.acme = {
acceptTerms = true;
defaults.email = "admin+acme@foodogsquared.one";
2022-11-29 13:05:42 +00:00
};
# We're only going to deal with servers in English.
i18n.defaultLocale = lib.mkForce "en_US.UTF-8";
2023-01-11 05:23:39 +00:00
i18n.supportedLocales = lib.mkForce [ "en_US.UTF-8/UTF-8" ];
}
2022-11-29 13:05:42 +00:00
(lib.mkIf cfg.auto-upgrade.enable {
system.autoUpgrade = {
enable = true;
flake = "github:foo-dogsquared/nixos-config";
allowReboot = true;
persistent = true;
rebootWindow = {
lower = "22:00";
upper = "00:00";
};
dates = "weekly";
flags = [
"--update-input"
"nixpkgs"
"--commit-lock-file"
"--no-write-lock-file"
];
randomizedDelaySec = "1min";
};
})
2022-11-29 13:05:42 +00:00
(lib.mkIf cfg.cleanup.enable {
# Weekly garbage collection of Nix store. Unlike in the desktop config,
# this has looser requirements for the store items age for up to 21 days
# older.
nix.gc = {
automatic = true;
persistent = true;
dates = "weekly";
options = "--delete-older-than 21d";
};
# Run the optimizer.
nix.optimise = {
automatic = true;
dates = [ "weekly" ];
};
# Journal settings for retention.
services.journald.extraConfig = ''
MaxRetentionSec="3 month"
'';
2022-11-29 13:05:42 +00:00
})
]);
}