configuration.nix/nixos/modules/default.nix

640 lines
20 KiB
Nix
Raw Normal View History

2024-08-07 18:44:14 +02:00
top @ { inputs, moduleWithSystem, ... }: {
flake.nixosModules = {
2024-08-07 18:44:14 +02:00
grub = moduleWithSystem ({ ... }: { pkgs, ... }: {
boot = {
loader = {
2024-08-07 18:44:14 +02:00
grub =
let
theme = pkgs.sleek-grub-theme.override {
withBanner = "Hello Ivan";
withStyle = "bigSur";
};
in
{
enable = pkgs.lib.mkDefault true;
useOSProber = true;
efiSupport = true;
device = "nodev";
theme = theme;
splashImage = "${theme}/background.png";
2024-08-04 19:08:59 +02:00
};
efi.canTouchEfiVariables = true;
};
};
2024-07-06 17:10:57 +02:00
});
2024-08-07 18:44:14 +02:00
base = moduleWithSystem ({ ... }: { pkgs, ... }: {
imports = [ inputs.hosts.nixosModule ];
2024-07-05 13:29:07 +02:00
system.stateVersion = top.config.flake.stateVersion;
2024-08-07 18:44:14 +02:00
nix = { extraOptions = ''experimental-features = nix-command flakes''; };
i18n.supportedLocales = [ "all" ];
2024-07-04 08:38:33 +02:00
time.timeZone = "Europe/Prague";
environment = {
2024-08-07 18:44:14 +02:00
systemPackages = with pkgs; [ cmatrix uutils-coreutils-noprefix cryptsetup fd file git glibc gnumake mlocate openssh openssl procs ripgrep srm unzip vim zip just nixos-install-tools tshark ];
sessionVariables = { MAKEFLAGS = "-j 4"; };
shells = with pkgs; [ bash zsh nushell ];
2024-08-03 20:16:58 +02:00
enableAllTerminfo = true;
2024-07-04 08:38:33 +02:00
};
2024-08-02 11:37:59 +02:00
users.defaultUserShell = pkgs.zsh;
2024-08-07 17:41:33 +02:00
programs = {
zsh.enable = true;
nix-ld.enable = true;
};
2024-08-02 18:46:46 +02:00
services = {
dbus.enable = true;
2024-08-07 17:41:33 +02:00
logind = {
killUserProcesses = true;
powerKeyLongPress = "reboot";
};
};
networking = {
stevenBlackHosts = {
enable = true;
blockFakenews = true;
blockGambling = true;
blockSocial = true;
};
2024-08-02 18:46:46 +02:00
};
2024-07-04 08:38:33 +02:00
});
2024-08-07 18:44:14 +02:00
shell = moduleWithSystem ({ ... }: { pkgs, ... }: {
2024-08-03 15:41:51 +02:00
programs = {
starship.enable = true;
zsh = {
enableBashCompletion = true;
syntaxHighlighting.enable = true;
autosuggestions = {
enable = true;
2024-08-07 18:44:14 +02:00
strategy = [ "completion" ];
2024-08-03 15:41:51 +02:00
};
shellAliases = {
cal = "cal $(date +%Y)";
GG = "git add . && git commit -m 'GG' && git push --set-upstream origin HEAD";
gad = "git add . && git diff --cached";
gac = "ga && gc";
ga = "git add .";
gc = "git commit";
dev = "nix develop --command $SHELL";
eza = "${pkgs.eza}/bin/eza '--long' '--header' '--icons' '--smart-group' '--mounts' '--octal-permissions' '--git'";
ls = "eza";
la = "eza --all";
lt = "eza --git-ignore --all --tree --level=10";
sc = "systemctl";
neofetch = "${pkgs.fastfetch}/bin/fastfetch -c all.jsonc";
};
};
};
});
2024-08-07 18:44:14 +02:00
sound = moduleWithSystem ({ ... }: { pkgs, ... }: {
2024-08-07 17:41:33 +02:00
services = {
pipewire = {
enable = true;
alsa.enable = true;
pulse.enable = true;
};
};
2024-08-07 18:44:14 +02:00
environment.systemPackages = with pkgs; [ pwvucontrol ];
2024-07-04 08:38:33 +02:00
});
2024-08-07 18:44:14 +02:00
music = moduleWithSystem ({ ... }: { pkgs, ... }: {
imports = [ inputs.musnix.nixosModules.musnix ];
environment.systemPackages = with pkgs; [ guitarix ];
2024-07-05 11:53:58 +02:00
services.pipewire = {
jack.enable = true;
2024-08-07 18:44:14 +02:00
extraConfig = { jack."69-low-latency" = { "jack.properties" = { "node.latency" = "64/48000"; }; }; };
2024-07-05 11:52:45 +02:00
};
2024-07-05 00:10:36 +02:00
musnix = {
enable = true;
rtcqs.enable = true;
soundcardPciId = "00:1f.3";
2024-08-07 17:41:33 +02:00
kernel = {
realtime = true;
packages = pkgs.linuxPackages-rt;
};
2024-07-05 00:10:36 +02:00
};
});
2024-08-07 18:44:14 +02:00
wayland = moduleWithSystem ({ ... }: { ... }: {
2024-08-02 22:43:08 +02:00
hardware.graphics.enable = true;
2024-08-07 18:44:14 +02:00
security.pam.services.swaylock = { };
2024-08-02 22:43:08 +02:00
xdg.portal = {
enable = true;
xdgOpenUsePortal = true;
2024-08-07 17:41:33 +02:00
wlr = {
enable = true;
settings = {
screencast = {
output_name = "HDMI-A-1";
max_fps = 60;
};
};
};
2024-08-02 22:43:08 +02:00
config.common.default = "*";
};
});
2024-08-07 18:44:14 +02:00
security = moduleWithSystem ({ ... }: { ... }: {
security = {
2024-08-07 17:41:33 +02:00
sudo = {
enable = false;
execWheelOnly = true;
2024-08-07 18:44:14 +02:00
extraRules = [{ groups = [ "wheel" ]; }];
2024-08-07 17:41:33 +02:00
};
doas = {
enable = true;
extraRules = [
{
2024-08-07 18:44:14 +02:00
groups = [ "wheel" ];
2024-08-07 17:41:33 +02:00
noPass = true;
keepEnv = true;
}
];
};
polkit.enable = true;
rtkit.enable = true;
};
});
2024-08-04 20:07:52 +02:00
intranet = {
2024-07-04 08:38:33 +02:00
networking.wg-quick.interfaces = {
wg0 = {
2024-08-07 18:44:14 +02:00
address = [ "10.0.0.2/32" ];
2024-07-04 08:38:33 +02:00
privateKeyFile = "/etc/wireguard/privatekey";
peers = [
{
publicKey = "5FiTLnzbgcbgQLlyVyYeESEd+2DtwM1JHCGz/32UcEU=";
2024-08-07 18:44:14 +02:00
allowedIPs = [ "0.0.0.0/0" "::/0" ];
2024-07-04 08:38:33 +02:00
endpoint = "37.205.13.29:51820";
persistentKeepalive = 25;
}
];
};
};
2024-08-04 21:24:32 +02:00
services.openssh = {
2024-08-04 20:07:52 +02:00
enable = true;
settings = {
PermitRootLogin = "prohibit-password";
};
};
};
2024-07-04 08:38:33 +02:00
wireless = {
networking = {
wireless = {
enable = true;
networks = {
"Smart-Hostel-2.4" = {
psk = "smarttrans.bg";
};
"Yohohostel2.4G" = {
psk = "kaskamaska";
};
"Nomado_Guest" = {
psk = "welcomehome";
};
"HostelMusala Uni" = {
psk = "mhostelm";
};
"BOUTIQUE APARTMENTS" = {
psk = "boutique26";
};
"Safestay" = {
psk = "AlldayrooftopBAR";
};
"HOSTEL JASMIN 2" = {
psk = "Jasmin2024";
};
"HOME" = {
psk = "iloveprague";
};
"Vodafone-B925" = {
psk = "7aGh3FE6pN4p4cu6";
};
"O2WIFIZ_EXT" = {
psk = "iloveprague";
};
2024-06-23 15:35:19 +02:00
"KOTEKLAN_GUEST" = {
psk = "koteklankotek";
};
2024-07-30 10:01:43 +02:00
"3G" = {
hidden = true;
};
};
};
};
};
2024-08-07 18:44:14 +02:00
ivand = moduleWithSystem ({ ... }: { pkgs, ... }:
let
homeMods = top.config.flake.homeManagerModules;
in
{
imports = [ inputs.home-manager.nixosModules.default ];
home-manager = {
backupFileExtension = "bak";
useUserPackages = true;
useGlobalPkgs = true;
users.ivand = { ... }: {
imports = with homeMods; [
base
ivand
shell
util
swayland
web
2024-08-07 17:41:33 +02:00
];
2024-08-02 20:04:50 +02:00
};
};
2024-08-07 18:44:14 +02:00
fonts.packages = with pkgs; [ (nerdfonts.override { fonts = [ "FiraCode" ]; }) noto-fonts noto-fonts-emoji noto-fonts-lgc-plus ];
users = {
users = {
ivand = {
isNormalUser = true;
createHome = true;
extraGroups = [
"adbusers"
"adm"
"audio"
"bluetooth"
"dialout"
"flatpak"
"kvm"
"mlocate"
"realtime"
"render"
"video"
"wheel"
];
};
};
extraGroups = {
mlocate = { };
realtime = { };
};
2024-08-07 17:41:33 +02:00
};
2024-08-07 18:44:14 +02:00
programs.dconf.enable = true;
});
2024-07-04 08:38:33 +02:00
flatpak = {
2024-08-07 17:41:33 +02:00
xdg = {
portal = {
enable = true;
wlr.enable = true;
config.common.default = "*";
};
};
2024-07-04 08:38:33 +02:00
services.flatpak.enable = true;
};
2024-08-07 18:44:14 +02:00
ai = moduleWithSystem ({ ... }: { ... }: {
services = { ollama.enable = true; };
});
2024-08-07 18:44:14 +02:00
anon = moduleWithSystem ({ ... }: { pkgs, ... }: {
environment.systemPackages = with pkgs; [ tor-browser ];
2024-07-24 10:05:13 +02:00
});
2024-08-07 18:44:14 +02:00
cryptocurrency = moduleWithSystem ({ ... }: { pkgs, ... }: {
environment.systemPackages = with pkgs; [ monero-cli ];
services = { monero.enable = true; };
2024-07-06 22:58:14 +02:00
});
2024-08-07 18:44:14 +02:00
monero-miner = moduleWithSystem ({ ... }: { ... }: {
2024-08-04 15:11:01 +02:00
services = {
xmrig = {
enable = true;
settings = {
autosave = true;
cpu = true;
opencl = false;
cuda = false;
pools = [
{
url = "pool.supportxmr.com:443";
user = "48e9t9xvq4M4HBWomz6whiY624YRCPwgJ7LPXngcc8pUHk6hCuR3k6ENpLGDAhPEHWaju8Z4btxkbENpcwaqWcBvLxyh5cn";
keepalive = true;
tls = true;
}
];
};
};
};
});
2024-08-07 18:44:14 +02:00
vps = moduleWithSystem ({ ... }: { ... }: {
2024-08-03 17:09:52 +02:00
imports = [
inputs.vpsadminos.nixosConfigurations.container
];
});
2024-08-07 18:44:14 +02:00
mailserver = moduleWithSystem ({ ... }: { config
, pkgs
, ...
}: {
2024-08-05 18:12:02 +02:00
imports = [
inputs.simple-nixos-mailserver.nixosModule
];
mailserver = {
enable = true;
localDnsResolver = false;
fqdn = "mail.idimitrov.dev";
2024-08-07 18:44:14 +02:00
domains = [ "idimitrov.dev" "mail.idimitrov.dev" ];
2024-08-05 18:12:02 +02:00
loginAccounts = {
"ivan@idimitrov.dev" = {
hashedPassword = "$2b$05$rTVIQD98ogXeCBKdk/YufulWHqpMCAlb7SHDPlh5y8Xbukoa/uQLm";
2024-08-07 18:44:14 +02:00
aliases = [ "admin@idimitrov.dev" ];
2024-08-05 18:12:02 +02:00
};
"security@idimitrov.dev" = {
hashedPassword = "$2b$05$rTVIQD98ogXeCBKdk/YufulWHqpMCAlb7SHDPlh5y8Xbukoa/uQLm";
};
};
certificateScheme = "acme-nginx";
hierarchySeparator = "/";
};
services = {
2024-08-07 18:44:14 +02:00
dovecot2.sieve.extensions = [ "fileinto" ];
2024-08-05 18:12:02 +02:00
roundcube = {
enable = true;
2024-08-07 18:44:14 +02:00
package = pkgs.roundcube.withPlugins (plugins: [ plugins.persistent_login ]);
2024-08-05 18:12:02 +02:00
plugins = [
"persistent_login"
];
hostName = "${config.mailserver.fqdn}";
extraConfig = ''
$config['smtp_host'] = "tls://${config.mailserver.fqdn}";
$config['smtp_user'] = "%u";
$config['smtp_pass'] = "%p";
'';
};
2024-08-07 18:44:14 +02:00
nginx.virtualHosts =
let
restrictToVpn = ''
allow 10.0.0.2/32;
allow 10.0.0.3/32;
allow 10.0.0.4/32;
deny all;
'';
in
{
"${config.mailserver.fqdn}" = {
extraConfig = restrictToVpn;
};
};
2024-08-05 18:12:02 +02:00
postgresql.enable = true;
};
security = {
acme = {
acceptTerms = true;
defaults.email = "security@idimitrov.dev";
};
};
});
2024-08-07 18:44:14 +02:00
nginx = moduleWithSystem ({ ... }: { pkgs, ... }: {
2024-08-05 18:25:15 +02:00
services = {
2024-08-07 18:44:14 +02:00
nginx =
let
webshiteConfig = ''
add_header 'Referrer-Policy' 'origin-when-cross-origin';
add_header X-Content-Type-Options nosniff;
'';
extensions = [ "html" "txt" "png" "jpg" "jpeg" ];
serveStatic = exts: ''
try_files $uri $uri/ ${pkgs.lib.strings.concatStringsSep " " (builtins.map (x: "$uri." + "${x}") exts)} =404;
'';
in
{
enable = true;
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
sslCiphers = "AES256+EECDH:AES256+EDH:!aNULL";
virtualHosts = {
"idimitrov.dev" = {
enableACME = true;
forceSSL = true;
locations."/" = {
root = "${pkgs.webshite}";
extraConfig = serveStatic extensions;
};
extraConfig = webshiteConfig;
2024-08-05 18:25:15 +02:00
};
2024-08-07 18:44:14 +02:00
"www.idimitrov.dev" = {
enableACME = true;
forceSSL = true;
locations."/" = {
root = "${pkgs.webshite}";
extraConfig = serveStatic extensions;
};
extraConfig = webshiteConfig;
2024-08-05 18:25:15 +02:00
};
2024-08-07 18:44:14 +02:00
"src.idimitrov.dev" = {
enableACME = true;
forceSSL = true;
locations."/" = {
proxyPass = "http://127.0.0.1:3001";
};
2024-08-05 18:25:15 +02:00
};
2024-08-07 18:44:14 +02:00
"pic.idimitrov.dev" = {
enableACME = true;
forceSSL = true;
locations."/" = {
root = "/var/pic";
extraConfig = ''
autoindex on;
${serveStatic ["png"]}
'';
};
2024-08-05 18:25:15 +02:00
};
};
};
gitea = {
enable = true;
appName = "src";
database = {
type = "postgres";
};
settings = {
server = {
DOMAIN = "src.idimitrov.dev";
ROOT_URL = "https://src.idimitrov.dev/";
HTTP_PORT = 3001;
};
repository = {
DEFAULT_BRANCH = "master";
};
service = {
DISABLE_REGISTRATION = true;
};
};
};
postgresql = {
enable = true;
ensureUsers = [
{
name = "root";
ensureClauses = {
superuser = true;
createrole = true;
createdb = true;
};
}
];
};
};
});
2024-08-07 18:44:14 +02:00
wireguard-output = moduleWithSystem ({ ... }: { pkgs, ... }: {
2024-08-05 18:40:34 +02:00
networking = {
nat = {
enable = true;
enableIPv6 = true;
externalInterface = "venet0";
2024-08-07 18:44:14 +02:00
internalInterfaces = [ "wg0" ];
2024-08-05 18:40:34 +02:00
};
wg-quick.interfaces = {
2024-08-07 18:44:14 +02:00
wg0 =
let
iptables = "${pkgs.iptables}/bin/iptables";
ip6tables = "${pkgs.iptables}/bin/ip6tables";
in
{
address = [ "10.0.0.1/32" ];
listenPort = 51820;
privateKeyFile = "/etc/wireguard/privatekey";
postUp = ''
${iptables} -A FORWARD -i wg0 -j ACCEPT
${iptables} -t nat -A POSTROUTING -s 10.0.0.1/24 -o venet0 -j MASQUERADE
${ip6tables} -A FORWARD -i wg0 -j ACCEPT
${ip6tables} -t nat -A POSTROUTING -s fdc9:281f:04d7:9ee9::1/64 -o venet0 -j MASQUERADE
'';
preDown = ''
${iptables} -D FORWARD -i wg0 -j ACCEPT
${iptables} -t nat -D POSTROUTING -s 10.0.0.1/24 -o venet0 -j MASQUERADE
${ip6tables} -D FORWARD -i wg0 -j ACCEPT
${ip6tables} -t nat -D POSTROUTING -s fdc9:281f:04d7:9ee9::1/64 -o venet0 -j MASQUERADE
'';
peers = [
{
publicKey = "kI93V0dVKSqX8hxMJHK5C0c1hEDPQTgPQDU8TKocVgo=";
allowedIPs = [ "10.0.0.2/32" ];
}
{
publicKey = "RqTsFxFCcgYsytcDr+jfEoOA5UNxa1ZzGlpx6iuTpXY=";
allowedIPs = [ "10.0.0.3/32" ];
}
{
publicKey = "1e0mjluqXdLbzv681HlC9B8BfGN8sIXIw3huLyQqwXI=";
allowedIPs = [ "10.0.0.4/32" ];
}
];
};
2024-08-05 18:40:34 +02:00
};
};
});
2024-08-07 18:44:14 +02:00
anonymous-dns = moduleWithSystem ({ ... }: { ... }: {
2024-08-05 18:46:10 +02:00
networking = {
2024-08-07 18:44:14 +02:00
nameservers = [ "127.0.0.1" "::1" ];
2024-08-05 18:46:10 +02:00
dhcpcd.extraConfig = "nohook resolv.conf";
};
services = {
dnscrypt-proxy2 = {
enable = true;
settings = {
cache = false;
ipv4_servers = true;
ipv6_servers = true;
dnscrypt_servers = true;
doh_servers = false;
odoh_servers = false;
require_dnssec = true;
require_nolog = true;
require_nofilter = true;
anonymized_dns = {
2024-08-07 17:41:33 +02:00
routes = [
{
server_name = "*";
2024-08-07 18:44:14 +02:00
via = [ "sdns://gQ8yMTcuMTM4LjIyMC4yNDM" ];
2024-08-07 17:41:33 +02:00
}
];
2024-08-05 18:46:10 +02:00
};
sources.public-resolvers = {
urls = [
"https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v3/public-resolvers.md"
"https://download.dnscrypt.info/resolvers-list/v3/public-resolvers.md"
];
cache_file = "/var/lib/dnscrypt-proxy/public-resolvers.md";
minisign_key = "RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3";
};
};
};
};
});
2024-08-07 18:44:14 +02:00
firewall = moduleWithSystem ({ ... }: { lib, ... }: {
2024-08-05 18:54:30 +02:00
networking = {
firewall = lib.mkForce {
enable = true;
allowedTCPPorts = [
25 # smtp
465 # smtps
80 # http
443 # https
];
allowedUDPPorts = [
25
465
80
443
51820 # wireguard
];
extraCommands = ''
iptables -N vpn # create a new chain named vpn
iptables -A vpn --src 10.0.0.2 -j ACCEPT # allow
iptables -A vpn --src 10.0.0.3 -j ACCEPT # allow
iptables -A vpn --src 10.0.0.4 -j ACCEPT # allow
iptables -A vpn -j DROP # drop everyone else
iptables -I INPUT -m tcp -p tcp --dport 22 -j vpn
'';
extraStopCommands = ''
iptables -F vpn
iptables -D INPUT -m tcp -p tcp --dport 22 -j vpn
iptables -X vpn
'';
};
};
});
2024-08-07 18:44:14 +02:00
rest = moduleWithSystem ({ ... }: { pkgs, ... }: {
2024-08-05 18:57:10 +02:00
fileSystems."/mnt/export1981" = {
device = "172.16.128.47:/nas/5490";
fsType = "nfs";
2024-08-07 18:44:14 +02:00
options = [ "nofail" ];
2024-08-05 18:57:10 +02:00
};
users = {
users.ivand = {
isNormalUser = true;
2024-08-07 17:41:33 +02:00
hashedPassword = "$2b$05$hPrPcewxj4qjLCRQpKBAu.FKvKZdIVlnyn4uYsWE8lc21Jhvc9jWG";
2024-08-07 18:44:14 +02:00
extraGroups = [ "wheel" "adm" "mlocate" ];
2024-08-05 18:57:10 +02:00
openssh.authorizedKeys.keys = [
''
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICcLkzuCoBEg+wq/H+hkrv6pLJ8J5BejaNJVNnymlnlo ivan@idimitrov.dev
''
];
};
2024-08-07 18:44:14 +02:00
extraGroups = { mlocate = { }; };
2024-08-05 18:57:10 +02:00
};
services = {
openssh = {
enable = true;
settings = {
PermitRootLogin = "prohibit-password";
};
};
};
systemd = {
timers = {
bingwp = {
2024-08-07 18:44:14 +02:00
wantedBy = [ "timers.target" ];
2024-08-05 18:57:10 +02:00
timerConfig = {
OnCalendar = "*-*-* 10:00:00";
Persistent = true;
};
};
};
services = {
bingwp = {
description = "Download bing image of the day";
script = ''
${pkgs.nushell}/bin/nu -c "http get ('https://bing.com' + ((http get https://www.bing.com/HPImageArchive.aspx?format=js&n=1).images.0.url)) | save ('/var/pic' | path join ( [ (date now | format date '%Y-%m-%d'), '.png' ] | str join ))"
${pkgs.nushell}/bin/nu -c "${pkgs.toybox}/bin/ln -sf (ls /var/pic | where type == file | get name | sort | last) /var/pic/latest.png"
'';
};
};
};
});
};
}