nix-config/config/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

339 lines
9.3 KiB
Nix
Raw Normal View History

{ config, hostRegistry, lib, nixos, pkgs, ssh-public-keys, zentralwerk, ... }:
# this file contains default configuration that may be turned on depending on other config settings.
# options should go to modules.
2023-01-16 20:24:33 +01:00
{
assertions = [
{
assertion = config.system.replaceRuntimeDependencies == [];
message = "system.replaceRuntimeDependencies causes hydra to build the system at evaluation time. It must be removed!";
}
2023-03-15 21:31:21 +01:00
{
assertion = lib.versions.major pkgs.ceph.version != 16;
message = "Please pin ceph to major version 16!";
}
];
2023-01-16 20:24:33 +01:00
boot = {
2024-04-15 16:26:00 +02:00
enableContainers = false; # should be enabled explicitly
2024-01-07 03:41:20 +01:00
loader.systemd-boot = {
configurationLimit = lib.mkDefault 10;
editor = false;
graceful = true;
};
2023-01-16 20:24:33 +01:00
kernel.sysctl = {
2023-10-16 01:27:04 +02:00
"kernel.panic" = 60; # reset 60 seconds after a kernel panic
2023-01-16 20:24:33 +01:00
"net.ipv4.tcp_congestion_control" = "bbr";
};
2024-01-07 03:41:20 +01:00
tmp.cleanOnBoot = true;
2023-01-16 20:24:33 +01:00
# recommend to turn off, only on by default for backwards compatibility
zfs.forceImportRoot = false;
};
c3d2 = {
2023-05-29 21:44:01 +02:00
# NOTE: this must be off, otherwise our nix binary cache creates a loop with itself
addBinaryCache = lib.mkForce false;
2023-01-16 20:24:33 +01:00
addKnownHosts = true;
2023-04-22 23:03:14 +02:00
sshKeys = ssh-public-keys;
2023-01-16 20:24:33 +01:00
};
2023-11-09 21:33:39 +01:00
documentation.enable = false;
2023-01-16 20:24:33 +01:00
environment = {
etc."resolv.conf" = lib.mkIf (!config.services.resolved.enable) {
text = lib.concatMapStrings (ns: ''
nameserver ${ns}
'') config.networking.nameservers;
};
2023-04-24 23:02:35 +02:00
gnome.excludePackages = with pkgs; with gnome; [
baobab
cheese
2023-01-16 20:24:33 +01:00
epiphany # we are using firefox or chromium and requires second webkitgtk
2023-07-18 19:56:02 +02:00
geary
2023-04-24 23:02:35 +02:00
gnome-calendar
gnome-contacts
gnome-maps
gnome-music
gnome-photos
gnome-weather
orca
simple-scan
totem
2023-01-16 20:24:33 +01:00
yelp # less webkitgtk's
];
2023-11-14 01:48:49 +01:00
interactiveShellInit = /* sh */ ''
# raise some awareness torwards failed services
2023-11-15 15:18:13 +01:00
systemctl --no-pager --failed || true
2023-11-14 01:48:49 +01:00
'';
noXlibs = !config.services.xserver.enable;
2023-01-16 20:24:33 +01:00
systemPackages = with pkgs; [
bmon
curl
dig
ethtool
fd
git
htop
iotop
2024-03-27 23:23:55 +01:00
(iproute2.overrideAttrs ({ configureFlags ? [], src, ... }: let
version = "6.8.0";
in {
inherit version;
src = pkgs.fetchurl {
url = "mirror://kernel/linux/utils/net/iproute2/iproute2-${version}.tar.xz";
hash = "sha256-A6bMo9cakI0fFfe0lb4rj+hR+UFFjcRmSQDX9F/PaM4=";
};
configureFlags = configureFlags ++ [
"--color" "auto"
];
}))
2023-12-17 17:26:04 +01:00
jq
2023-09-18 18:37:19 +02:00
lsof # to find lingering nix processes locking files in nix store
2023-01-16 20:24:33 +01:00
mtr
pv
ripgrep
2024-01-07 18:06:00 +01:00
rsync
2023-01-16 20:24:33 +01:00
screen
2023-09-10 15:50:51 +02:00
strace
2023-01-16 20:24:33 +01:00
tcpdump
tree
vim
wget
];
};
hardware.enableRedistributableFirmware = lib.mkDefault true;
i18n = {
defaultLocale = "en_US.UTF-8";
supportedLocales = [
"en_US.UTF-8/UTF-8"
"de_DE.UTF-8/UTF-8"
];
};
networking = {
firewall.allowedTCPPorts = lib.mkIf config.services.nginx.enable [
# proxy protocol used by public-access-proxy
8080
8443
];
nameservers = with hostRegistry.dnscache; [
ip4
ip6
"9.9.9.9"
];
useHostResolvConf = lib.mkIf (!config.services.resolved.enable) true;
};
2023-01-16 20:24:33 +01:00
nix = {
2023-01-17 00:35:16 +01:00
deleteChannels = true;
deleteUserProfiles = true;
gc = {
automatic = lib.mkDefault true;
dates = "06:00";
options = "--delete-older-than 21d";
randomizedDelaySec = "6h";
};
2023-02-01 01:27:35 +01:00
nixPath = [
2023-04-04 20:48:48 +02:00
"nixpkgs=${builtins.unsafeDiscardStringContext nixos}"
"nixos=${builtins.unsafeDiscardStringContext nixos}"
2023-02-01 01:27:35 +01:00
"nixos-config=/you/shall/deploy/from/the/flake"
];
2023-04-04 20:48:48 +02:00
registry.nixpkgs.flake = nixos;
2023-01-16 20:24:33 +01:00
settings = {
extra-experimental-features = "ca-derivations";
2023-11-27 00:46:56 +01:00
# if a download from hydra fails, we want to stop and retry it, instead of building it
fallback = false;
2023-01-16 20:24:33 +01:00
trusted-public-keys = [
2023-04-03 20:34:04 +02:00
"nix-cache.hq.c3d2.de:KZRGGnwOYzys6pxgM8jlur36RmkJQ/y8y62e52fj1ps="
2022-12-22 01:15:10 +01:00
];
stalled-download-timeout = 60; # in case hydra is not reachable fail faster
2023-01-16 20:24:33 +01:00
# don't self feed hydra
substituters = lib.mkIf (config.networking.hostName != "hydra") (
2023-04-03 20:34:04 +02:00
lib.mkBefore [ "https://nix-cache.hq.c3d2.de" ]
2023-01-16 20:24:33 +01:00
);
2022-12-22 01:15:10 +01:00
};
2023-01-16 20:24:33 +01:00
};
2023-05-19 02:20:57 +02:00
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (pkgs.lib.getName pkg) [
"drone.io"
"drone-runner-ssh"
"elasticsearch" # mastodon
];
2023-01-16 20:24:33 +01:00
# trust sandro to set good defaults in nixos-modules
opinionatedDefaults = true;
programs = {
fzf.keybindings = true;
2023-01-30 00:35:32 +01:00
git = {
enable = true;
# silence hints in various programs like drone
config.init.defaultBranch = "master";
};
2023-01-16 20:24:33 +01:00
tmux = {
enable = true;
historyLimit = 50000;
extraConfig = ''
# mouse control
set -g mouse on
# don't clear selection on copy
bind-key -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-selection-no-clear
bind-key -Tcopy-mode-vi y send -X copy-selection-no-clear
'';
2022-12-22 01:15:10 +01:00
};
2023-01-30 00:35:32 +01:00
2023-01-16 20:24:33 +01:00
vim.defaultEditor = true;
};
2023-01-17 00:35:25 +01:00
security.ldap.domainComponent = [ "c3d2" "de" ];
2023-01-16 20:24:33 +01:00
services = {
2023-12-04 01:40:03 +01:00
# set here explicitly, so that other modules can acces it like nixos-modules grafana
# keep in sync with nixos/modules/services/misc/portunus.nix
dex.settings.issuer = "https://${config.services.portunus.domain}/dex";
2023-07-01 23:43:15 +02:00
gitea.ldap = {
adminGroup = "gitea-admins";
userGroup = "gitea-users";
};
2023-01-16 20:24:33 +01:00
gnome = {
# less webkitgtk's
evolution-data-server.enable = lib.mkForce false;
gnome-initial-setup.enable = false;
2022-12-22 01:15:10 +01:00
};
2023-12-03 16:57:50 +01:00
grafana.oauth = {
adminGroup = "grafana-admins";
userGroup = "grafana-users";
};
2023-07-01 23:43:15 +02:00
hedgedoc.ldap.userGroup = "hedgedoc-users";
home-assistant.ldap = {
adminGroup = "home-assistant-admins";
userGroup = "home-assistant-users";
};
2023-07-01 23:43:15 +02:00
hydra.ldap = {
roleMappings = [
{ hydra-admins = "admin"; }
];
userGroup = "hydra-users";
};
mastodon.ldap.userGroup = "mastodon-users";
matrix-synapse.ldap.userGroup = "matrix-users";
nginx = {
appendHttpConfig = ''
log_format proxyCombined '$proxy_protocol_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log /var/log/nginx/access.log proxyCombined;
'';
commonServerConfig = with zentralwerk.lib.config.site.net.serv; ''
# https://docs.nginx.com/nginx/admin-guide/load-balancer/using-proxy-protocol/
set_real_ip_from ${hosts4.public-access-proxy};
set_real_ip_from ${hosts6.up4.public-access-proxy};
real_ip_header proxy_protocol;
proxy_set_header X-Real-IP $proxy_protocol_addr;
proxy_set_header X-Forwarded-For $proxy_protocol_addr;
'';
};
2023-01-18 01:52:47 +01:00
2023-01-16 20:24:33 +01:00
openssh = {
# Required for deployment and sops
enable = true;
2023-06-16 20:08:33 +02:00
settings = {
2024-01-28 01:17:00 +01:00
AcceptEnv = "SYSTEMD_PAGER";
LoginGraceTime = 30; # throw out unauthenticated connections earlier than the 120 default
2023-06-16 20:08:33 +02:00
PasswordAuthentication = lib.mkIf (!config.c3d2.k-ot.enable) false;
PermitRootLogin = lib.mkOverride 900 "prohibit-password";
};
2022-12-31 02:44:22 +01:00
};
2023-01-16 20:24:33 +01:00
portunus = with zentralwerk.lib.config.site.net.serv; {
domain = "auth.c3d2.de";
2023-02-23 00:35:25 +01:00
internalIp4 = hosts4.auth;
internalIp6 = hosts6.up4.auth;
2023-01-17 00:35:25 +01:00
ldapPreset = true;
2023-07-12 15:11:29 +02:00
# those can't be under hosts/*/default.nix because those are not imported for the auth microvm
2024-04-12 20:37:42 +02:00
seedSettings.groups = map (n: {
long_name = n;
name = lib.toLower (lib.replaceStrings [" "] ["-"] n);
permissions = { };
}) [
"Mail Users"
"Mobilizon Users"
"Vaultwarden Users"
"Vaultwarden Social Media Accounts"
];
2022-12-22 01:15:10 +01:00
};
2023-01-16 20:24:33 +01:00
postgresql.upgrade = {
extraArgs = [ "--link" ]
++ lib.optional (config ? microvm) "--jobs=${toString config.microvm.vcpu}";
2023-09-26 21:10:21 +02:00
newPackage = pkgs.postgresql_16;
2023-01-16 20:24:33 +01:00
stopServices = lib.optional config.services.nginx.enable "nginx"
++ lib.optional config.c3d2.hq.statistics.enable "collectd";
};
2023-10-16 01:27:04 +02:00
redis.vmOverCommit = true;
2023-01-16 20:24:33 +01:00
};
security.acme = {
acceptTerms = true;
defaults = {
email = "mail@c3d2.de";
# letsencrypt staging server with way higher rate limits
# server = "https://acme-staging-v02.api.letsencrypt.org/directory";
};
};
# does not suceed on installation which is okay
2023-05-16 18:49:51 +02:00
system.activationScripts.deleteOldSystemProfiles = lib.mkIf config.nix.gc.automatic ''
echo "Deleting old system profiles..."
2023-05-20 22:11:42 +02:00
${config.nix.package}/bin/nix-env --profile /nix/var/nix/profiles/system --delete-generations +10 || true
2023-05-16 18:49:51 +02:00
'';
2023-01-16 20:24:33 +01:00
systemd = {
2024-02-24 20:25:37 +01:00
# don't kick us out if one disk is missing
enableEmergencyMode = false;
2023-11-28 18:39:52 +01:00
# maybe set enable = false instead?
2023-07-05 23:13:08 +02:00
network.wait-online.anyInterface = true;
2023-05-29 20:59:21 +02:00
services.nix-daemon.serviceConfig = {
# kill all worker thread when restarting
KillMode = "control-group";
# restart if killed eg oom killed
Restart = "on-failure";
};
2023-01-16 20:24:33 +01:00
# Reboot on hang
watchdog = lib.mkIf (!config.boot.isContainer) {
runtimeTime = "15s";
rebootTime = "15s";
2022-12-22 01:15:10 +01:00
};
2023-01-16 20:24:33 +01:00
};
2022-12-22 01:15:10 +01:00
2023-01-16 20:24:33 +01:00
time.timeZone = lib.mkDefault "Europe/Berlin";
2022-12-22 01:15:10 +01:00
2023-12-20 23:14:15 +01:00
users.motdFile = ./motd;
2023-01-16 20:24:33 +01:00
}