flakes
This commit is contained in:
678
hosts/hel1-a/configuration.nix
Normal file
678
hosts/hel1-a/configuration.nix
Normal file
@@ -0,0 +1,678 @@
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
agenix,
|
||||
myData,
|
||||
...
|
||||
}: let
|
||||
backup_paths = {
|
||||
var_lib = {
|
||||
mountpoint = "/var/lib";
|
||||
zfs_name = "rpool/nixos/var/lib";
|
||||
paths = [
|
||||
"/var/lib/.snapshot-latest/gitea"
|
||||
"/var/lib/.snapshot-latest/headscale"
|
||||
"/var/lib/.snapshot-latest/matrix-synapse"
|
||||
];
|
||||
backup_at = "*-*-* 00:11:00";
|
||||
};
|
||||
var_log = {
|
||||
mountpoint = "/var/log";
|
||||
zfs_name = "rpool/nixos/var/log";
|
||||
paths = ["/var/log/.snapshot-latest/caddy/"];
|
||||
patterns = [
|
||||
"+ /var/log/.snapshot-latest/caddy/access-jakstys.lt.log-*.zst"
|
||||
"- *"
|
||||
];
|
||||
backup_at = "*-*-* 00:10:00";
|
||||
};
|
||||
};
|
||||
|
||||
turn_cert_dir = "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/turn.jakstys.lt";
|
||||
gitea_uidgid = 995;
|
||||
|
||||
# functions
|
||||
mountLatest = (
|
||||
{
|
||||
mountpoint,
|
||||
zfs_name,
|
||||
}: ''
|
||||
set -euo pipefail
|
||||
${pkgs.util-linux}/bin/umount ${mountpoint}/.snapshot-latest &>/dev/null || :
|
||||
mkdir -p ${mountpoint}/.snapshot-latest
|
||||
${pkgs.util-linux}/bin/mount -t zfs $(${pkgs.zfs}/bin/zfs list -H -t snapshot -o name ${zfs_name} | sort | tail -1) ${mountpoint}/.snapshot-latest
|
||||
''
|
||||
);
|
||||
|
||||
umountLatest = (
|
||||
{mountpoint, ...}: ''exec ${pkgs.util-linux}/bin/umount ${mountpoint}/.snapshot-latest''
|
||||
);
|
||||
in {
|
||||
imports = [
|
||||
./hardware-configuration.nix
|
||||
./zfs.nix
|
||||
];
|
||||
|
||||
boot.initrd.network = {
|
||||
enable = true;
|
||||
ssh = {
|
||||
enable = true;
|
||||
authorizedKeys = builtins.attrValues myData.ssh_pubkeys;
|
||||
hostKeys = ["/etc/secrets/initrd/ssh_host_ed25519_key"];
|
||||
};
|
||||
};
|
||||
|
||||
mj = {
|
||||
stateVersion = "22.11";
|
||||
timeZone = "UTC";
|
||||
|
||||
base.initrd = {
|
||||
enable = true;
|
||||
authorizedKeys = builtins.attrValues myData.ssh_pubkeys;
|
||||
hostKeys = ["/etc/secrets/initrd/ssh_host_ed25519_key"];
|
||||
};
|
||||
};
|
||||
|
||||
users = {
|
||||
users.git = {
|
||||
description = "Gitea Service";
|
||||
home = "/var/lib/gitea";
|
||||
useDefaultShell = true;
|
||||
group = "gitea";
|
||||
isSystemUser = true;
|
||||
uid = gitea_uidgid;
|
||||
};
|
||||
|
||||
groups.gitea.gid = gitea_uidgid;
|
||||
};
|
||||
|
||||
environment = {
|
||||
systemPackages = with pkgs; [
|
||||
git
|
||||
tmux
|
||||
htop
|
||||
#ncdu
|
||||
nmap
|
||||
ipset
|
||||
ngrep
|
||||
p7zip
|
||||
pwgen
|
||||
parted
|
||||
sqlite
|
||||
direnv
|
||||
tcpdump
|
||||
vimv-rs
|
||||
openssl
|
||||
bsdgames
|
||||
headscale
|
||||
mailutils
|
||||
nixos-option
|
||||
graphicsmagick
|
||||
];
|
||||
};
|
||||
|
||||
services = {
|
||||
tailscale.enable = true;
|
||||
|
||||
nsd = {
|
||||
enable = true;
|
||||
interfaces = [ "0.0.0.0" "::" ];
|
||||
zones = {
|
||||
"jakstys.lt.".data = myData.jakstysLTZone;
|
||||
};
|
||||
};
|
||||
|
||||
zfs = {
|
||||
autoScrub.enable = true;
|
||||
trim.enable = true;
|
||||
expandOnBoot = "all";
|
||||
};
|
||||
|
||||
openssh = {
|
||||
extraConfig = ''
|
||||
AcceptEnv GIT_PROTOCOL
|
||||
'';
|
||||
};
|
||||
|
||||
locate = {
|
||||
enable = true;
|
||||
locate = pkgs.plocate;
|
||||
localuser = null;
|
||||
};
|
||||
|
||||
sanoid = {
|
||||
enable = true;
|
||||
templates.prod = {
|
||||
hourly = 24;
|
||||
daily = 7;
|
||||
autosnap = true;
|
||||
autoprune = true;
|
||||
};
|
||||
datasets =
|
||||
lib.mapAttrs' (name: value: {
|
||||
name = value.zfs_name;
|
||||
value = {use_template = ["prod"];};
|
||||
})
|
||||
backup_paths;
|
||||
extraArgs = ["--verbose"];
|
||||
};
|
||||
|
||||
borgbackup.jobs =
|
||||
lib.mapAttrs' (name: value: let
|
||||
snapshot = {
|
||||
mountpoint = value.mountpoint;
|
||||
zfs_name = value.zfs_name;
|
||||
};
|
||||
rwpath = value.mountpoint + "/.snapshot-latest";
|
||||
in {
|
||||
name = name;
|
||||
value =
|
||||
{
|
||||
doInit = true;
|
||||
repo = "zh2769@zh2769.rsync.net:hel1-a.servers.jakst";
|
||||
encryption = {
|
||||
mode = "repokey-blake2";
|
||||
passCommand = "cat ${config.age.secrets.borgbackup-password.path}";
|
||||
};
|
||||
paths = value.paths;
|
||||
extraArgs = "--remote-path=borg1";
|
||||
compression = "auto,lzma";
|
||||
startAt = value.backup_at;
|
||||
readWritePaths = [rwpath];
|
||||
preHook = mountLatest snapshot;
|
||||
postHook = umountLatest snapshot;
|
||||
prune.keep = {
|
||||
within = "1d";
|
||||
daily = 7;
|
||||
weekly = 4;
|
||||
monthly = 3;
|
||||
};
|
||||
}
|
||||
// lib.optionalAttrs (value ? patterns) {
|
||||
patterns = value.patterns;
|
||||
};
|
||||
})
|
||||
backup_paths;
|
||||
|
||||
headscale = {
|
||||
enable = true;
|
||||
settings = {
|
||||
server_url = "https://vpn.jakstys.lt";
|
||||
ip_prefixes = [
|
||||
myData.tailscale_subnet.cidr
|
||||
"fd7a:115c:a1e0:59b0::/64"
|
||||
];
|
||||
log.level = "warn";
|
||||
dns_config = {
|
||||
nameservers = ["1.1.1.1" "8.8.4.4"];
|
||||
magic_dns = true;
|
||||
base_domain = "jakst";
|
||||
};
|
||||
oidc = {
|
||||
issuer = "https://git.jakstys.lt/";
|
||||
client_id = "1c5fe796-452c-458d-b295-71a9967642fc";
|
||||
client_secret_path = "/var/lib/headscale/oidc_client_secret"; # TODO move to secrets
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
gitea = {
|
||||
enable = true;
|
||||
user = "git";
|
||||
database.user = "git";
|
||||
settings = {
|
||||
admin.DISABLE_REGULAR_ORG_CREATION = true;
|
||||
api.ENABLE_SWAGGER = false;
|
||||
mirror.ENABLED = false;
|
||||
other.SHOW_FOOTER_VERSION = false;
|
||||
packages.ENABLED = false;
|
||||
repository = {
|
||||
DEFAULT_REPO_UNITS = "repo.code,repo.releases";
|
||||
DISABLE_MIGRATIONS = true;
|
||||
DISABLE_STARS = true;
|
||||
ENABLE_PUSH_CREATE_USER = true;
|
||||
};
|
||||
security.LOGIN_REMEMBER_DAYS = 30;
|
||||
server = {
|
||||
ENABLE_GZIP = true;
|
||||
LANDING_PAGE = "/motiejus";
|
||||
ROOT_URL = "https://git.jakstys.lt";
|
||||
HTTP_ADDR = "127.0.0.1";
|
||||
HTTP_PORT = 3000;
|
||||
DOMAIN = "git.jakstys.lt";
|
||||
};
|
||||
service = {
|
||||
DISABLE_REGISTRATION = true;
|
||||
ENABLE_TIMETRACKING = false;
|
||||
ENABLE_USER_HEATMAP = false;
|
||||
SHOW_MILESTONES_DASHBOARD_PAGE = false;
|
||||
COOKIE_SECURE = true;
|
||||
};
|
||||
log.LEVEL = "Error";
|
||||
# TODO: does not work with 1.7.4, getting error
|
||||
# in the UI when testing the email sending workflow.
|
||||
#mailer = {
|
||||
# ENABLED = true;
|
||||
# MAILER_TYPE = "sendmail";
|
||||
# FROM = "<noreply@jakstys.lt>";
|
||||
# SENDMAIL_PATH = "${pkgs.system-sendmail}/bin/sendmail";
|
||||
#};
|
||||
"service.explore".DISABLE_USERS_PAGE = true;
|
||||
};
|
||||
};
|
||||
|
||||
caddy = {
|
||||
enable = true;
|
||||
email = "motiejus+acme@jakstys.lt";
|
||||
virtualHosts."recordrecap.jakstys.lt".extraConfig = ''
|
||||
reverse_proxy vno1-oh2.servers.jakst:8080
|
||||
'';
|
||||
virtualHosts."www.recordrecap.jakstys.lt".extraConfig = ''
|
||||
redir https://recordrecap.jakstys.lt
|
||||
'';
|
||||
virtualHosts."vpn.jakstys.lt".extraConfig = ''
|
||||
reverse_proxy 127.0.0.1:8080
|
||||
'';
|
||||
virtualHosts."git.jakstys.lt".extraConfig = ''
|
||||
reverse_proxy 127.0.0.1:3000
|
||||
'';
|
||||
virtualHosts."turn.jakstys.lt".extraConfig = ''
|
||||
redir https://jakstys.lt
|
||||
'';
|
||||
virtualHosts."www.jakstys.lt".extraConfig = ''
|
||||
redir https://jakstys.lt
|
||||
'';
|
||||
virtualHosts."fwmine.jakstys.lt".extraConfig = ''
|
||||
reverse_proxy fwmine.motiejus.jakst:8080
|
||||
'';
|
||||
virtualHosts."jakstys.lt" = {
|
||||
logFormat = ''
|
||||
output file ${config.services.caddy.logDir}/access-jakstys.lt.log {
|
||||
roll_disabled
|
||||
}
|
||||
'';
|
||||
extraConfig = ''
|
||||
header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
|
||||
|
||||
header /_/* Cache-Control "public, max-age=31536000, immutable"
|
||||
|
||||
root * /var/www/jakstys.lt
|
||||
file_server {
|
||||
precompressed br gzip
|
||||
}
|
||||
|
||||
@matrixMatch {
|
||||
path /.well-known/matrix/client
|
||||
path /.well-known/matrix/server
|
||||
}
|
||||
header @matrixMatch Content-Type application/json
|
||||
header @matrixMatch Access-Control-Allow-Origin *
|
||||
header @matrixMatch Cache-Control "public, max-age=3600, immutable"
|
||||
|
||||
handle /.well-known/matrix/client {
|
||||
respond "{\"m.homeserver\": {\"base_url\": \"https://jakstys.lt\"}}" 200
|
||||
}
|
||||
handle /.well-known/matrix/server {
|
||||
respond "{\"m.server\": \"jakstys.lt:443\"}" 200
|
||||
}
|
||||
|
||||
handle /_matrix/* {
|
||||
encode gzip
|
||||
reverse_proxy http://127.0.0.1:8008
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
coturn = {
|
||||
enable = true;
|
||||
min-port = 49152;
|
||||
max-port = 49999;
|
||||
no-tcp-relay = true;
|
||||
realm = "turn.jakstys.lt";
|
||||
cert = "/run/coturn/tls-cert.pem";
|
||||
pkey = "/run/coturn/tls-key.pem";
|
||||
static-auth-secret-file = "\${CREDENTIALS_DIRECTORY}/static-auth-secret";
|
||||
extraConfig = ''
|
||||
verbose
|
||||
no-multicast-peers
|
||||
denied-peer-ip=10.0.0.0-10.255.255.255
|
||||
denied-peer-ip=192.168.0.0-192.168.255.255
|
||||
denied-peer-ip=172.16.0.0-172.31.255.255
|
||||
denied-peer-ip=${myData.tailscale_subnet.range}
|
||||
'';
|
||||
};
|
||||
|
||||
# TODO: app_service_config_files
|
||||
matrix-synapse = {
|
||||
enable = true;
|
||||
settings = {
|
||||
server_name = "jakstys.lt";
|
||||
admin_contact = "motiejus@jakstys.lt";
|
||||
enable_registration = false;
|
||||
report_stats = true;
|
||||
signing_key_path = "/run/matrix-synapse/jakstys_lt_signing_key";
|
||||
extraConfigFiles = ["/run/matrix-synapse/secrets.yaml"];
|
||||
log_config = pkgs.writeText "log.config" ''
|
||||
version: 1
|
||||
formatters:
|
||||
precise:
|
||||
format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
|
||||
handlers:
|
||||
console:
|
||||
class: logging.StreamHandler
|
||||
formatter: precise
|
||||
loggers:
|
||||
synapse.storage.SQL:
|
||||
level: WARN
|
||||
root:
|
||||
level: ERROR
|
||||
handlers: [console]
|
||||
disable_existing_loggers: false
|
||||
'';
|
||||
public_baseurl = "https://jakstys.lt/";
|
||||
database.name = "sqlite3";
|
||||
url_preview_enabled = false;
|
||||
max_upload_size = "50M";
|
||||
turn_allow_guests = false;
|
||||
turn_uris = [
|
||||
"turn:turn.jakstys.lt:3487?transport=udp"
|
||||
"turn:turn.jakstys.lt:3487?transport=tcp"
|
||||
"turns:turn.jakstys.lt:5349?transport=udp"
|
||||
"turns:turn.jakstys.lt:5349?transport=tcp"
|
||||
];
|
||||
rc_messages_per_second = 0.2;
|
||||
rc_message_burst_count = 10.0;
|
||||
federation_rc_window_size = 1000;
|
||||
federation_rc_sleep_limit = 10;
|
||||
federation_rc_sleep_delay = 500;
|
||||
federation_rc_reject_limit = 50;
|
||||
federation_rc_concurrent = 3;
|
||||
allow_profile_lookup_over_federation = false;
|
||||
thumbnail_sizes = [
|
||||
{
|
||||
width = 32;
|
||||
height = 32;
|
||||
method = "crop";
|
||||
}
|
||||
{
|
||||
width = 96;
|
||||
height = 96;
|
||||
method = "crop";
|
||||
}
|
||||
{
|
||||
width = 320;
|
||||
height = 240;
|
||||
method = "scale";
|
||||
}
|
||||
{
|
||||
width = 640;
|
||||
height = 480;
|
||||
method = "scale";
|
||||
}
|
||||
{
|
||||
width = 800;
|
||||
height = 600;
|
||||
method = "scale";
|
||||
}
|
||||
];
|
||||
user_directory = {
|
||||
enabled = true;
|
||||
search_all_users = false;
|
||||
prefer_local_users = true;
|
||||
};
|
||||
allow_device_name_lookup_over_federation = false;
|
||||
email = {
|
||||
smtp_host = "127.0.0.1";
|
||||
smtp_port = 25;
|
||||
notf_for_new_users = false;
|
||||
notif_from = "Jakstys %(app)s homeserver <noreply@jakstys.lt>";
|
||||
};
|
||||
include_profile_data_on_invite = false;
|
||||
password_config.enabled = true;
|
||||
require_auth_for_profile_requests = true;
|
||||
};
|
||||
};
|
||||
|
||||
postfix = {
|
||||
enable = true;
|
||||
enableSmtp = true;
|
||||
networks = [
|
||||
"127.0.0.1/8"
|
||||
"[::ffff:127.0.0.0]/104"
|
||||
"[::1]/128"
|
||||
myData.tailscale_subnet.cidr
|
||||
];
|
||||
hostname = "${config.networking.hostName}.${config.networking.domain}";
|
||||
relayHost = "smtp.sendgrid.net";
|
||||
relayPort = 587;
|
||||
mapFiles = {
|
||||
sasl_passwd = config.age.secrets.sasl-passwd.path;
|
||||
};
|
||||
extraConfig = ''
|
||||
smtp_sasl_auth_enable = yes
|
||||
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
|
||||
smtp_sasl_security_options = noanonymous
|
||||
smtp_sasl_tls_security_options = noanonymous
|
||||
smtp_tls_security_level = encrypt
|
||||
header_size_limit = 4096000
|
||||
'';
|
||||
};
|
||||
|
||||
logrotate = {
|
||||
settings = {
|
||||
"/var/log/caddy/access-jakstys.lt.log" = {
|
||||
rotate = 60;
|
||||
frequency = "daily";
|
||||
dateext = true;
|
||||
dateyesterday = true;
|
||||
compress = true;
|
||||
compresscmd = "${pkgs.zstd}/bin/zstd";
|
||||
compressext = ".zst";
|
||||
compressoptions = "--long -19";
|
||||
uncompresscmd = "${pkgs.zstd}/bin/unzstd";
|
||||
postrotate = "${pkgs.systemd}/bin/systemctl restart caddy";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sshguard = {
|
||||
enable = true;
|
||||
blocktime = 900;
|
||||
whitelist = [
|
||||
"192.168.0.0/16"
|
||||
myData.tailscale_subnet.cidr
|
||||
myData.ips.vno1
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
networking = {
|
||||
hostName = "hel1-a";
|
||||
domain = "jakstys.lt";
|
||||
firewall = let
|
||||
coturn = with config.services.coturn; [
|
||||
{
|
||||
from = min-port;
|
||||
to = max-port;
|
||||
}
|
||||
];
|
||||
in {
|
||||
allowedTCPPorts = [
|
||||
53
|
||||
80
|
||||
443
|
||||
3478 # turn/headscale
|
||||
5349 # turn
|
||||
5350 # turn
|
||||
];
|
||||
allowedUDPPorts = [
|
||||
53
|
||||
443
|
||||
3478 # turn
|
||||
41641 # tailscale
|
||||
];
|
||||
allowedUDPPortRanges = coturn;
|
||||
logRefusedConnections = false;
|
||||
checkReversePath = "loose"; # for tailscale
|
||||
};
|
||||
};
|
||||
|
||||
system = {
|
||||
# TODO: run the upgrades after the backup service is complete
|
||||
autoUpgrade.enable = true;
|
||||
autoUpgrade = {
|
||||
allowReboot = true;
|
||||
dates = "01:00";
|
||||
rebootWindow = {
|
||||
lower = "01:00";
|
||||
upper = "03:00";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
nix = {
|
||||
gc = {
|
||||
automatic = true;
|
||||
dates = "daily";
|
||||
options = "--delete-older-than 14d";
|
||||
};
|
||||
extraOptions = ''
|
||||
experimental-features = nix-command flakes
|
||||
trusted-users = motiejus
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d /run/matrix-synapse 0700 matrix-synapse matrix-synapse -"
|
||||
];
|
||||
|
||||
systemd.services =
|
||||
{
|
||||
"make-snapshot-dirs" = let
|
||||
vals = builtins.attrValues backup_paths;
|
||||
mountpoints = builtins.catAttrs "mountpoint" vals;
|
||||
unique_mountpoints = lib.unique mountpoints;
|
||||
in {
|
||||
description = "prepare snapshot directories for backups";
|
||||
wantedBy = ["multi-user.target"];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = builtins.map (d: "${pkgs.coreutils}/bin/mkdir -p ${d}/.snapshot-latest") unique_mountpoints;
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
};
|
||||
|
||||
coturn = {
|
||||
preStart = ''
|
||||
ln -sf ''${CREDENTIALS_DIRECTORY}/tls-key.pem /run/coturn/tls-key.pem
|
||||
ln -sf ''${CREDENTIALS_DIRECTORY}/tls-cert.pem /run/coturn/tls-cert.pem
|
||||
'';
|
||||
unitConfig.ConditionPathExists = [
|
||||
"${turn_cert_dir}/turn.jakstys.lt.key"
|
||||
"${turn_cert_dir}/turn.jakstys.lt.crt"
|
||||
];
|
||||
serviceConfig.LoadCredential = [
|
||||
"static-auth-secret:${config.age.secrets.turn-static-auth-secret.path}"
|
||||
"tls-key.pem:${turn_cert_dir}/turn.jakstys.lt.key"
|
||||
"tls-cert.pem:${turn_cert_dir}/turn.jakstys.lt.crt"
|
||||
];
|
||||
};
|
||||
|
||||
headscale = {
|
||||
unitConfig.StartLimitIntervalSec = "5m";
|
||||
|
||||
# Allow restarts for up to a minute. A start
|
||||
# itself may take a while, thus the window of restart
|
||||
# is higher.
|
||||
unitConfig.StartLimitBurst = 50;
|
||||
serviceConfig.RestartSec = 1;
|
||||
};
|
||||
|
||||
matrix-synapse = let
|
||||
# TODO https://github.com/NixOS/nixpkgs/pull/222336 replace with `preStart`
|
||||
secretsScript = pkgs.writeShellScript "write-secrets" ''
|
||||
set -euo pipefail
|
||||
umask 077
|
||||
ln -sf ''${CREDENTIALS_DIRECTORY}/jakstys_lt_signing_key /run/matrix-synapse/jakstys_lt_signing_key
|
||||
cat > /run/matrix-synapse/secrets.yaml <<EOF
|
||||
registration_shared_secret: "$(cat ''${CREDENTIALS_DIRECTORY}/registration_shared_secret)"
|
||||
macaroon_secret_key: "$(cat ''${CREDENTIALS_DIRECTORY}/macaroon_secret_key)"
|
||||
turn_shared_secret: "$(cat ''${CREDENTIALS_DIRECTORY}/turn_shared_secret)"
|
||||
EOF
|
||||
'';
|
||||
in {
|
||||
serviceConfig.ExecStartPre = ["" secretsScript];
|
||||
serviceConfig.LoadCredential = [
|
||||
"jakstys_lt_signing_key:${config.age.secrets.synapse-jakstys-signing-key.path}"
|
||||
"registration_shared_secret:${config.age.secrets.synapse-registration-shared-secret.path}"
|
||||
"macaroon_secret_key:${config.age.secrets.synapse-macaroon-secret-key.path}"
|
||||
"turn_shared_secret:${config.age.secrets.turn-static-auth-secret.path}"
|
||||
];
|
||||
};
|
||||
|
||||
cert-watcher = {
|
||||
description = "Restart coturn when tls key/cert changes";
|
||||
wantedBy = ["multi-user.target"];
|
||||
unitConfig = {
|
||||
StartLimitIntervalSec = 10;
|
||||
StartLimitBurst = 5;
|
||||
};
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${pkgs.systemd}/bin/systemctl restart coturn.service";
|
||||
};
|
||||
};
|
||||
|
||||
# https://northernlightlabs.se/2014-07-05/systemd-status-mail-on-unit-failure.html
|
||||
"unit-status-mail@" = let
|
||||
script = pkgs.writeShellScript "unit-status-mail" ''
|
||||
set -e
|
||||
MAILTO="motiejus+alerts@jakstys.lt"
|
||||
UNIT=$1
|
||||
EXTRA=""
|
||||
for e in "''${@:2}"; do
|
||||
EXTRA+="$e"$'\n'
|
||||
done
|
||||
UNITSTATUS=$(${pkgs.systemd}/bin/systemctl status "$UNIT")
|
||||
${pkgs.postfix}/bin/sendmail $MAILTO <<EOF
|
||||
Subject:Status mail for unit: $UNIT
|
||||
|
||||
Status report for unit: $UNIT
|
||||
$EXTRA
|
||||
|
||||
$UNITSTATUS
|
||||
EOF
|
||||
|
||||
echo -e "Status mail sent to: $MAILTO for unit: $UNIT"
|
||||
'';
|
||||
in {
|
||||
description = "Send an email on unit failure";
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
ExecStart = ''${script} "%I" "Hostname: %H" "Machine ID: %m" "Boot ID: %b" '';
|
||||
};
|
||||
};
|
||||
|
||||
zfs-scrub.unitConfig.OnFailure = "unit-status-mail@zfs-scrub.service";
|
||||
nixos-upgrade.unitConfig.OnFailure = "unit-status-mail@nixos-upgrade.service";
|
||||
}
|
||||
// lib.mapAttrs' (name: value: {
|
||||
name = "borgbackup-job-${name}";
|
||||
value = {
|
||||
unitConfig.OnFailure = "unit-status-mail@borgbackup-job-${name}.service";
|
||||
};
|
||||
})
|
||||
backup_paths;
|
||||
|
||||
systemd.paths = {
|
||||
cert-watcher = {
|
||||
wantedBy = ["multi-user.target"];
|
||||
pathConfig = {
|
||||
PathChanged = "${turn_cert_dir}/turn.jakstys.lt.crt";
|
||||
Unit = "cert-watcher.service";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
69
hosts/hel1-a/hardware-configuration.nix
Normal file
69
hosts/hel1-a/hardware-configuration.nix
Normal file
@@ -0,0 +1,69 @@
|
||||
# Do not modify this file! It was generated by ‘nixos-generate-config’
|
||||
# and may be overwritten by future invocations. Please make changes
|
||||
# to /etc/nixos/configuration.nix instead.
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
modulesPath,
|
||||
...
|
||||
}: {
|
||||
imports = [(modulesPath + "/profiles/qemu-guest.nix")];
|
||||
boot.initrd.availableKernelModules = ["ata_piix" "virtio_pci" "virtio_scsi" "xhci_pci" "sd_mod" "sr_mod"];
|
||||
boot.initrd.kernelModules = [];
|
||||
boot.kernelModules = [];
|
||||
boot.extraModulePackages = [];
|
||||
|
||||
fileSystems."/" = {
|
||||
device = "rpool/nixos/root";
|
||||
fsType = "zfs";
|
||||
options = ["zfsutil" "X-mount.mkdir"];
|
||||
};
|
||||
|
||||
fileSystems."/home" = {
|
||||
device = "rpool/nixos/home";
|
||||
fsType = "zfs";
|
||||
options = ["zfsutil" "X-mount.mkdir"];
|
||||
};
|
||||
|
||||
fileSystems."/var/lib" = {
|
||||
device = "rpool/nixos/var/lib";
|
||||
fsType = "zfs";
|
||||
options = ["zfsutil" "X-mount.mkdir"];
|
||||
};
|
||||
|
||||
fileSystems."/var/log" = {
|
||||
device = "rpool/nixos/var/log";
|
||||
fsType = "zfs";
|
||||
options = ["zfsutil" "X-mount.mkdir"];
|
||||
};
|
||||
|
||||
fileSystems."/boot" = {
|
||||
device = "bpool/nixos/root";
|
||||
fsType = "zfs";
|
||||
options = ["zfsutil" "X-mount.mkdir"];
|
||||
};
|
||||
|
||||
fileSystems."/boot/efis/scsi-0QEMU_QEMU_HARDDISK_9233346-part1" = {
|
||||
device = "/dev/disk/by-uuid/B6D7-D52E";
|
||||
fsType = "vfat";
|
||||
};
|
||||
|
||||
#fileSystems."/boot/efi" =
|
||||
# { device = "/boot/efis/scsi-0QEMU_QEMU_HARDDISK_9233346-part1";
|
||||
# fsType = "none";
|
||||
# options = [ "bind" ];
|
||||
# };
|
||||
|
||||
swapDevices = [{device = "/dev/disk/by-uuid/03ebe703-aa24-4ee5-a7c3-f8614ee779b0";}];
|
||||
|
||||
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
|
||||
# (the default) this is the recommended approach. When using systemd-networkd it's
|
||||
# still possible to use this option, but it's recommended to use it in conjunction
|
||||
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
|
||||
networking.useDHCP = lib.mkDefault true;
|
||||
# networking.interfaces.ens3.useDHCP = lib.mkDefault true;
|
||||
|
||||
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
||||
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
borgbackup-password: ENC[AES256_GCM,data:igLuxWZujydxdJO8Qt7sIOhIT9SqOkCvjw==,iv:pHk2V/VBb/HzHGieHyL4KY1RpmN6bqjjSDuTTnsH4bM=,tag:36aSlD6zY3AXE5X9ejs6CA==,type:str]
|
||||
sops:
|
||||
kms: []
|
||||
gcp_kms: []
|
||||
azure_kv: []
|
||||
hc_vault: []
|
||||
age:
|
||||
- recipient: age1wxwfy32jwskgzudzc8kvvx4uya5kr6lc5vp03y07ly0wpe3jk9gqqree6q
|
||||
enc: |
|
||||
-----BEGIN AGE ENCRYPTED FILE-----
|
||||
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSByNldGbmdndDJSclV5TFJ2
|
||||
aVNhR3hlSEdiaGVBVk5ReTN3TmM0ckNFNVZJCmtmdkdyT0ZBNUVmemNvaFlaMnda
|
||||
eXBpdEtDNFlNNkdBNVQxSloxc0dMcVUKLS0tIDZWZ3lvTWYzUHBxd3ZOa3UyREY5
|
||||
YmdScHFndG1leTl0VFo0dzh2SjhZTU0Kp3aiUTvTWMzw6y+D0ELT9BE4enrJAVDD
|
||||
1c0TvbFwDAJI3KB8T/Mz23qerExtZZQeCnm9zQKd+NsSKZCf52JEkg==
|
||||
-----END AGE ENCRYPTED FILE-----
|
||||
lastmodified: "2023-04-06T20:01:44Z"
|
||||
mac: ENC[AES256_GCM,data:PRjs8bZ/DGGlfDjRexvImDdAuE/W74HPa+KdQtE1Qktu6nz1cqlFy8a+CiA/mw+Y3P4NntzXHxU30sONrZWXA+n5RXAn8kMgpOYzRWqZWn0zzIyfhZ9+jPmP7uLpJWGZIEayw8NRfHGthDb7SLTnM9OpbkIP9dl4NgMSvn0A2MA=,iv:ma2ekXqtJGlTE2lAIw9YapvtXns/P1BwSgj+Ly4W+gE=,tag:z/ypCNkpdi2B1BFoZx5Jyw==,type:str]
|
||||
pgp:
|
||||
- created_at: "2023-04-05T19:33:35Z"
|
||||
enc: |
|
||||
-----BEGIN PGP MESSAGE-----
|
||||
|
||||
hQIMAznIq2pQRYaoARAApA2PMariUuuZ5D+XKf2W8od3oaTzGH9ttu6u7jNg2lqX
|
||||
3Ov1jbvUhT+stH5+DjbeApxxRJPcxMa3cA8g8907b3MagtyJYfxYJbqRNur2kOfy
|
||||
o4VlogFPTTIeeDP9hexX8p6jHC/lXPcT65B8Puj5NbTbitK9pP2RCQnvBG5vm2bB
|
||||
g+d4xiVfhtkt6Wv+m3oBdXO6mLn2tsakBEfseGJuovNpFd469ym9pqP0UpMEWtMy
|
||||
ezODZEbKsxvdUA+pa0wbTo5cQ+G5Pe2BjxNjfO2i4QgEPW5bCkeYDjN5uN9OgnxG
|
||||
zCMrr/PGrLDfebxU0YJqqkfLtmwgJpYKFNuwa6eLG7aOi3ahEsS9WUzLF/7nuTky
|
||||
p1+tOa6VRtQ1nTO0cV3XX9F6Pq/mtp5oozQUBhTzRndpO6Ju7luqzjNEvlS9ILzf
|
||||
w+3lxn/1nvwklBt9S9b2OOhf12iGPfoVye3lhXCSo6cNyk6uIs2fW/n7UXTJgG0W
|
||||
M5Zv5ygXbJwL3SyVaO9moL4ZSvllbwigI4MfSOoAH8P1Tzt/eyrfb3lL282b1N4c
|
||||
7KuTrWju3ml69QbulcN3Fae8ID+U8plcbpVv5f/v4zW4KPJBIN33D9InFzzwaBDF
|
||||
m2ESR/nsRMeLpR1StPz3SoPERLQ9PdLIuDp449O+EPgOK26yAvGiO+E4vfGQMpzS
|
||||
XAEdM3mNnGT8BTgChbPK+Khx0U0kJc2s9OjmW2aGEHNLeiPWcaj02EQ13rtH5q3c
|
||||
YFXzo8Ymlg3YEemwBY9LNVfGXmNUEgI8FYlh2mFwAwv3IdCjW7JsCwwsPE8C
|
||||
=KfCh
|
||||
-----END PGP MESSAGE-----
|
||||
fp: 5F6B7A8A92A260A437049BEB6F133A0C1C2848D7
|
||||
unencrypted_suffix: _unencrypted
|
||||
version: 3.7.3
|
||||
36
hosts/hel1-a/zfs.nix
Normal file
36
hosts/hel1-a/zfs.nix
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}: {
|
||||
boot.supportedFilesystems = ["zfs"];
|
||||
networking.hostId = "cd1a441c";
|
||||
boot.kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages;
|
||||
boot.loader.efi.efiSysMountPoint = "/boot/efi";
|
||||
boot.loader.efi.canTouchEfiVariables = false;
|
||||
boot.loader.generationsDir.copyKernels = true;
|
||||
boot.loader.grub.efiInstallAsRemovable = true;
|
||||
boot.loader.grub.enable = true;
|
||||
boot.loader.grub.version = 2;
|
||||
boot.loader.grub.copyKernels = true;
|
||||
boot.loader.grub.efiSupport = true;
|
||||
boot.loader.grub.zfsSupport = true;
|
||||
#boot.loader.grub.extraPrepareConfig = ''
|
||||
# mkdir -p /boot/efis
|
||||
# for i in /boot/efis/*; do mount $i ; done
|
||||
#
|
||||
# mkdir -p /boot/efi
|
||||
# mount /boot/efi
|
||||
#'';
|
||||
#boot.loader.grub.extraInstallCommands = ''
|
||||
#ESP_MIRROR=$(mktemp -d)
|
||||
#cp -r /boot/efi/EFI $ESP_MIRROR
|
||||
#for i in /boot/efis/*; do
|
||||
# cp -r $ESP_MIRROR/EFI $i
|
||||
#done
|
||||
#rm -rf $ESP_MIRROR
|
||||
#'';
|
||||
boot.loader.grub.devices = [
|
||||
"/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_9233346"
|
||||
];
|
||||
}
|
||||
@@ -9,11 +9,9 @@ in {
|
||||
mj = {
|
||||
stateVersion = "23.05";
|
||||
timeZone = "UTC";
|
||||
stubPasswords = true;
|
||||
};
|
||||
|
||||
users.users.vm.isSystemUser = true;
|
||||
users.users.vm.initialPassword = "test";
|
||||
|
||||
environment = {
|
||||
systemPackages = with pkgs; [
|
||||
tmux
|
||||
@@ -24,6 +22,7 @@ in {
|
||||
services = {
|
||||
nsd = {
|
||||
enable = true;
|
||||
interfaces = [ "0.0.0.0" "::" ];
|
||||
zones = {
|
||||
"jakstys.lt.".data = myData.jakstysLTZone;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user