nixos-conf/base.nix

212 lines
5.9 KiB
Nix
Raw Normal View History

2024-05-23 13:39:48 +03:00
{ config, pkgs, ... }:
{
2024-09-06 10:45:06 +03:00
######################################## Packages ###############################################
2024-06-02 16:18:19 +03:00
environment.systemPackages = with pkgs; [
alacritty
2024-06-02 16:18:19 +03:00
tmux
git
nvi
2024-06-02 16:18:19 +03:00
p7zip
tree
2024-07-16 22:25:43 +03:00
btop
2024-06-02 16:18:19 +03:00
];
2024-09-06 10:45:06 +03:00
######################################## ZSH configuration ######################################
2024-06-02 16:18:19 +03:00
users.defaultUserShell = pkgs.zsh;
environment.shells = with pkgs; [ zsh ];
programs.zsh = {
2024-06-02 05:53:39 +03:00
enable = true;
2024-06-02 16:18:19 +03:00
autosuggestions.enable = true;
syntaxHighlighting.enable = true;
ohMyZsh = {
enable = true;
plugins = [
"history-substring-search"
"tmux"
];
theme = "af-magic";
};
interactiveShellInit = ''
ZSH_TMUX_AUTOSTART=false
ZSH_TMUX_AUTOQUIT=false
ZSH_TMUX_CONFIG=/etc/tmux.conf
2024-06-02 05:53:39 +03:00
'';
2024-06-02 16:18:19 +03:00
promptInit = ''
if [ -n "$IN_NIX_SHELL" ]; then
setopt PROMPT_SUBST
RPROMPT+='[nix]'
fi
2024-06-02 05:53:39 +03:00
'';
};
2024-05-23 13:39:48 +03:00
2024-09-06 10:45:06 +03:00
######################################## tmux configuration #####################################
2024-06-02 16:18:19 +03:00
programs.tmux.enable = true;
programs.tmux.extraConfig = ''
unbind C-b
set -g prefix M-w
bind M-w send-prefix
bind s split-window -v
bind v split-window -h
# Smart pane switching with awareness of Vim splits.
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l) || tmux select-pane -R"
bind -n C-Left select-pane -L
bind -n C-Right select-pane -R
bind -n C-Up select-pane -U
bind -n C-Down select-pane -D
# resize panes more easily
bind -r h resize-pane -L 10
bind -r j resize-pane -D 10
bind -r k resize-pane -U 10
bind -r l resize-pane -R 10
bind M-c attach -c "#{pane_current_path}"
set -s escape-time 0
2024-06-02 05:53:39 +03:00
'';
2024-05-23 13:39:48 +03:00
2024-09-06 10:45:06 +03:00
######################################## SSH and fail2ban configuration #########################
2024-07-05 16:12:27 +03:00
services.openssh = {
enable = true;
settings.PasswordAuthentication = false;
};
2024-06-02 16:18:19 +03:00
users.users.root.openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBbGREoK1uVny1s8FK3KZ74Wmaf0VtifhqPyK69C/Gez vili@helium"
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPivDyDYrCRBHRl9zup1Gj5vtyesOW/XKG/68kA8HLaW vili@lithium"
2024-06-02 16:18:19 +03:00
];
2024-05-23 13:39:48 +03:00
2024-07-05 16:12:27 +03:00
services.fail2ban = {
enable = true;
bantime = "1h";
bantime-increment = {
enable = true;
factor = "2";
formula = "ban.Time * (1 << (min(ban.Count, 6) * banFactor))";
maxtime = "90d";
};
jails = {
DEFAULT.settings = {
findtime = 3600;
};
};
};
2024-09-06 10:45:06 +03:00
######################################## Localization ###########################################
2024-06-02 16:18:19 +03:00
i18n.defaultLocale = "en_US.UTF-8";
2024-09-16 17:00:28 +03:00
i18n.extraLocaleSettings = {
LC_ADDRESS = "fi_FI.UTF-8";
LC_IDENTIFICATION = "fi_FI.UTF-8";
LC_MEASUREMENT = "fi_FI.UTF-8";
LC_MONETARY = "fi_FI.UTF-8";
LC_NAME = "fi_FI.UTF-8";
LC_NUMERIC = "fi_FI.UTF-8";
LC_PAPER = "fi_FI.UTF-8";
LC_TELEPHONE = "fi_FI.UTF-8";
LC_TIME = "fi_FI.UTF-8";
};
2024-06-02 16:18:19 +03:00
services.xserver.xkb = {
layout = "us,";
variant = "de_se_fi,";
};
console = pkgs.lib.mkForce {
font = "Lat2-Terminus16";
useXkbConfig = true; # use xkbOptions in tty.
2024-06-02 05:53:39 +03:00
};
2024-06-02 16:18:19 +03:00
time.timeZone = "Europe/Helsinki";
2024-09-06 10:45:06 +03:00
######################################## Memory management ######################################
zramSwap.enable = true;
swapDevices = [
{
device = "/var/lib/swapfile";
2024-08-28 11:52:00 +03:00
size = 8 * 1024;
}
];
2024-09-06 10:45:06 +03:00
######################################## Housekeeping ###########################################
2024-06-02 16:18:19 +03:00
system.autoUpgrade = {
enable = true;
dates = "04:00";
2024-06-02 05:53:39 +03:00
randomizedDelaySec = "30min";
allowReboot = true;
rebootWindow = {
lower = "03:30";
upper = "05:00";
};
2024-06-02 05:53:39 +03:00
};
2024-05-23 13:39:48 +03:00
2024-06-02 16:18:19 +03:00
nix = {
2024-09-09 12:49:29 +03:00
package = pkgs.nixVersions.nix_2_20;
2024-06-02 16:18:19 +03:00
settings = {
auto-optimise-store = true;
tarball-ttl = 0;
2024-08-05 15:18:15 +03:00
experimental-features = "verified-fetches";
2024-06-02 16:18:19 +03:00
};
gc = {
automatic = true;
options = "--delete-older-than 7d";
dates = "05:00";
randomizedDelaySec = "30min";
};
};
2024-09-06 10:45:06 +03:00
# Define systemd template unit for reporting status via ntfy
systemd.services =
let
2024-10-02 09:47:28 +03:00
services = [ "nixos-upgrade" ];
in
{
"notify-push@" = {
environment.SERVICE_ID = "%i";
path = [
"/run/wrappers"
"/run/current-system/sw"
];
script = ''
curl \
-H "Title:$(hostname) $SERVICE_ID $(systemctl show --property=Result $SERVICE_ID)" \
2024-09-10 11:26:31 +03:00
-d "$(journalctl --output cat -n 2 -u $SERVICE_ID)" \
https://ntfy.vsinerva.fi/service-notifs
'';
};
# Merge attributes for all monitored services
}
// (pkgs.lib.attrsets.genAttrs services (name: {
onFailure = pkgs.lib.mkBefore [ "notify-push@%i.service" ];
onSuccess = pkgs.lib.mkBefore [ "notify-push@%i.service" ];
}));
2024-09-06 10:45:06 +03:00
######################################## Misc. ##################################################
nixpkgs.config.allowUnfree = true;
networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.
networking.tempAddresses = "disabled";
2024-09-06 10:45:06 +03:00
users.mutableUsers = false; # Force all user management to happen throught nix-files
security.pam.loginLimits = [
{
domain = "*";
type = "soft";
item = "nofile";
value = "8192";
}
];
2024-09-06 10:45:06 +03:00
boot.loader = {
systemd-boot.enable = true;
efi.canTouchEfiVariables = true;
timeout = 0;
};
services.logind.lidSwitch = if config.boot.resumeDevice != "" then "hibernate" else "suspend";
2024-06-02 16:18:19 +03:00
}