From fcee389f8eea3e3aa79b51dbd35dd28eeafae7ce Mon Sep 17 00:00:00 2001 From: bogale Date: Sun, 25 Oct 2026 12:57:58 +0900 Subject: [PATCH] nix formating, sops secrets migration, vps-init auto update --- .secrets.yaml | 17 ++- common.nix | 175 +++++++++++---------- desktop/configuration.nix | 165 ++++++++++---------- desktop/hardware.nix | 42 +++-- flake.nix | 80 ++++++---- home/bogale.nix | 85 +++++------ home/common.nix | 34 +++-- home/mods/niri.kdl | 122 ++++++++------- home/mods/noctalia.toml | 89 ----------- home/root.nix | 35 +++-- mods/pxeboot.nix | 213 +++++++++++++++----------- mods/vps-init.nix | 39 +++-- server/configuration.nix | 105 ++++++++----- server/hardware.nix | 36 +++-- server/mods/mail.nix | 182 ++++++++++++---------- server/mods/system.nix | 114 +++++++------- server/mods/web.nix | 311 ++++++++++++++++++++++---------------- 17 files changed, 988 insertions(+), 856 deletions(-) diff --git a/.secrets.yaml b/.secrets.yaml index 218599a..6381f0c 100644 --- a/.secrets.yaml +++ b/.secrets.yaml @@ -1,11 +1,18 @@ -root-passwd: ENC[AES256_GCM,data:taTvrqyI90UsBufUi+tFSNhcJNBo/+Owb9Zy+83PFA8J9I2ukz0TUafDMzxN/bI1whSlOnb/fq/ESi+ewGj5wxrIVimYE6/jJQ==,iv:ze9UccF64S113wLP/6lFunk5KqIAf8d5hISXHkFg5t8=,tag:dzozycgw77PXIyqio58Qkg==,type:str] -bogale-passwd: ENC[AES256_GCM,data:jPm/6XkoN66AWj5xPHGfI/IyKKOiUhP7nY9bVP0gWKLUGDemIannbHMA8RQeN7FQEwDocqPdkawNq5MWu+mb8uECMAyMyE5FSg==,iv:eEzG393tJNFKWI2Qeg9Fc6o7x7KblBBRJj9HDT3R70I=,tag:klbG/O/w0VWR4do+1pzfhQ==,type:str] -wifi-env: ENC[AES256_GCM,data:22s1o+2Dvf6HcDlfUPWVgMldjKl7k8wNicsisoX7p7uIP+BBx4WPpNFINtYO/UllDL22XiJs+4k1+7W+o+baCHFXdTZAi+psF9CeYqdogRUUrUIOokdEuxRFZFTsANDU8ljb88THz5Pn3wuZyhoVVaM=,iv:c3lEYdzh+nW/vATGiv4BRD70rP8qwwI1hZnT8LG6DE0=,tag:gQTZR3c6womkaQCHvb4ozg==,type:str] awg-obf: ENC[AES256_GCM,data:8m0wlQO1pXgnTptYThZoCIqqef/cjjhg5P7iW6hE08Zbm9DadIbi4e2h1owH/O/+T5MKyOfIFONl2r6G/3ctDY1XGkbcwPaLN6z8/SE21k5PrKivMaTdEKGd5J0U0ny5s+sZZSqJxtBnb62czsXZ5ZrZSmvg/IsL72ObmwmcdC57nP9MFC/3/Gaawaz2bEjaaSVikLk22wZw7GRwbUSXsh/m9vBH02EyVhGqYcRcodNIzkdeMowPuhyEeVQmj9o0ODIDOWvMD71h9N5t6xkzApjLQXxdxxQon7YiQVxOCFsKibsfiTVTVl7wvWFqICKveEkXIzVlN6ubP/upspKiC3YtKUIU/ix4m4Lqk/e8HlStjeQWDOhaM/1n3p2M5NHNGf/X5vAvK0DGv+e1CoUd1FN3l0rm4SUGgi/mpQ0sOJb9zuPqv4OB8SmgYdnHNlW7GBFqJVD07s6otgQH+PQz04jL2EMw7JNBtXWk3t7fV15Ps31UqPiHfCLRtbakj/z7A2ljTDDl/PXQkfx7gl3j0an/R/Z/DFol1mLjdbgUhOEHWlNu23DCw4JCKGrLAw==,iv:kvpR3C/rDp++9EjM/9hKb8CAwiR29y5xmXZm4kWtsHU=,tag:iRtXdsdUcCzS7pRYb26uHA==,type:str] awg0-spec: ENC[AES256_GCM,data:Ml+zSgMPymoMM7tTYrzfyjzavZUPjLuI22TCz58UGxRTK0YF7ip6ScBgxKwvF1sRD9qxS1wRWbRE/h8HSE5CbKELYjrCg3aiKRVY8bGv0dxrYQjV/BjljvLy1+8sVnjpD1IFVEOFJmpjkGaFUc8/7Xb0rVAmK6XTa5g+f55kp5n557UalfS29FwOcr8HgW1hZVTYiRZlaW3FxUDGZDjEP3Y1pG2h5MEsAQCTlkUv6dy+VdeUxN6G15v9dNF1CplvFXsi+sVqxmcPOANiKqaWmB5OYaE6C6RMuuPNJsbV6zecYOm2thQJALgHbX/Wq3Nqegxt+0CVHm7devnOsZhE2aSjsGTmI+KBDtUedY78qkSvHQhzhWfNAkptj9JUyJmXhBvT5yz56KHTCqDIKj/l8Hu+ZWbsXc3bH3r9nRXrJseTrGed9Y3sI+YgcNnEcTPWBU4xsveOTVHP2Y8KtZ9fM6iGJns/qxzmNbS6xKX8T2028feMu15CHdF2X3UVxDlIjla2MB7KX+BG+masyzxcTs4ThG1U6eWA/MsUVt/PXVpyMBrKLmuSsWWD90j17/X0ZVCJFRl0h8+vTq4pPWp8sclCiXtu0rxNlM9VL45VeUxvkWYebcR9aHdk2EaJnR2Qm5Jr3KKf8+Mf6WLvX6/PlRbKnSx24UZppC9gQiNVEoCsHfVkgKL5mG3gnGLARCZ6Y2imj0fJr692HV7RYCgzqVkPizSVBJqvTusCgWhlmTwVKXag6KJFVz2q9f6QRDM0Rb/ImC066XT+8wVzC3RJzEruxTW15aR8TdrlQytTtpmiK4z+WwI9UmLhrzsrSwPvWMdR,iv:WoJpKHNjTIuQWIgdKkgvqCmC+1DE5UsgqrvJ3M9wqj4=,tag:quE06vOF5tvlrnGbxaBVPQ==,type:str] awg1-spec: ENC[AES256_GCM,data:qAKqA3ng760utSYHJGda0q9nwiWXpubGXGhMah9d6RMI8o67JAadyLVhSPGARibfsxmINiltrHVQU3KO6cFYkbPcGuKO0/YQq5MOukVp/8LnFHFN4tKUJpHZdt4JOEHJE9js1u7pJdg5jE+orIKl60iPccm9xunl/XYI7IdAjMGuVk9yMHvjOsQK9xK8w4qgMrWCj7XhZ9CmKk4yAwmN6Qivwv5AEwjyqRMWRvWRLxKyzjvoitsGo/EW+c54/t6MByH+ypXn7/jnZykc9usptyqhsOdNfYkoOgU9EHPzZ9uCnX2yinJBq5OTIvuuy5CX7svpRQ6LY+d0ha2b+IcPGAjsjtd9PmHv0miW/Hb0wMNNFy8xG7uN9mmdwmJnNVAJ2d0LI4tfFvLJIOzZF+ZVkf8=,iv:FapQlYAbfmkNgXCjIO18rjtS4dEFpGsjeoKwTannu2k=,tag:ZyquPLykqROF3HVEKbNr3w==,type:str] awg2-spec: ENC[AES256_GCM,data:lKf1YU5LDL4Kgl4cTy9ZdBPFz/WbfTvUdf9D4KejTsqnRMnxLieIgS3HWwEK4oGup5aKZgx2PL0T/bCFkRnxujJEOIdNqBa7a8esvsmzkVInEMMq7Z4Ofnnlz3S+y7o/WPFil2Oik+uE3HhS77uSOWrrq7bW2RMQcKUzlIEYbtUsFFcMkdEoh2sUqXSqUxX1L/lg8VtCIhsulEE8GjGJ8p/dzURZ9LHWPah95hW7bFU5j4rPF6NRGv4OMf7sHX+g5mc4tiTWV9H5NKoTtuxFVhVw3mQzxteIRMZPdvgKFnSIuVlb7JrWAL0sd3DPln7le8D3JRdTgZScQc24G9oCpH+IYaUbqKJ633MWzm/oZQDMqALwMKZbXP/uoDe2SBUl37C55B3r4oJsWT9FpQH8YEI=,iv:nvkJ1CzRKyluqxMTLtPkXBpUGhDeCzDdXl/aXNOP9BU=,tag:aC51Eo5mZ0zA7KdlJS6niQ==,type:str] awg3-spec: ENC[AES256_GCM,data:2F+edwAugIjiPbPbanXl8GsfDcijHxg0N4jIExgcbn0AaAJpx78bJq7dwk4ahuVZX6HcYH+07d7ZYOf+m5080YDEf9gnFnL+DJNmMbWXISixe9zFv/t/FhdceHHf1xKWp4dFFhCjMv18xMIEVVEzIyLwNwL4UpF+p3Kks6RdysclAS0FFX/gFTNH5io5xTp7UprtIKvSYz4oPl1NSp8qYMWuHV7J8KN5Jh1zPfx7OGk7UemyYwNQbasfsxpoYC6Zb8a8W+1684xRqioEZLSL4IhGcz0GsjpP+Yt+KOjZoqcWfro5OdjR+Yz4uxFANi/FN3xerIwS4Keqlk164YA/n42O0nY0sebQ88daIwpEYkW6HsqnUd7Q6WmeCu66DunAcKERp+gxqf13fFHvf35QfeQ=,iv:Pj+Klu+N9UJAEffVRU+otBN2kJTpTEYXSmAlXH22NNM=,tag:FLvtFwm4bo2HumU8/q1Ckw==,type:str] +bogale-passwd: ENC[AES256_GCM,data:jPm/6XkoN66AWj5xPHGfI/IyKKOiUhP7nY9bVP0gWKLUGDemIannbHMA8RQeN7FQEwDocqPdkawNq5MWu+mb8uECMAyMyE5FSg==,iv:eEzG393tJNFKWI2Qeg9Fc6o7x7KblBBRJj9HDT3R70I=,tag:klbG/O/w0VWR4do+1pzfhQ==,type:str] +cf-token: ENC[AES256_GCM,data:AZoJXvWKZJ/BsiUzWcThh0wpIuQOM5eedt5bQh7gVdTIsjzqX3rDYjZx6qD3rh0TrNzStHs=,iv:CgocnA9+RqC3ZyQbBtw+QMNk/CXkVO+k0/OhM9OkSVA=,tag:ag+mwaidSloklqNHwwBchw==,type:str] +dovecot-pw: ENC[AES256_GCM,data:KzSipWmrm4zHq/aj6lfPSkyk20EB2Qqfn8nKLks4x/OsHz0KxJukGgM3K7ZVFIn2yXoUvw30KdmXwJC0pkFpr4G9wprQFjgL7FwYVPi+RQpd9ZAIjT4x56IxTkIIreU95mNkuVTid5fdpN5hBDH2XwUrMlUAhpTR6twtOd8=,iv:Y56qjTrGIfk8/kF4BqtodrN/gQ2f3y68M6fpJA1ZhX4=,tag:EYPyhwlFIX6SdD2azox20Q==,type:str] +grafana-key: ENC[AES256_GCM,data:fN1Uysxlw79XB4LpW2V0WUTqVxRaWbC9KMurszwHI/gHY4CUgCYTOXxQHjJ31FNfXQXt5HIi6VqQnK0PKpwlcw==,iv:ah5/weyVPeK0jj/nmOp2XChPIYBaPi4m6q22bUt4J/8=,tag:RQNkwUiJQ3x5sDFRrKnzzA==,type:str] +nextcloud-pw: ENC[AES256_GCM,data:9eygcJ43j90OUdxXynD5UlwCl9w=,iv:XIb/fg4zHu6s3MpR+YgCc6Myy99WVniIBxYjyTuD3fo=,tag:pUVcu7bow2loR0IQWxm7Tw==,type:str] +root-passwd: ENC[AES256_GCM,data:taTvrqyI90UsBufUi+tFSNhcJNBo/+Owb9Zy+83PFA8J9I2ukz0TUafDMzxN/bI1whSlOnb/fq/ESi+ewGj5wxrIVimYE6/jJQ==,iv:ze9UccF64S113wLP/6lFunk5KqIAf8d5hISXHkFg5t8=,tag:dzozycgw77PXIyqio58Qkg==,type:str] +smtp-sasl: ENC[AES256_GCM,data:SmAYdhcMNFqLqGgLOCcvAT+V6K5Mzd45aoAczPtHk3G9THDCJttI/hxYLTa8xw32opzPPackboSB71kytRNnhA==,iv:dGwsbKsKT0TnUSw7KJX9AIvpEr9qoGdBFi9QHNV9kS0=,tag:LTfVAjQ3TF//jUvq9E6Bog==,type:str] +tgbot-env: ENC[AES256_GCM,data:B/MNagCs/j7rQKMqSobQMbV5fcEWoJ+8Xpecv00L69Z7vFRMa7TlBCCztCFGAS0ahO27BPDW/FZfcgfFui6oGR5fgqCb/oGQXLPvk/0vEAliCyneeVSgTZZu1ODJUOGXF5msBdmLDbWO/3Rw3fZWsxf2+GizFKLacT9FnSXqm0E+CM5fcZRpn8Ofv5c+fCDGtlhBGilotGgYGkmAMZEQEnj/b3HzJw==,iv:hpVo3+wiqDWxAVWcGB1jUKcuwUg8KyjIZ5u7CQKrm3g=,tag:pHpvNI3H/rGYqy5G8a1PKA==,type:str] +vaultwarden-env: ENC[AES256_GCM,data:d9C9Nm+dQUOlK3Un5sw3nSY0gRLfXRDL0/rBNQ4EMze5FV+3kDN6O2C1TN0+cO1a3nCxKlrhIPqqFvSI/PoSp+axrVle//aWxZd/aON0x/y7LkSrupd+lpzMqDtG9lHZH+dDoMCOfuEgANBWur6Mw3xZsC8YjLnb8iGw8xDcxEUrJ88t,iv:XGz7G42xYR5TxlOrKYJK7nOAZZacQcLEPzkSktg3Gag=,tag:DofrMeGGf+xELSpN+YEguw==,type:str] +wifi-env: ENC[AES256_GCM,data:22s1o+2Dvf6HcDlfUPWVgMldjKl7k8wNicsisoX7p7uIP+BBx4WPpNFINtYO/UllDL22XiJs+4k1+7W+o+baCHFXdTZAi+psF9CeYqdogRUUrUIOokdEuxRFZFTsANDU8ljb88THz5Pn3wuZyhoVVaM=,iv:c3lEYdzh+nW/vATGiv4BRD70rP8qwwI1hZnT8LG6DE0=,tag:gQTZR3c6womkaQCHvb4ozg==,type:str] sops: age: - enc: | @@ -17,7 +24,7 @@ sops: xofUgJG+4M8o0libyI7KjGrOiQNqIe6/WVbR+KcbNwxPtOA1+mfYyQ== -----END AGE ENCRYPTED FILE----- recipient: age1gqcjvqqaf6mh2p4uhtx2cym69xhu3n3tr82dzzqp8qrmh6nsaurqed3zqy - lastmodified: "2026-10-24T07:56:22Z" - mac: ENC[AES256_GCM,data:/p2O0wvj9FsRMfE5P3XO7eagkGOc9t2P10mCL+frlvDqiTql4DQIhP1TslSNCroiwkvvkCQsfeXTOHaibJXZUIM0BAx8/C/3cGH9qaWlSWjXS0H3ItiiJ3q/NHSJol5YnQP/Z7GTyD2WGBgNrffA3eL4pqP1zJ84wTbzyOzcPVo=,iv:khmzu/WXlek6I9pLj1+j5f/gzHIcGZCIqct7IvmNdXs=,tag:WtitTkufK5nyPhRN98Tj/A==,type:str] + lastmodified: "2026-10-25T03:43:35Z" + mac: ENC[AES256_GCM,data:AMHkVxOjMUb5hUC36XPwItPtygxvko6QaQJkQJ8xrdaExWogeeJR3AUeXqidEz6CPQeMhd/iOd6H7UrRija14Oxy3nIj6sY4CLoCkXfwYneC1gXJT+ruErgjgOCinOuYhof/ROtwuTYnMfX8bwyDstn24vnOyhnGPwySi+LKLSs=,iv:Zld3CIQtvzdi4Ta+rp4Q+cnvae8AQPWZk+JxP372pOM=,tag:j2sMObA0bUAsfDwWv/h96Q==,type:str] unencrypted_suffix: _unencrypted version: 3.13.3 diff --git a/common.nix b/common.nix index a0fc831..98b51f0 100644 --- a/common.nix +++ b/common.nix @@ -1,102 +1,123 @@ -{ config, lib, pkgs, ... }: -{ - time.timeZone = "Asia/Chita"; - system.stateVersion = "26.11"; - i18n.defaultLocale = "ru_RU.UTF-8"; - swapDevices = [ { device = "/var/swapfile"; } ]; - imports = [ ./mods/pxeboot.nix ./mods/vps-init.nix ]; - nix.settings.experimental-features = [ "nix-command" "flakes" ]; - users.users.root.hashedPasswordFile = sops.secrets.root-passwd.path; +{ config, pkgs, ... }: { + boot = { + extraModulePackages = [ config.boot.kernelPackages.amneziawg ]; + kernelModules = [ "amneziawg" ]; + kernelPackages = pkgs.linuxPackages_latest; + loader.limine = { + enable = true; + panicOnChecksumMismatch = true; + secureBoot.enable = true; + }; + zswap = { + enable = true; + maxPoolPercent = 15; + }; + }; console = { - font = "cyr-sun16"; + font = "${pkgs.kbd}/share/consolefonts/cyr-sun16.psfu.gz"; keyMap = "ruwin_alt_sh-UTF-8"; }; + environment.systemPackages = with pkgs; [ + _7zz + binutils + file + jq + openssl + python314 + qrencode + sbctl + sops + speedtest-go + ]; fileSystems = { "/".options = [ "noatime" ]; "/boot".options = [ "noatime" ]; }; - systemd.tmpfiles.rules = [ - "d /root/backup" - "d /root/backup/base" - "L /root/backup/base/root - - - - /root" - "L /root/backup/base/nixos - - - - /etc/nixos" - "L /root/backup/base/sbctl - - - - /var/lib/sbctl" + i18n.defaultLocale = "ru_RU.UTF-8"; + imports = [ + ./mods/pxeboot.nix + ./mods/vps-init.nix ]; - boot = { - kernelModules = [ "amneziawg" ]; - kernelPackages = pkgs.linuxPackages_latest; - extraModulePackages = [ config.boot.kernelPackages.amneziawg ]; - loader.limine = { - enable = true; - secureBoot.enable = true; - panicOnChecksumMismatch = true; - }; - }; - services.dnsmasq = { - enable = true; - settings = { - enable-ra = true; - no-resolv = true; - bogus-priv = true; - cache-size = 4096; - domain-needed = true; - server = [ "1.1.1.2" "1.0.0.2" "2606:4700:4700::1112" "2606:4700:4700::1002" ]; - }; - }; - environment.systemPackages = with pkgs; [ - jq - _7zz - file - sops - sbctl - openssl - binutils - qrencode - python314 - speedtest-go - ]; - sops = { - defaultSopsFile = ./.secrets.yaml; - secrets = { - awg-obf = {}; - wifi-env = {}; - root-passwd = {}; - }; - age = { - generateKey = true; - sshKeyPaths = [ "/root/.ssh/sops" ]; - keyFile = "/var/lib/sops-nix/key.txt"; - }; - }; networking = { - wg-quick.interfaces.awg0 = { - type = "amneziawg"; - peers = [ { - endpoint = "bogaledev.ru"; - allowedIPs = [ "::/0" "0.0.0.0/0" ]; - } ]; - }; networkmanager = { - enable = true; dns = "dnsmasq"; + enable = true; ensureProfiles = { environmentFiles = [ config.sops.secrets.wifi-env.path ]; profiles.home-wifi = { - wifi-security.key-mgmt = "sae"; connection = { - type = "wifi"; id = "home-wifi"; - }; - ipv6 = { - method = "manual"; - gateway = "fc01::1"; + type = "wifi"; }; ipv4 = { - method = "manual"; gateway = "10.1.0.1"; + method = "manual"; }; + ipv6 = { + gateway = "fc01::1"; + method = "manual"; + }; + wifi-security.key-mgmt = "sae"; }; }; }; + wg-quick.interfaces.awg0 = { + peers = [ + { + allowedIPs = [ + "::/0" + "0.0.0.0/0" + ]; + endpoint = "bogaledev.ru"; + } + ]; + type = "amneziawg"; + }; }; + nix.settings.experimental-features = [ + "flakes" + "nix-command" + ]; + services = { + dnsmasq = { + enable = true; + settings = { + bogus-priv = true; + cache-size = 4096; + domain-needed = true; + enable-ra = true; + no-resolv = true; + server = [ + "1.0.0.2" + "1.1.1.2" + "2606:4700:4700::1002" + "2606:4700:4700::1112" + ]; + }; + }; + swapspace.enable = true; + }; + sops = { + age = { + generateKey = true; + keyFile = "/var/lib/sops-nix/key.txt"; + sshKeyPaths = [ "/root/.ssh/sops" ]; + }; + defaultSopsFile = ./.secrets.yaml; + secrets = { + awg-obf = { }; + root-passwd = { }; + wifi-env = { }; + }; + }; + system.stateVersion = "26.11"; + systemd.tmpfiles.rules = [ + "L /root/backup/base/nixos - - - - /etc/nixos" + "L /root/backup/base/root - - - - /root" + "L /root/backup/base/sbctl - - - - /var/lib/sbctl" + "d /root/backup" + "d /root/backup/base" + ]; + time.timeZone = "Asia/Chita"; + users.users.root.hashedPasswordFile = config.sops.secrets.root-passwd.path; } diff --git a/desktop/configuration.nix b/desktop/configuration.nix index 6a6ddf6..87f8dd0 100644 --- a/desktop/configuration.nix +++ b/desktop/configuration.nix @@ -1,34 +1,106 @@ -{ config, lib, pkgs, ... }: -{ - imports = [ ../common.nix ./hardware.nix ]; +{ config, pkgs, ... }: { boot.kernelParams = [ "hibernate.compressor=lz4" ]; - environment.systemPackages = with pkgs; [ qemu binwalk android-tools ]; - programs = { - niri.enable = true; - virt-manager.enable = true; - }; + environment.systemPackages = with pkgs; [ + android-tools + binwalk + qemu + ]; hardware = { bluetooth.enable = true; graphics.enable32Bit = true; }; - users.users.bogale = { - uid = 1551; - isNormalUser = true; - extraGroups = [ "wheel" "libvirtd" "networkmanager" ]; - users.users.root.hashedPasswordFile = sops.secrets.bogale-passwd.path; + imports = [ + ../common.nix + ./hardware.nix + ]; + networking = { + firewall.allowedTCPPorts = [ 8000 ]; + hostName = "nixos-desktop"; + networkmanager.ensureProfiles.profiles = { + dhcp-eth.connection = { + id = "dhcp-eth"; + type = "ethernet"; + }; + home-wifi = { + ipv4.addresses = "10.1.0.3/16"; + ipv6.addresses = "fc01::3/64"; + wifi-security.psk = "$BOGALE_5_PSK"; + wifi.ssid = "bogale_5"; + }; + phone-wifi = { + connection = { + id = "phone-wifi"; + type = "wifi"; + }; + wifi-security = { + key-mgmt = "sae"; + psk = "$HELLO_WORLD_PSK"; + }; + wifi.ssid = "Hello world"; + }; + }; + wg-quick.interfaces.awg0 = { + address = [ + "10.0.0.3/32" + "fc00::3/128" + ]; + configFile = config.sops.templates.awg2-conf.path; + }; + }; + programs = { + niri.enable = true; + virt-manager.enable = true; + }; + services = { + displayManager.noctalia-greeter = { + cursorTheme = { + name = "Bibata-Modern-Amber"; + package = pkgs.bibata-cursors; + }; + enable = true; + passwordlessSyncUsers = [ "bogale" ]; + settings.cursor.size = 24; + }; + greetd = { + enable = true; + settings.default_session = { + command = "${pkgs.noctalia-greeter}/bin/noctalia-greeter-session"; + user = "greeter"; + }; + }; + pipewire = { + enable = true; + pulse.enable = true; + }; + tuned.enable = true; + upower = { + allowRiskyCriticalPowerAction = true; + criticalPowerAction = "Suspend"; + enable = true; + percentageCritical = 10; + }; }; sops = { secrets = { - awg2-spec = {}; - bogale-passwd = {}; + awg2-spec = { }; + bogale-passwd = { }; }; templates.awg2-conf.content = '' ${config.sops.placeholder.awg-obf} ${config.sops.placeholder.awg2-spec} ''; }; + users.users.bogale = { + extraGroups = [ + "libvirtd" + "networkmanager" + "wheel" + ]; + hashedPasswordFile = config.sops.secrets.bogale-passwd.path; + isNormalUser = true; + uid = 1551; + }; virtualisation = { - spiceUSBRedirection.enable = true; libvirtd = { enable = true; qemu = { @@ -36,65 +108,6 @@ vhostUserPackages = [ pkgs.virtiofsd ]; }; }; - }; - networking = { - hostName = "nixos-desktop"; - firewall.allowedTCPPorts = [ 8000 ]; - wg-quick.interfaces.awg0 = { - address = [ "10.0.0.3/32" "fc00::3/128" ]; - configFile = config.sops.templates.awg2-conf.path; - }; - networkmanager.ensureProfiles.profiles = { - dhcp-eth.connection = { - id = "dhcp-eth"; - type = "ethernet"; - }; - home-wifi = { - wifi.ssid = "bogale_5"; - ipv6.addresses = "fc01::3/64"; - ipv4.addresses = "10.1.0.3/16"; - wifi-security.psk = "$BOGALE_5_PSK"; - }; - phone-wifi = { - wifi.ssid = "Hello world"; - connection = { - type = "wifi"; - id = "phone-wifi"; - }; - wifi-security = { - key-mgmt = "sae"; - psk = "$HELLO_WORLD_PSK"; - }; - }; - }; - }; - services = { - tuned.enable = true; - pipewire = { - enable = true; - pulse.enable = true; - }; - upower = { - enable = true; - percentageCritical = 10; - criticalPowerAction = "Suspend"; - allowRiskyCriticalPowerAction = true; - }; - greetd = { - enable = true; - settings.default_session = { - user = "greeter"; - command = "${pkgs.noctalia-greeter}/bin/noctalia-greeter-session"; - }; - }; - displayManager.noctalia-greeter = { - enable = true; - settings.cursor.size = 24; - passwordlessSyncUsers = [ "bogale" ]; - cursorTheme = { - name = "Bibata-Modern-Amber"; - package = pkgs.bibata-cursors; - }; - }; + spiceUSBRedirection.enable = true; }; } diff --git a/desktop/hardware.nix b/desktop/hardware.nix index 9111d1a..f7c90ec 100644 --- a/desktop/hardware.nix +++ b/desktop/hardware.nix @@ -1,25 +1,45 @@ -{ config, lib, pkgs, modulesPath, ... }: { - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; - hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + config, + lib, + modulesPath, + ... +}: +{ boot = { + initrd = { + availableKernelModules = [ + "nvme" + "rtsx_usb_sdmmc" + "sd_mod" + "usb_storage" + "xhci_pci" + ]; + luks.devices.root.device = "/dev/disk/by-uuid/70ac6613-2e6c-4817-a0ce-43a97efb8bab"; + }; kernelModules = [ "kvm-amd" ]; kernelParams = [ "ttm.pages_limit=3014656" ]; - initrd = { - luks.devices.root.device = "/dev/disk/by-uuid/70ac6613-2e6c-4817-a0ce-43a97efb8bab"; - availableKernelModules = [ "nvme" "xhci_pci" "usb_storage" "sd_mod" "rtsx_usb_sdmmc" ]; - }; }; fileSystems = { "/" = { - fsType = "ext4"; device = "/dev/mapper/root"; + fsType = "ext4"; }; "/boot" = { - fsType = "vfat"; device = "/dev/disk/by-uuid/2610-A769"; - options = [ "fmask=0077" "dmask=0077" ]; + fsType = "vfat"; + options = [ + "dmask=0077" + "fmask=0077" + ]; }; }; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + swapDevices = [ + { + device = "/var/lib/swapfile"; + size = 15 * 1024; + } + ]; } diff --git a/flake.nix b/flake.nix index 75c79f9..b13ae59 100644 --- a/flake.nix +++ b/flake.nix @@ -1,38 +1,60 @@ { inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - sops-nix = { - url = "github:Mic92/sops-nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; home-manager = { inputs.nixpkgs.follows = "nixpkgs"; url = "github:nix-community/home-manager"; }; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + sops-nix = { + inputs.nixpkgs.follows = "nixpkgs"; + url = "github:Mic92/sops-nix"; + }; }; - outputs = inputs@{ self, nixpkgs, sops-nix, home-manager, ... }: { nixosConfigurations = { - nixos-server = nixpkgs.lib.nixosSystem { modules = [ - ./server/configuration.nix - sops-nix.nixosModules.sops - home-manager.nixosModules.home-manager { home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - extraSpecialArgs = { inherit inputs; }; - users.root = ./home/root.nix; - }; } - ]; }; - nixos-desktop = nixpkgs.lib.nixosSystem { modules = [ - ./desktop/configuration.nix - sops-nix.nixosModules.sops - home-manager.nixosModules.home-manager { home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - extraSpecialArgs = { inherit inputs; }; - users = { - root = ./home/root.nix; - bogale = ./home/bogale.nix; + outputs = + inputs@{ + home-manager, + nixpkgs, + sops-nix, + ... + }: + { + formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-tree; + nixosConfigurations = { + nixos-desktop = nixpkgs.lib.nixosSystem { + modules = [ + ./desktop/configuration.nix + home-manager.nixosModules.home-manager + { + home-manager = { + extraSpecialArgs = { inherit inputs; }; + sharedModules = [ inputs.sops-nix.homeManagerModules.sops ]; + useGlobalPkgs = true; + useUserPackages = true; + users = { + bogale = ./home/bogale.nix; + root = ./home/root.nix; + }; + }; + } + sops-nix.nixosModules.sops + ]; }; - }; } - ]; }; - }; }; + nixos-server = nixpkgs.lib.nixosSystem { + modules = [ + ./server/configuration.nix + home-manager.nixosModules.home-manager + { + home-manager = { + extraSpecialArgs = { inherit inputs; }; + sharedModules = [ inputs.sops-nix.homeManagerModules.sops ]; + useGlobalPkgs = true; + useUserPackages = true; + users.root = ./home/root.nix; + }; + } + sops-nix.nixosModules.sops + ]; + }; + }; + }; } diff --git a/home/bogale.nix b/home/bogale.nix index 12717e6..95e97c2 100644 --- a/home/bogale.nix +++ b/home/bogale.nix @@ -1,67 +1,66 @@ -{ config, pkgs, ... }: -{ - imports = [ ./common.nix ]; - wayland.windowManager.niri.enable = true; - xdg.configFile."niri/config.kdl".source = ./mods/niri.kdl; - systemd.user.sessionVariables.QT_QPA_PLATFORMTHEME = "gtk3"; +{ config, pkgs, ... }: { gtk = { - enable = true; colorScheme = "dark"; + enable = true; }; - programs = { - noctalia = { + home = { + homeDirectory = "/home/bogale"; + packages = with pkgs; [ + alacritty + bibata-cursors + bluez + brave-origin + ffmpeg-headless + heroic + libqalculate + libreoffice + llama-cpp-vulkan + mpv + nvtopPackages.full + qbittorrent + telegram-desktop + thunderbird + ]; + pointerCursor = { enable = true; - systemd.enable = true; - settings = ./mods/noctalia.toml; + gtk.enable = true; + name = "Bibata-Modern-Amber"; + package = pkgs.bibata-cursors; + size = 24; + x11.enable = true; }; + username = "bogale"; + }; + imports = [ ./common.nix ]; + programs = { bash = { - sessionVariables.TTS_MODEL = "ggml-org/Qwen3-TTS-12Hz-1.7B-Base-GGUF"; initExtra = '' session() { sudo machinectl shell root@ } ''; + sessionVariables.TTS_MODEL = "ggml-org/Qwen3-TTS-12Hz-1.7B-Base-GGUF"; + }; + noctalia = { + enable = true; + settings = ./mods/noctalia.toml; + systemd.enable = true; }; }; services.gammastep = { enable = true; latitude = 52.0; longitude = 113.5; - temperature = { - day = 6000; - night = 3000; - }; settings.general = { brightness-day = 0.9; brightness-night = 0.6; }; - }; - home = { - username = "bogale"; - homeDirectory = "/home/bogale"; - pointerCursor = { - size = 24; - enable = true; - gtk.enable = true; - x11.enable = true; - name = "Bibata-Modern-Amber"; - package = pkgs.bibata-cursors; + temperature = { + day = 6000; + night = 3000; }; - packages = with pkgs; [ - mpv - bluez - heroic - alacritty - libreoffice - qbittorrent - thunderbird - brave-origin - libqalculate - bibata-cursors - ffmpeg-headless - llama-cpp-vulkan - telegram-desktop - nvtopPackages.amd - ]; }; + systemd.user.sessionVariables.QT_QPA_PLATFORMTHEME = "gtk3"; + wayland.windowManager.niri.enable = true; + xdg.configFile."niri/config.kdl".source = ./mods/niri.kdl; } diff --git a/home/common.nix b/home/common.nix index f11dfe2..5d97a78 100644 --- a/home/common.nix +++ b/home/common.nix @@ -1,43 +1,45 @@ -{ config, pkgs, ... }: -{ - services.ssh-agent.enable = true; +{ config, pkgs, ... }: { home = { + packages = [ + pkgs.ncdu + pkgs.yt-dlp + ]; stateVersion = "26.11"; - packages = with pkgs; [ ncdu yt-dlp ]; }; programs = { - ssh = { - enable = true; - enableDefaultConfig = false; - settings."*".SetEnv.TERM = "xterm-256color"; - }; bash = { enable = true; - shellAliases.la = "ls -lAtr"; historyControl = [ "ignoreboth" ]; sessionVariables.PROMPT_COMMAND = "history -a"; + shellAliases.la = "ls -lAtr"; }; git = { enable = true; settings = { init.defaultbranch = "main"; user = { - name = "bogale"; email = "git@bogaledev.ru"; + name = "bogale"; }; }; }; neovim = { - enable = true; defaultEditor = true; + enable = true; extraConfig = '' - set number + autocmd FileType nix set shiftwidth=2 tabstop=2 set expandtab - set tabstop=4 - set shiftwidth=4 + set number set relativenumber - autocmd FileType nix set tabstop=2 shiftwidth=2 + set shiftwidth=4 + set tabstop=4 ''; }; + ssh = { + enable = true; + enableDefaultConfig = false; + settings."*".SetEnv.TERM = "xterm-256color"; + }; }; + services.ssh-agent.enable = true; } diff --git a/home/mods/niri.kdl b/home/mods/niri.kdl index 69c1470..f019a95 100644 --- a/home/mods/niri.kdl +++ b/home/mods/niri.kdl @@ -1,54 +1,6 @@ -include "./noctalia.kdl"; -gestures { hot-corners { off; }; }; -hotkey-overlay { skip-at-startup; }; -screenshot-path "~/Multimedia/Screenshots/%Y-%m-%d_%H-%M-%S.png"; -window-rule { - match app-id="mpv"; - open-fullscreen true; -}; -cursor { - xcursor-size 24; - xcursor-theme "Bibata-Modern-Amber"; -}; -layout { - center-focused-column "always"; - default-column-width { proportion 0.8; }; -}; -window-rule { - open-floating false; - clip-to-geometry true; - geometry-corner-radius 8; -}; -input { - touchpad { - dwt; - tap; - natural-scroll; - }; - keyboard { - numlock; - xkb { - layout "us,ru"; - options "grp:alt_shift_toggle"; - }; - }; -}; binds { - Mod+T { spawn "alacritty"; }; - Mod+D { spawn-sh "noctalia msg panel-toggle launcher"; }; - Mod+E { spawn-sh "noctalia msg panel-toggle session"; }; - Mod+S { spawn-sh "noctalia msg panel-toggle control-center"; }; - Mod+Shift+S { spawn-sh "noctalia msg settings-open"; }; - - Mod+H { focus-column-left; }; - Mod+J { focus-window-or-workspace-down; }; - Mod+K { focus-window-or-workspace-up; }; - Mod+L { focus-column-right; }; - Mod+Shift+H { move-column-left; }; - Mod+Shift+J { move-window-down-or-to-workspace-down; }; - Mod+Shift+K { move-window-up-or-to-workspace-up; }; - Mod+Shift+L { move-column-right; }; - + Alt+Print { screenshot-window; }; + Ctrl+Print { screenshot-screen; }; Mod+Ctrl+H { focus-monitor-left; }; Mod+Ctrl+J { focus-monitor-down; }; Mod+Ctrl+K { focus-monitor-up; }; @@ -57,22 +9,66 @@ binds { Mod+Ctrl+Shift+J { move-column-to-monitor-down; }; Mod+Ctrl+Shift+K { move-column-to-monitor-up; }; Mod+Ctrl+Shift+L { move-column-to-monitor-right; }; - - XF86MonBrightnessUp { spawn-sh "noctalia msg brightness-up"; }; - XF86MonBrightnessDown { spawn-sh "noctalia msg brightness-down"; }; - XF86AudioRaiseVolume { spawn-sh "noctalia msg volume-up"; }; - XF86AudioLowerVolume { spawn-sh "noctalia msg volume-down"; }; - XF86AudioMute { spawn-sh "noctalia msg volume-mute"; }; - Shift+XF86AudioRaiseVolume { spawn-sh "noctalia msg mic-volume-up"; }; - Shift+XF86AudioLowerVolume { spawn-sh "noctalia msg mic-volume-down"; }; - Shift+XF86AudioMute { spawn-sh "noctalia msg mic-mute"; }; - + Mod+D { spawn-sh "noctalia msg panel-toggle launcher"; }; + Mod+E { spawn-sh "noctalia msg panel-toggle session"; }; + Mod+F { maximize-column; }; + Mod+H { focus-column-left; }; + Mod+J { focus-window-or-workspace-down; }; + Mod+K { focus-window-or-workspace-up; }; + Mod+L { focus-column-right; }; Mod+O { toggle-overview; }; Mod+Q { close-window; }; - Mod+F { maximize-column; }; + Mod+S { spawn-sh "noctalia msg panel-toggle control-center"; }; Mod+Shift+F { fullscreen-window; }; + Mod+Shift+H { move-column-left; }; + Mod+Shift+J { move-window-down-or-to-workspace-down; }; + Mod+Shift+K { move-window-up-or-to-workspace-up; }; + Mod+Shift+L { move-column-right; }; Mod+Shift+P { power-off-monitors; }; + Mod+Shift+S { spawn-sh "noctalia msg settings-open"; }; + Mod+T { spawn "alacritty"; }; Print { screenshot; }; - Alt+Print { screenshot-window; }; - Ctrl+Print { screenshot-screen; }; + Shift+XF86AudioLowerVolume { spawn-sh "noctalia msg mic-volume-down"; }; + Shift+XF86AudioMute { spawn-sh "noctalia msg mic-mute"; }; + Shift+XF86AudioRaiseVolume { spawn-sh "noctalia msg mic-volume-up"; }; + XF86AudioLowerVolume { spawn-sh "noctalia msg volume-down"; }; + XF86AudioMute { spawn-sh "noctalia msg volume-mute"; }; + XF86AudioRaiseVolume { spawn-sh "noctalia msg volume-up"; }; + XF86MonBrightnessDown { spawn-sh "noctalia msg brightness-down"; }; + XF86MonBrightnessUp { spawn-sh "noctalia msg brightness-up"; }; +}; +cursor { + xcursor-size 24; + xcursor-theme "Bibata-Modern-Amber"; +}; +gestures { hot-corners { off; }; }; +hotkey-overlay { skip-at-startup; }; +include "./noctalia.kdl"; +input { + keyboard { + numlock; + xkb { + layout "us,ru"; + options "grp:alt_shift_toggle"; + }; + }; + touchpad { + dwt; + natural-scroll; + tap; + }; +}; +layout { + center-focused-column "always"; + default-column-width { proportion 0.8; }; +}; +screenshot-path "~/Multimedia/Screenshots/%Y-%m-%d_%H-%M-%S.png"; +window-rule { + clip-to-geometry true; + geometry-corner-radius 8; + open-floating false; +}; +window-rule { + match app-id="mpv"; + open-fullscreen true; }; diff --git a/home/mods/noctalia.toml b/home/mods/noctalia.toml index cf0ab5e..c8f23ef 100644 --- a/home/mods/noctalia.toml +++ b/home/mods/noctalia.toml @@ -1,112 +1,43 @@ [bar] order = [ "default" ] - [bar.default] center = [ "workspaces" ] - enabled = true end = [ "tray", "keyboard_layout", "battery", "notifications" ] margin_ends = 0 start = [ "date", "clock", "sysmon" ] widget_spacing = 12 - [bar.default.dead_zone.actions] right = "none" - [control_center] -hidden_tabs = [ "media", "audio", "monitor", "notifications" ] - [[control_center.shortcuts]] type = "wifi" - [[control_center.shortcuts]] type = "bluetooth" - [[control_center.shortcuts]] type = "caffeine" - [[control_center.shortcuts]] type = "notification" - [[control_center.shortcuts]] type = "power_profile" - -[desktop_widgets] -enabled = false -schema_version = 2 -widget_order = [] - - [desktop_widgets.grid] - cell_size = 16 - major_interval = 4 - visible = true - - [desktop_widgets.widget] - [idle] behavior_order = [ "screen-off", "lock", "lock-and-suspend" ] - [idle.behavior.lock] action = "lock" enabled = true timeout = 600.0 - [idle.behavior.lock-and-suspend] action = "lock_and_suspend" enabled = true timeout = 900.0 - [idle.behavior.screen-off] action = "screen_off" enabled = true timeout = 300.0 - [location] address = "Chita" - -[lockscreen] -fingerprint = false - -[lockscreen_widgets] -enabled = false -schema_version = 2 -widget_order = [ "lockscreen-login-box@eDP-1" ] - - [lockscreen_widgets.grid] - cell_size = 16 - major_interval = 4 - visible = true - - [lockscreen_widgets.widget."lockscreen-login-box@eDP-1"] - box_height = 196.0 - box_width = 810.0 - cx = 960.0 - cy = 898.0 - output = "eDP-1" - placement_height = 1080.0 - placement_width = 1920.0 - rotation = 0.0 - type = "login_box" - - [lockscreen_widgets.widget."lockscreen-login-box@eDP-1".settings] - background_color = "surface_variant" - background_opacity = 0.88 - background_radius = 12.0 - center_password_text = false - input_opacity = 1.0 - input_radius = 6.0 - layout = "regular" - show_caps_lock = true - show_keyboard_layout = true - show_login_button = true - show_media = true - show_session_buttons = true - show_unlock_hint = true - show_weather = true - [notification] history_retention_hours = 8 layer = "overlay" - [osd.kinds] bluetooth = false caffeine = false @@ -117,32 +48,26 @@ media = false nightlight = false power_profile = false wifi = false - [shell] clipboard_enabled = false launch_apps_as_systemd_services = true screen_time_enabled = true - [shell.greeter_sync] auto_sync = true - [shell.screen_corners] enabled = true - [[shell.session.actions]] action = "lock" countdown_seconds = 0.0 enabled = true shortcut = "1" variant = "default" - [[shell.session.actions]] action = "lock_and_suspend" countdown_seconds = 0.0 enabled = true shortcut = "2" variant = "default" - [[shell.session.actions]] action = "command" command = "systemctl hibernate" @@ -152,40 +77,26 @@ screen_time_enabled = true label = "Гибернация" shortcut = "3" variant = "default" - [[shell.session.actions]] action = "reboot" countdown_seconds = 0.0 enabled = true shortcut = "4" variant = "default" - [[shell.session.actions]] action = "shutdown" countdown_seconds = 0.0 enabled = true shortcut = "5" variant = "default" - [theme] builtin = "Tokyo-Night" - [theme.templates] builtin_ids = [ "alacritty", "gtk3", "gtk4", "niri" ] - enable_community_templates = false - [wallpaper] directory = "/home/bogale/Multimedia/Wallpapers" transition_on_startup = true - [wallpaper.default] path = "/home/bogale/Multimedia/Wallpapers/main.jpg" - - [wallpaper.last] - path = "/home/bogale/Multimedia/Wallpapers/main.jpg" - - [wallpaper.monitors.eDP-1] - path = "/home/bogale/Multimedia/Wallpapers/main.jpg" - [weather] refresh_minutes = 10 diff --git a/home/root.nix b/home/root.nix index 5397c2c..7600e78 100644 --- a/home/root.nix +++ b/home/root.nix @@ -1,49 +1,48 @@ -{ config, pkgs, ... }: -{ - imports = [ ./common.nix ]; +{ config, pkgs, ... }: { home = { - username = "root"; homeDirectory = "/root"; + username = "root"; }; + imports = [ ./common.nix ]; programs = { bash = { - shellAliases.dd = "dd bs=1M conv=fsync status=progress"; - sessionVariables.SOPS_AGE_KEY_FILE = "/var/lib/sops-nix/key.txt"; initExtra = '' - session() { - systemd-run -tGM bogale@ --user --wait $SHELL - } awg-gen() { PRIVATE=$(awg genkey) + echo "private: $PRIVATE" printf "public: " echo $PRIVATE | awg pubkey - echo "private: $PRIVATE" printf "preshared: " awg genpsk } + session() { + systemd-run -tGM bogale@ --user --wait $SHELL + } ''; + sessionVariables.SOPS_AGE_KEY_FILE = config.sops.age.keyFile; + shellAliases.dd = "dd bs=1M conv=fsync status=progress"; }; tmux = { - enable = true; clock24 = true; + enable = true; escapeTime = 0; - keyMode = "vi"; - terminal = "screen-256color"; extraConfig = '' - unbind C-b - set -g mouse on - set -g prefix M-f bind f send-prefix bind h select-pane -L + bind i split-window -v bind j select-pane -D bind k select-pane -U bind l select-pane -R - bind i split-window -v bind u split-window -h + set -g mouse on + set -g prefix M-f set -s set-clipboard external - set-option -g focus-events on set-option -a terminal-features "xterm-256color:RGB" + set-option -g focus-events on + unbind C-b ''; + keyMode = "vi"; + terminal = "screen-256color"; }; }; } diff --git a/mods/pxeboot.nix b/mods/pxeboot.nix index 945f300..8055c78 100644 --- a/mods/pxeboot.nix +++ b/mods/pxeboot.nix @@ -1,4 +1,8 @@ -{ config, lib, pkgs, ... }: +{ + config, + pkgs, + ... +}: { environment.systemPackages = [ pkgs.grub2_efi ]; virtualisation.oci-containers.containers.fedora-dracut = { @@ -20,22 +24,39 @@ interface = "enp1s0"; tftp-root = "/srv/tftp"; dhcp-boot = "grubx64.efi"; - dhcp-range = [ "10.2.0.2,10.2.255.254,12h" "fc02::2,fc02::ffff:ffff:ffff:ffff,12h" ]; + dhcp-range = [ + "10.2.0.2,10.2.255.254,12h" + "fc02::2,fc02::ffff:ffff:ffff:ffff,12h" + ]; }; nfs.server = { enable = true; - exports = let - clients."10.2.0.0/16" = [ "mp" "rw" "no_root_squash" ]; - in { - "/srv/nfs/arch/root" = clients; - "/srv/nfs/fedora/root" = clients; - }; + exports = + let + clients."10.2.0.0/16" = [ + "mp" + "rw" + "no_root_squash" + ]; + in + { + "/srv/nfs/arch/root" = clients; + "/srv/nfs/fedora/root" = clients; + }; }; }; networking = { firewall = { - allowedTCPPorts = [ 53 2049 ]; - allowedUDPPorts = [ 53 67 69 547 ]; + allowedTCPPorts = [ + 53 + 2049 + ]; + allowedUDPPorts = [ + 53 + 67 + 69 + 547 + ]; }; nat = { enable = true; @@ -62,7 +83,13 @@ services.pxeboot = { before = [ "nfs-server.service" ]; requiredBy = [ "nfs-server.service" ]; - path = with pkgs; [ xz curl e2fsprogs grub2_efi util-linux ]; + path = with pkgs; [ + xz + curl + e2fsprogs + grub2_efi + util-linux + ]; serviceConfig = { Type = "oneshot"; RemainAfterExit = true; @@ -77,90 +104,92 @@ done ''; }; - script = let - resolv = pkgs.writeText "resolv.conf" '' - nameserver fc02::1 - nameserver 10.2.0.1 - options edns0 trust-ad - ''; - archIso = { - rootfs = "arch/x86_64/airootfs.sfs"; - hash = "684ded26c63240ff4a41e8c25ee84ea6da233f557364821f13d12c2b0a9059a5"; - url = "https://fastly.mirror.pkgbuild.com/iso/2026.10.01/archlinux-x86_64.iso"; - }; - fedoraIso = { - rootfs = "LiveOS/squashfs.img"; - hash = "1620295f6a00c27c3208f0c00b8ece4eab1ec69b9002152d97488bf26a426ddf"; - url = "https://download.fedoraproject.org/pub/fedora/linux/releases/44/Workstation/x86_64/iso/Fedora-Workstation-Live-44-1.7.x86_64.iso"; - }; - entryScript = pkgs.writeShellScript "entry.sh" '' - set -e - dnf install -y nfs-utils dracut-network - cd /data/workdir - for target in $(ls .. | grep -v workdir); do - mkdir $target - modsDir=../$target/usr/lib/modules/* - cp $modsDir/vmlinuz $target - dracut -Nm "network-manager nfs" --zstd -k $modsDir --kver $(basename $modsDir) $target/initramfs + script = + let + resolv = pkgs.writeText "resolv.conf" '' + nameserver fc02::1 + nameserver 10.2.0.1 + options edns0 trust-ad + ''; + archIso = { + rootfs = "arch/x86_64/airootfs.sfs"; + hash = "684ded26c63240ff4a41e8c25ee84ea6da233f557364821f13d12c2b0a9059a5"; + url = "https://fastly.mirror.pkgbuild.com/iso/2026.10.01/archlinux-x86_64.iso"; + }; + fedoraIso = { + rootfs = "LiveOS/squashfs.img"; + hash = "1620295f6a00c27c3208f0c00b8ece4eab1ec69b9002152d97488bf26a426ddf"; + url = "https://download.fedoraproject.org/pub/fedora/linux/releases/44/Workstation/x86_64/iso/Fedora-Workstation-Live-44-1.7.x86_64.iso"; + }; + entryScript = pkgs.writeShellScript "entry.sh" '' + set -e + dnf install -y nfs-utils dracut-network + cd /data/workdir + for target in $(ls .. | grep -v workdir); do + mkdir $target + modsDir=../$target/usr/lib/modules/* + cp $modsDir/vmlinuz $target + dracut -Nm "network-manager nfs" --zstd -k $modsDir --kver $(basename $modsDir) $target/initramfs + done + ''; + grubCfg = pkgs.writeText "grub.cfg" '' + function load { + set path=$cmdpath/boot/$1 + linux $path/vmlinuz $2 rw ip=dhcp root=nfs4:$net_default_server:/srv/nfs/$1/root + initrd $path/initramfs + } + menuentry Arch { + load arch + } + menuentry Fedora { + load fedora selinux=0 + } + ''; + in + '' + for distro in arch fedora; do + case $distro in + arch) url=${archIso.url} + rootfs=${archIso.rootfs} + hash=${archIso.hash};; + fedora) url=${fedoraIso.url} + rootfs=${fedoraIso.rootfs} + hash=${fedoraIso.hash};; + esac + mkdir -p /srv/nfs/$distro + cd /srv/nfs/$distro + if [ ! -e $distro.iso ]; then + until curl --head --max-time 3 https://www.google.com; do sleep 5; done + curl -C - "$url" -Lo $distro.iso.tmp + mv $distro.iso{.tmp,} + sha256sum $distro.iso | grep $hash + fi + mkdir -p loop root work lower upper + mountpoint -q loop || mount $distro.iso loop + mountpoint -q lower || mount loop/$rootfs lower + mountpoint -q root || mount -t overlay overlay root -o workdir=work,nfs_export=on,lowerdir=lower,upperdir=upper + if [ ! -e upper/etc/resolv.conf ]; then + cd root/etc + rm -f resolv.conf + cp ${resolv} resolv.conf + chattr +i resolv.conf + fi done - ''; - grubCfg = pkgs.writeText "grub.cfg" '' - function load { - set path=$cmdpath/boot/$1 - linux $path/vmlinuz $2 rw ip=dhcp root=nfs4:$net_default_server:/srv/nfs/$1/root - initrd $path/initramfs - } - menuentry Arch { - load arch - } - menuentry Fedora { - load fedora selinux=0 - } - ''; - in '' - for distro in arch fedora; do - case $distro in - arch) url=${archIso.url} - rootfs=${archIso.rootfs} - hash=${archIso.hash};; - fedora) url=${fedoraIso.url} - rootfs=${fedoraIso.rootfs} - hash=${fedoraIso.hash};; - esac - mkdir -p /srv/nfs/$distro - cd /srv/nfs/$distro - if [ ! -e $distro.iso ]; then - until curl --head --max-time 3 https://www.google.com; do sleep 5; done - curl -C - "$url" -Lo $distro.iso.tmp - mv $distro.iso{.tmp,} - sha256sum $distro.iso | grep $hash + cd /srv/tftp + if [ ! -e grubx64.efi ]; then + grub-mkstandalone -O x86_64-efi --compress=xz -o grubx64.efi --modules=efinet /boot/grub/grub.cfg=${grubCfg} fi - mkdir -p loop root work lower upper - mountpoint -q loop || mount $distro.iso loop - mountpoint -q lower || mount loop/$rootfs lower - mountpoint -q root || mount -t overlay overlay root -o workdir=work,nfs_export=on,lowerdir=lower,upperdir=upper - if [ ! -e upper/etc/resolv.conf ]; then - cd root/etc - rm -f resolv.conf - cp ${resolv} resolv.conf - chattr +i resolv.conf + if [ ! -e boot ]; then + workdir=/var/lib/podman-dracut + rm -rf $workdir + mkdir boot $workdir + cp ${entryScript} $workdir/entry.sh + systemctl --wait start podman-fedora-dracut.service + mv $workdir/*/ boot + chmod -R 644 boot + chmod +x $(find boot -type d) fi - done - cd /srv/tftp - if [ ! -e grubx64.efi ]; then - grub-mkstandalone -O x86_64-efi --compress=xz -o grubx64.efi --modules=efinet /boot/grub/grub.cfg=${grubCfg} - fi - if [ ! -e boot ]; then - workdir=/var/lib/podman-dracut - rm -rf $workdir - mkdir boot $workdir - cp ${entryScript} $workdir/entry.sh - systemctl --wait start podman-fedora-dracut.service - mv $workdir/*/ boot - chmod -R 644 boot - chmod +x $(find boot -type d) - fi - ''; + ''; }; }; } diff --git a/mods/vps-init.nix b/mods/vps-init.nix index 17cd435..ec35a06 100644 --- a/mods/vps-init.nix +++ b/mods/vps-init.nix @@ -1,7 +1,6 @@ -{ config, lib, pkgs, ... }: -{ +{ config, pkgs, ... }: { sops = { - secrets.awg0-spec = {}; + secrets.awg0-spec = { }; templates.awg0-conf.content = '' ${config.sops.placeholder.awg-obf} ${config.sops.placeholder.awg0-spec} @@ -9,10 +8,9 @@ }; systemd.services.vps-init = { path = [ pkgs.openssh ]; - serviceConfig.Type = "oneshot"; script = '' - cd /root/run/awg - date +%s > start-time + cd /root/run + date +%s > awg-start-time . vps-init.env scp -i /root/.ssh/vps ${config.sops.templates.awg0-conf.path} $SSHCONN:awg0.conf until cat <<'EOF' | ssh -i /root/.ssh/vps $SSHCONN @@ -26,18 +24,30 @@ FILENAME="$(mktemp)" (echo PasswordAuthentication no; cat sshd_config) > "$FILENAME" mv "$FILENAME" sshd_config - fallocate -l 1GiB /var/swapfile - chmod 600 /var/swapfile - mkswap /var/swapfile - echo "/var/swapfile none swap defaults 0 0" >> /etc/fstab + SIZE="$(awk '/MemTotal:/ { print $2 "KiB" }' /proc/meminfo)" + fallocate -l $SIZE /swapfile + chmod 600 /swapfile + mkswap /swapfile + echo "/swapfile none swap defaults 0 0" >> /etc/fstab + cd /etc/apt/apt.conf.d + cat <<' EOF' > 99policy + Dpkg::Options { "--force-confnew"; }; + Unattended-Upgrade::Automatic-Reboot "true"; + Unattended-Upgrade::Remove-Unused-Dependencies "true"; + EOF export DEBIAN_FRONTEND=noninteractive + apt-get install -y unattended-upgrades + cat <<' EOF' > 20auto-upgrades + APT::Periodic::Unattended-Upgrade "1"; + APT::Periodic::Update-Package-Lists "1"; + EOF apt-get update - apt-get dist-upgrade -y -o Dpkg::Options::="--force-confold";; + apt-get dist-upgrade -y;; 1) cat <<' EOF' >> /etc/sysctl.conf - net.ipv6.conf.all.forwarding = 1 - net.ipv4.ip_forward = 1 net.ipv4.conf.all.forwarding = 1 + net.ipv4.ip_forward = 1 + net.ipv6.conf.all.forwarding = 1 EOF for v in 6 ""; do ip''${v}tables -P FORWARD DROP @@ -83,7 +93,8 @@ exit 1 EOF do sleep 1; done - echo Installed in $(($(date +%s)-$(cat start-time)))s + echo Installed in $(($(date +%s)-$(cat awg-start-time)))s ''; + serviceConfig.Type = "oneshot"; }; } diff --git a/server/configuration.nix b/server/configuration.nix index 8cb8399..06f1bf5 100644 --- a/server/configuration.nix +++ b/server/configuration.nix @@ -1,71 +1,98 @@ -{ config, lib, pkgs, ... }: -{ +{ config, pkgs, ... }: { boot.kernelParams = [ "consoleblank=60" ]; - imports = [ ../common.nix ./hardware.nix ./mods/web.nix ./mods/mail.nix ./mods/system.nix ]; + imports = [ + ../common.nix + ./hardware.nix + ./mods/mail.nix + ./mods/system.nix + ./mods/web.nix + ]; + networking = { + firewall = { + allowedTCPPorts = [ + 25 + 443 + 465 + 80 + 993 + ]; + allowedUDPPorts = [ 443 ]; + }; + hostName = "nixos-server"; + networkmanager.ensureProfiles.profiles.home-wifi = { + ipv4.addresses = "10.1.0.2/16"; + ipv6.addresses = "fc01::2/64"; + wifi-security.psk = "$BOGALE_2_4_PSK"; + wifi.ssid = "bogale_2.4"; + }; + wg-quick.interfaces.awg0 = { + address = [ + "10.0.0.2/32" + "fc00::2/128" + ]; + configFile = config.sops.templates.awg1-conf.path; + }; + }; + security.acme = { + acceptTerms = true; + certs."bogaledev.ru" = { + credentialFiles.CF_DNS_API_TOKEN_FILE = config.sops.secrets.cf-token.path; + dnsProvider = "cloudflare"; + extraDomainNames = [ "*.bogaledev.ru" ]; + reloadServices = [ + "dovecot.service" + "nginx.service" + "postfix.service" + ]; + validMinDays = 3; + }; + defaults.email = "letsencrypt@bogaledev.ru"; + }; services.openssh = { enable = true; settings.PasswordAuthentication = false; }; sops = { - secrets.awg1-spec = {}; + secrets = { + awg1-spec = { }; + cf-token = { }; + }; templates.awg1-conf.content = '' ${config.sops.placeholder.awg-obf} ${config.sops.placeholder.awg1-spec} ''; }; systemd.tmpfiles.rules = [ - "d /root/backup/server" - "L /root/backup/server/http - - - - /srv/http" "L /root/backup/server/acme - - - - /var/lib/acme" - "L /root/backup/server/mail - - - - /var/spool/mail" "L /root/backup/server/forgejo - - - - /var/lib/forgejo" + "L /root/backup/server/http - - - - /srv/http" + "L /root/backup/server/mail - - - - /var/spool/mail" "L /root/backup/server/postgresql - - - - /var/backup/postgresql" + "d /root/backup/server" ]; - security.acme = { - acceptTerms = true; - defaults.email = "letsencrypt@bogaledev.ru"; - certs."bogaledev.ru" = { - validMinDays = 3; - dnsProvider = "cloudflare"; - extraDomainNames = [ "*.bogaledev.ru" ]; - credentialFiles = { "CF_DNS_API_TOKEN_FILE" = "/secrets/cf-token"; }; - reloadServices = [ "nginx.service" "dovecot.service" "postfix.service" ]; - }; - }; - networking = { - hostName = "nixos-server"; - firewall = { - allowedUDPPorts = [ 443 ]; - allowedTCPPorts = [ 25 80 443 465 993 ]; - }; - wg-quick.interfaces.awg0 = { - address = [ "10.0.0.2/32" "fc00::2/128" ]; - configFile = config.sops.templates.awg1-conf.path; - }; - networkmanager.ensureProfiles.profiles.home-wifi = { - wifi.ssid = "bogale_2.4"; - ipv6.addresses = "fc01::2/64"; - ipv4.addresses = "10.1.0.2/16"; - wifi-security.psk = "$BOGALE_2_4_PSK"; - }; - }; users = { groups = { php.gid = 1568; vmail.gid = 1819; }; users = { - nginx.extraGroups = [ "php" "acme" "grafana" ]; - root.openssh.authorizedKeys.keys = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPTb4c1ISQSV34GN27GgaJ08jpiRM3Wul/iSWjQ6emTq" ]; + nginx.extraGroups = [ + "acme" + "grafana" + "php" + ]; php = { - uid = 1568; group = "php"; isSystemUser = true; + uid = 1568; }; + root.openssh.authorizedKeys.keys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPTb4c1ISQSV34GN27GgaJ08jpiRM3Wul/iSWjQ6emTq" + ]; vmail = { - uid = 1819; group = "vmail"; isSystemUser = true; + uid = 1819; }; }; }; diff --git a/server/hardware.nix b/server/hardware.nix index f76336e..5e6a40f 100644 --- a/server/hardware.nix +++ b/server/hardware.nix @@ -1,27 +1,41 @@ -{ config, lib, pkgs, modulesPath, ... }: { - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; - hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + config, + lib, + modulesPath, + ... +}: +{ boot = { + initrd = { + availableKernelModules = [ + "ahci" + "ehci_pci" + "sd_mod" + "sdhci_pci" + "xhci_pci" + ]; + luks.devices.root.device = "/dev/disk/by-uuid/e0288e5e-87eb-453f-ab22-0d6e54576609"; + }; kernelParams = [ "memmap=0x4000%0xbfb76000-4" "memmap=0x4000%0xbfb7a000-4" ]; - initrd = { - availableKernelModules = [ "xhci_pci" "ahci" "ehci_pci" "sd_mod" "sdhci_pci" ]; - luks.devices.root.device = "/dev/disk/by-uuid/e0288e5e-87eb-453f-ab22-0d6e54576609"; - }; }; fileSystems = { "/" = { - fsType = "ext4"; device = "/dev/mapper/root"; + fsType = "ext4"; }; "/boot" = { - fsType = "vfat"; device = "/dev/disk/by-uuid/86F4-A8F1"; - options = [ "fmask=0077" "dmask=0077" ]; + fsType = "vfat"; + options = [ + "dmask=0077" + "fmask=0077" + ]; }; }; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; } diff --git a/server/mods/mail.nix b/server/mods/mail.nix index 162dc62..a3b7f7b 100644 --- a/server/mods/mail.nix +++ b/server/mods/mail.nix @@ -1,87 +1,111 @@ -{ config, lib, pkgs, ... }: +{ config, ... }: let postfixDir = "/var/spool/postfix"; -in { - systemd.tmpfiles.rules = [ "d ${postfixDir} 0700 postfix postfix" ]; - services = let - sslCertDir = config.security.acme.certs."bogaledev.ru".directory; - in { - redis.servers.rspamd = { - enable = true; - user = "rspamd"; - }; - rspamd = { - enable = true; - postfix.enable = true; - locals = { - "classifier-bayes.conf".text = "autolearn = true;"; - "redis.conf".text = ''servers = "${config.services.redis.servers.rspamd.unixSocket}";''; - }; - }; - postfix = { - enable = true; - enableSubmissions = true; - virtualMapType = "regexp"; - mapFiles.smtp_passwd = "/secrets/smtp_passwd"; - virtual = "/.*@bogaledev.ru/ mail@bogaledev.ru"; - submissionsOptions = { - smtpd_sasl_type = "dovecot"; - smtpd_tls_wrappermode = true; - smtpd_sasl_auth_enable = "yes"; - smtpd_sasl_path = "${postfixDir}/auth"; - milter_macro_daemon_name = "ORIGINATING"; - smtpd_client_restrictions = "permit_sasl_authenticated,reject"; - }; - settings.main = { - smtp_tls_wrappermode = true; - smtp_sasl_auth_enable = true; - smtp_tls_security_level = "verify"; - smtpd_tls_security_level = "encrypt"; - relayhost = [ "smtp.resend.com:2465" ]; - virtual_mailbox_domains = "bogaledev.ru"; - smtp_sasl_tls_security_options = "noanonymous"; - virtual_transport = "lmtp:unix:${postfixDir}/lmtp"; - smtp_sasl_password_maps = "hash:/etc/postfix/smtp_passwd"; - smtpd_tls_chain_files = [ "${sslCertDir}/key.pem" "${sslCertDir}/fullchain.pem" ]; - }; - }; - dovecot2 = { - enable = true; - settings = let - postfix-mode = { - mode = "0600"; - user = "postfix"; - group = "postfix"; - }; - in { - ssl = "required"; - mail_gid = "vmail"; - mail_uid = "vmail"; - mail_driver = "maildir"; - auth_mechanisms = [ "plain" ]; - protocols = [ "imap" "lmtp" ]; - dovecot_config_version = "2.4.5"; - dovecot_storage_version = "2.4.5"; - mail_path = "/var/spool/mail/vmail"; - ssl_server_key_file = "${sslCertDir}/key.pem"; - ssl_server_cert_file = "${sslCertDir}/fullchain.pem"; - "passdb passwd-file".passwd_file_path = "/secrets/dovecot-pw"; - "service auth"."unix_listener ${postfixDir}/auth" = postfix-mode; - "service lmtp"."unix_listener ${postfixDir}/lmtp" = postfix-mode; - "namespace inbox" = let - mailbox = name: { - auto = "subscribe"; - mailbox_special_use = "\\${name}"; +in +{ + services = + let + sslCertDir = config.security.acme.certs."bogaledev.ru".directory; + in + { + dovecot2 = { + enable = true; + settings = + let + postfix-mode = { + group = "postfix"; + mode = "0600"; + user = "postfix"; + }; + in + { + "namespace inbox" = + let + mailbox = name: { + auto = "subscribe"; + mailbox_special_use = "\\${name}"; + }; + in + { + "mailbox Archive" = mailbox "Archive"; + "mailbox Important" = mailbox "Flagged"; + "mailbox Sent" = mailbox "Sent"; + "mailbox Spam" = mailbox "Junk" // { + mailbox_autoexpunge = "45d"; + }; + "mailbox Trash" = mailbox "Trash" // { + mailbox_autoexpunge = "45d"; + }; + inbox = true; + }; + "passdb passwd-file".passwd_file_path = config.sops.secrets.dovecot-pw.path; + "service auth"."unix_listener ${postfixDir}/auth" = postfix-mode; + "service lmtp"."unix_listener ${postfixDir}/lmtp" = postfix-mode; + auth_mechanisms = [ "plain" ]; + dovecot_config_version = "2.4.5"; + dovecot_storage_version = "2.4.5"; + mail_driver = "maildir"; + mail_gid = "vmail"; + mail_path = "/var/spool/mail/vmail"; + mail_uid = "vmail"; + protocols = [ + "imap" + "lmtp" + ]; + ssl = "required"; + ssl_server_cert_file = "${sslCertDir}/fullchain.pem"; + ssl_server_key_file = "${sslCertDir}/key.pem"; }; - in { - inbox = true; - "mailbox Sent" = mailbox "Sent"; - "mailbox Archive" = mailbox "Archive"; - "mailbox Important" = mailbox "Flagged"; - "mailbox Spam" = mailbox "Junk" // { mailbox_autoexpunge = "45d"; }; - "mailbox Trash" = mailbox "Trash" // { mailbox_autoexpunge = "45d"; }; + }; + postfix = { + enable = true; + enableSubmissions = true; + mapFiles.smtp-sasl = config.sops.secrets.smtp-sasl.path; + settings.main = { + relayhost = [ "smtp.resend.com:2465" ]; + smtp_sasl_auth_enable = true; + smtp_sasl_password_maps = "hash:/etc/postfix/smtp-sasl"; + smtp_sasl_tls_security_options = "noanonymous"; + smtp_tls_security_level = "verify"; + smtp_tls_wrappermode = true; + smtpd_tls_chain_files = [ + "${sslCertDir}/key.pem" + "${sslCertDir}/fullchain.pem" + ]; + smtpd_tls_security_level = "encrypt"; + virtual_mailbox_domains = "bogaledev.ru"; + virtual_transport = "lmtp:unix:${postfixDir}/lmtp"; }; + submissionsOptions = { + milter_macro_daemon_name = "ORIGINATING"; + smtpd_client_restrictions = "permit_sasl_authenticated,reject"; + smtpd_sasl_auth_enable = "yes"; + smtpd_sasl_path = "${postfixDir}/auth"; + smtpd_sasl_type = "dovecot"; + smtpd_tls_wrappermode = true; + }; + virtual = "/.*@bogaledev.ru/ mail@bogaledev.ru"; + virtualMapType = "regexp"; + }; + redis.servers.rspamd = { + enable = true; + user = "rspamd"; + }; + rspamd = { + enable = true; + locals = { + "classifier-bayes.conf".text = "autolearn = true;"; + "redis.conf".text = ''servers = "${config.services.redis.servers.rspamd.unixSocket}";''; + }; + postfix.enable = true; }; }; + sops.secrets = { + dovecot-pw = { + group = "dovecot2"; + mode = "0440"; + }; + smtp-sasl = { }; }; + systemd.tmpfiles.rules = [ "d ${postfixDir} 0700 postfix" ]; } diff --git a/server/mods/system.nix b/server/mods/system.nix index c624060..3b53459 100644 --- a/server/mods/system.nix +++ b/server/mods/system.nix @@ -1,69 +1,27 @@ -{ config, lib, pkgs, ... }: -{ - services = { - prometheus = { - enable = true; - exporters.node.enable = true; - scrapeConfigs = [ { +{ config, pkgs, ... }: { + services.prometheus = { + enable = true; + exporters.node.enable = true; + scrapeConfigs = [ + { job_name = "node"; - static_configs = [ { targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ]; } ]; - } ]; - }; - grafana = { - enable = true; - settings = { - security.secret_key = "$__file{/secrets/grafana-key}"; - database = { - user = "grafana"; - type = "postgres"; - host = "/run/postgresql"; - }; - server = { - enable_gzip = true; - protocol = "socket"; - root_url = "https://bogaledev.ru/grafana"; - }; - }; - }; + static_configs = [ + { + targets = [ + "localhost:${toString config.services.prometheus.exporters.node.port}" + ]; + } + ]; + } + ]; }; + sops.secrets.tgbot-env = { }; systemd = { - timers = { - tgbot-send = { - wantedBy = [ "timers.target" ]; - timerConfig = { - Persistent = true; - OnCalendar = "*-*-01 16:00"; - }; - }; - network-watchdog = { - wantedBy = [ "timers.target" ]; - timerConfig = { - OnBootSec = 30; - AccuracySec = 1; - OnUnitActiveSec = 10; - }; - }; - }; services = { - tgbot-send = { - serviceConfig.Type = "oneshot"; - script = '' - . /secrets/tgbot.env - for msg in "''${MESSAGES[@]}"; do - TEXT="''${msg#*:}" - CHAT_ID="''${msg%%:*}" - ${pkgs.curl}/bin/curl -X POST "https://api.telegram.org/$BOT/sendMessage" -d "chat_id=$CHAT_ID" -d "text=$TEXT" 2> /dev/null | ${pkgs.jq}/bin/jq - sleep 1 - done - ''; - }; network-watchdog = { - serviceConfig = { - Type = "oneshot"; - LogLevelMax = "warning"; - }; script = '' - if [ ! -e /run/network.failures ] || [ ! -e /run/network.limit ] || ${pkgs.curl}/bin/curl --head --max-time 3 https://www.google.com; then + if [ ! -e /run/network.failures ] || [ ! -e /run/network.limit ] || \ + ${pkgs.curl}/bin/curl --head --max-time 3 https://bogaledev.ru; then limit=3 failures=0 else @@ -73,12 +31,48 @@ if [ $failures -ge $limit ]; then echo "<4>restarting network" systemctl restart NetworkManager.service + sleep 1 + systemctl restart wg-quick-awg0.service [ $limit -lt 360 ] && limit=$((2*$limit)) failures=0 fi echo $limit > /run/network.limit echo $failures > /run/network.failures ''; + serviceConfig = { + LogLevelMax = "warning"; + Type = "oneshot"; + }; + }; + tgbot-send = { + script = '' + . ${config.sops.secrets.tgbot-env.path} + for msg in "''${MESSAGES[@]}"; do + CHAT_ID="''${msg%%:*}" + TEXT="''${msg#*:}" + ${pkgs.curl}/bin/curl -X POST "https://api.telegram.org/$BOT/sendMessage" \ + -d "chat_id=$CHAT_ID" -d "text=$TEXT" 2> /dev/null | ${pkgs.jq}/bin/jq + sleep 1 + done + ''; + serviceConfig.Type = "oneshot"; + }; + }; + timers = { + network-watchdog = { + timerConfig = { + AccuracySec = 1; + OnBootSec = 30; + OnUnitActiveSec = 10; + }; + wantedBy = [ "timers.target" ]; + }; + tgbot-send = { + timerConfig = { + OnCalendar = "*-*-01 16:00"; + Persistent = true; + }; + wantedBy = [ "timers.target" ]; }; }; }; diff --git a/server/mods/web.nix b/server/mods/web.nix index 21ecc40..7912d97 100644 --- a/server/mods/web.nix +++ b/server/mods/web.nix @@ -1,141 +1,184 @@ -{ config, lib, pkgs, ... }: -{ - services = let - sslCertDir = config.security.acme.certs."bogaledev.ru".directory; - phpSettings = { - "pm" = "ondemand"; - "pm.max_children" = 4; - "listen.group" = "nginx"; - "listen.owner" = "nginx"; - }; - in { - dnsmasq.settings.cname = "nextcloud-local,localhost"; - phpfpm.pools.php = { - user = "php"; - group = "php"; - settings = phpSettings; - }; - postgresqlBackup = { - enable = true; - startAt = "16:00"; - compression = "none"; - databases = [ "php" "forgejo" "grafana" "nextcloud" "vaultwarden" ]; - }; - postgresql = { - enable = true; - ensureDatabases = [ "php" "grafana" ]; - ensureUsers = let - user = name: { - inherit name; - ensureDBOwnership = true; - }; - in map user [ "php" "grafana" ]; - }; - nextcloud = { - enable = true; - poolSettings = phpSettings; - hostName = "nextcloud-local"; - database.createLocally = true; - config = { - dbtype = "pgsql"; - adminpassFile = "/secrets/nextcloud-pw"; +{ config, pkgs, ... }: { + services = + let + phpSettings = { + "listen.group" = "nginx"; + "listen.owner" = "nginx"; + "pm" = "ondemand"; + "pm.max_children" = 4; }; - settings = { - overwritewebroot = "/nextcloud"; - trusted_domains = [ "bogaledev.ru" "wl.bogaledev.ru" ]; - }; - }; - vaultwarden = { - enable = true; - configurePostgres = true; - dbBackend = "postgresql"; - package = pkgs.vaultwarden-postgresql; - environmentFile = "/secrets/vw-token.env"; - config = { - ROCKET_PORT = 46151; - SIGNUPS_ALLOWED = false; - TRASH_AUTO_DELETE_DAYS = 90; - PASSWORD_HINTS_ALLOWED = false; - EMERGENCY_ACCESS_ALLOWED = false; - DOMAIN = "https://bogaledev.ru/vaultwarden/"; - }; - }; - forgejo = { - enable = true; - database.type = "postgres"; - settings = { - service = { - ENABLE_CAPTCHA = true; - REGISTER_EMAIL_CONFIRM = true; - }; - mailer = { - ENABLED = true; - SMTP_PORT = 25; - SMTP_ADDR = "localhost"; - FROM = "Forgejo "; - }; - server = { - SSH_PORT = 32831; - PROTOCOL = "http+unix"; - ROOT_URL = "https://bogaledev.ru/git/"; - HTTP_ADDR = "/run/forgejo/forgejo.sock"; - }; - }; - }; - nginx = { - enable = true; - recommendedTlsSettings = true; - recommendedGzipSettings = true; - recommendedOptimisation = true; - recommendedProxySettings = true; - recommendedBrotliSettings = true; - virtualHosts = { - nextcloud-local.listen = [ { - port = 45837; - addr = "nextcloud-local"; - } ]; - main = let - phpPool = '' - index index.php index.html; - location ~ \.php$ { - fastcgi_pass unix:${config.services.phpfpm.pools.php.socket}; - } - ''; - localNetworks = '' - allow fc00::/64; - allow fc01::/96; - allow 10.0.0.0/16; - allow 10.1.0.0/24; - deny all; - ''; - in { - quic = true; - default = true; - forceSSL = true; - root = "/srv/http"; - useACMEHost = "bogaledev.ru"; - extraConfig = '' - add_header Alt-Svc 'h3=":443"; ma=2592000' always; - add_header X-Content-Type-Options 'nosniff' always; - ''; - locations = { - "/".extraConfig = phpPool; - "/local/".extraConfig = "${phpPool} ${localNetworks}"; - "/nextcloud/".proxyPass = "http://nextcloud-local:45837/"; - "/git/".proxyPass = "http://unix:/run/forgejo/forgejo.sock:/"; - "/vaultwarden/" = { - proxyWebsockets = true; - extraConfig = localNetworks; - proxyPass = "http://localhost:46151"; - }; - "/grafana/" = { - proxyWebsockets = true; - extraConfig = localNetworks; - proxyPass = "http://unix:/run/grafana/grafana.sock:/"; - }; + sslCertDir = config.security.acme.certs."bogaledev.ru".directory; + in + { + forgejo = { + database.type = "postgres"; + enable = true; + settings = { + mailer = { + ENABLED = true; + FROM = "Forgejo "; + SMTP_ADDR = "localhost"; + SMTP_PORT = 25; + }; + server = { + HTTP_ADDR = "/run/forgejo/forgejo.sock"; + PROTOCOL = "http+unix"; + ROOT_URL = "https://bogaledev.ru/git/"; + SSH_PORT = 32831; + }; + service = { + ENABLE_CAPTCHA = true; + REGISTER_EMAIL_CONFIRM = true; }; }; }; + grafana = { + enable = true; + settings = { + database = { + host = "/run/postgresql"; + type = "postgres"; + user = "grafana"; + }; + security.secret_key = "$__file{${config.sops.secrets.grafana-key.path}}"; + server = { + enable_gzip = true; + protocol = "socket"; + root_url = "https://bogaledev.ru/grafana"; + }; + }; + }; + nextcloud = { + config = { + adminpassFile = config.sops.secrets.nextcloud-pw.path; + dbtype = "pgsql"; + }; + database.createLocally = true; + enable = true; + hostName = "nextcloud-local"; + poolSettings = phpSettings; + settings = { + htaccess.RewriteBase = "/nextcloud"; + overwritewebroot = "/nextcloud"; + trusted_domains = [ + "bogaledev.ru" + "wl.bogaledev.ru" + ]; + }; + }; + nginx = { + enable = true; + recommendedBrotliSettings = true; + recommendedGzipSettings = true; + recommendedOptimisation = true; + recommendedProxySettings = true; + recommendedTlsSettings = true; + virtualHosts = { + nextcloud-local.listen = [ + { + addr = "localhost"; + port = 45837; + } + ]; + main = + let + localNetworks = '' + allow 10.0.0.0/16; + allow 10.1.0.0/24; + allow fc00::/64; + allow fc01::/96; + deny all; + ''; + phpPool = '' + index index.php index.html; + location ~ \.php$ { + fastcgi_pass unix:${config.services.phpfpm.pools.php.socket}; + } + ''; + in + { + default = true; + extraConfig = '' + add_header Alt-Svc 'h3=":443"; ma=2592000' always; + add_header X-Content-Type-Options 'nosniff' always; + ''; + forceSSL = true; + locations = { + "/".extraConfig = phpPool; + "/git/".proxyPass = "http://unix:/run/forgejo/forgejo.sock:/"; + "/grafana/" = { + extraConfig = localNetworks; + proxyPass = "http://unix:/run/grafana/grafana.sock:/"; + proxyWebsockets = true; + }; + "/local/".extraConfig = "${phpPool} ${localNetworks}"; + "/nextcloud/".proxyPass = "http://localhost:45837/"; + "/vaultwarden/" = { + extraConfig = localNetworks; + proxyPass = "http://localhost:46151"; + proxyWebsockets = true; + }; + }; + quic = true; + root = "/srv/http"; + useACMEHost = "bogaledev.ru"; + }; + }; + }; + phpfpm.pools.php = { + group = "php"; + settings = phpSettings; + user = "php"; + }; + postgresql = { + enable = true; + ensureDatabases = [ + "grafana" + "php" + ]; + ensureUsers = + let + user = name: { + ensureDBOwnership = true; + inherit name; + }; + in + map user [ + "grafana" + "php" + ]; + }; + postgresqlBackup = { + compression = "none"; + databases = [ + "forgejo" + "grafana" + "nextcloud" + "php" + "vaultwarden" + ]; + enable = true; + startAt = "16:00"; + }; + vaultwarden = { + config = { + DOMAIN = "https://bogaledev.ru/vaultwarden/"; + EMERGENCY_ACCESS_ALLOWED = false; + PASSWORD_HINTS_ALLOWED = false; + ROCKET_PORT = 46151; + SIGNUPS_ALLOWED = false; + TRASH_AUTO_DELETE_DAYS = 90; + }; + configurePostgres = true; + dbBackend = "postgresql"; + enable = true; + environmentFile = config.sops.secrets.vaultwarden-env.path; + package = pkgs.vaultwarden-postgresql; + }; }; + sops.secrets = { + grafana-key = { }; + nextcloud-pw = { }; + vaultwarden-env = { }; }; }