This commit is contained in:
Reid 2024-03-28 01:38:40 -07:00
commit 132a109da8
15 changed files with 436 additions and 0 deletions

70
modules/security.nix Executable file
View file

@ -0,0 +1,70 @@
{ config, lib, options, pkgs, ... }:
with lib;
let
cfg = config.modules.security;
in {
options.modules.security = {
useDoas = mkEnableOption "use opendoas instead of sudo";
};
config = mkIf cfg.enable {
boot = {
tmp.useTmpfs = lib.mkDefault true;
tmp.cleanOnBoot = lib.mkDefault (!config.boot.tmp.useTmpfs);
kernel.sysctl = {
# magic sysrq key, allows low-level commands through keyboard input
"kernel.sysrq" = 0;
## TCP hardening
# prevent bogus ICMP errors from filling up logs
"net.ipv4.icmp_ignore_bogus_error_responses" = 1;
# do not accept IP source packets (we are not a router)
"net.ipv4.conf.all.accept_source_route" = 0;
"net.ipv6.conf.all.accept_source_route" = 0;
# don't send ICMP redirects (again, we're not a router)
"net.ipv4.conf.all.send_redirects" = 0;
"net.ipv4.conf.default.send_redirects" = 0;
# refuse ICMP redirects (MITM mitigations)
"net.ipv4.conf.all.accept_redirects" = 0;
"net.ipv4.conf.default.accept_redirects" = 0;
"net.ipv4.conf.all.secure_redirects" = 0;
"net.ipv4.conf.default.secure_redirects" = 0;
"net.ipv6.conf.all.accept_redirects" = 0;
"net.ipv6.conf.default.accept_redirects" = 0;
# protects against SYN flood attacks
"net.ipv4.tcp_syncookies" = 1;
# incomplete protection against TIME-WAIT assassination
"net.ipv4.tcp_rfc1337" = 1;
## TCP optimization
# TCP fastopen
"net.ipv4.tcp_fastopen" = 3;
# bufferbloat mitigations + improvement in throughput and latency
"net.ipv4.tcp_conjestion_control" = "bbr";
"net.core.default_qdisc" = "cake";
};
kernelModules = [ "tcp_bbr" ];
};
security = {
# prevents replacing the kernel without a reboot
protectKernelImage = true;
# rtkit allows unprivileged processes to use realtime scheduling
# polkit allows unprivileged processes to speak to privileged processes (ex. nmtui, reboot)
rtkit.enable = true;
polkit.enable = true;
};
# personal computer? no firewall ty :3
networking.firewall.enable = false;
} // (mkIf cfg.useDoas {
security.sudo.enable = false;
security.doas.enable = true;
security.doas.extraRules = [
{ users = [ config.user.name ]; noPass = true; persist = false; keepEnv = true; }
];
environment.systemPackages = with pkgs; [ doas-sudo-shim ];
});
}

29
modules/user.nix Normal file
View file

@ -0,0 +1,29 @@
{ config, pkgs, lib, options, ... }:
with lib;
with lib.my;
{
options = {
user = mkOpt types.attrs {};
};
config = {
user = rec {
name = "reidlab";
description = "awesome guy";
extraGroups = ["wheel" "input" "audio" "video" "storage"];
isNormalUser = true;
home = "/home/${name}";
group = name;
uid = 1000;
};
users.groups.${config.user.group} = {};
users.users.${config.user.name} = mkAliasDefinitions options.user;
home-manager.useUserPackages = true;
hm.home.username = config.user.name;
hm.home.homeDirectory = lib.mkForce config.user.home;
};
}

19
modules/xdg.nix Normal file
View file

@ -0,0 +1,19 @@
{ ... }:
{
config = {
hm.xdg.enable = true;
hm.xdg.userDirs = {
enable = true;
createDirectories = true;
desktop = "$HOME/desktop";
documents = "$HOME/documents";
download = "$HOME/downloads";
music = "$HOME/music";
pictures = "$HOME/pictures";
publicShare = "$HOME/public";
templates = "$HOME/templates";
videos = "$HOME/videos";
};
};
}