From 1dd7fac8ed951b97f9b121bae1ad626ec8853ba1 Mon Sep 17 00:00:00 2001 From: bogale Date: Tue, 27 Oct 2026 00:08:14 +0900 Subject: [PATCH] pxeboot rewrite, bridge for qemu --- common.nix | 80 ++------------------------------------- desktop/configuration.nix | 16 ++------ flake.nix | 8 +++- home/bogale.nix | 1 + mods/host.nix | 62 ++++++++++++++++++++++++++++++ mods/pxeboot.nix | 40 +++++++++++++------- pxeboot/configuration.nix | 7 ++++ pxeboot/hardware.nix | 15 ++++++++ server/configuration.nix | 10 +---- server/mods/web.nix | 2 + 10 files changed, 129 insertions(+), 112 deletions(-) create mode 100644 mods/host.nix create mode 100644 pxeboot/configuration.nix create mode 100644 pxeboot/hardware.nix diff --git a/common.nix b/common.nix index 7f37077..7ba3971 100644 --- a/common.nix +++ b/common.nix @@ -1,7 +1,5 @@ { config, pkgs, ... }: { boot = { - extraModulePackages = [ config.boot.kernelPackages.amneziawg ]; - kernelModules = [ "amneziawg" ]; kernelPackages = pkgs.linuxPackages_latest; loader.limine = { enable = true; @@ -19,96 +17,24 @@ }; environment.systemPackages = with pkgs; [ _7zz - binutils file jq - openssl python314 - qrencode sbctl sops speedtest-go ]; - fileSystems = { - "/".options = [ "noatime" ]; - "/boot".options = [ "noatime" ]; - }; i18n.defaultLocale = "ru_RU.UTF-8"; - imports = [ - ./mods/pxeboot.nix - ./mods/vps-init.nix - ]; - networking = { - networkmanager = { - dns = "dnsmasq"; - enable = true; - ensureProfiles = { - environmentFiles = [ config.sops.secrets.wifi-env.path ]; - profiles.home-wifi = { - connection = { - id = "home-wifi"; - type = "wifi"; - }; - ipv4 = { - gateway = "10.1.0.1"; - method = "manual"; - }; - ipv6 = { - gateway = "fc01::1"; - method = "manual"; - }; - wifi-security = { - key-mgmt = "sae"; - psk = "$BOGALE_5_PSK"; - }; - wifi.ssid = "bogale_5"; - }; - }; - }; - wg-quick.interfaces.awg0 = { - peers = [ - { - allowedIPs = [ - "::/0" - "0.0.0.0/0" - ]; - endpoint = "bogaledev.ru"; - } - ]; - type = "amneziawg"; - }; - }; + networking.networkmanager.enable = true; 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; - }; + services.swapspace.enable = true; sops = { age.keyFile = "/var/lib/sops-nix/key.txt"; defaultSopsFile = ./.secrets.yaml; - secrets = { - awg-obf = { }; - root-passwd = { }; - wifi-env = { }; - }; + secrets.root-passwd = { }; }; system.stateVersion = "26.11"; systemd.tmpfiles.rules = [ diff --git a/desktop/configuration.nix b/desktop/configuration.nix index 4dc5d8d..8807497 100644 --- a/desktop/configuration.nix +++ b/desktop/configuration.nix @@ -2,25 +2,23 @@ boot.kernelParams = [ "hibernate.compressor=lz4" ]; environment.systemPackages = with pkgs; [ android-tools + binutils binwalk qemu + qrencode ]; hardware = { bluetooth.enable = true; graphics.enable32Bit = true; }; imports = [ - ../common.nix + ../mods/host.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"; @@ -37,13 +35,7 @@ wifi.ssid = "Hello world"; }; }; - wg-quick.interfaces.awg0 = { - address = [ - "10.0.0.3/32" - "fc00::3/128" - ]; - configFile = config.sops.templates.awg2-conf.path; - }; + wg-quick.interfaces.awg0.configFile = config.sops.templates.awg2-conf.path; }; programs = { niri.enable = true; diff --git a/flake.nix b/flake.nix index b13ae59..38fdd8c 100644 --- a/flake.nix +++ b/flake.nix @@ -27,7 +27,6 @@ { home-manager = { extraSpecialArgs = { inherit inputs; }; - sharedModules = [ inputs.sops-nix.homeManagerModules.sops ]; useGlobalPkgs = true; useUserPackages = true; users = { @@ -39,6 +38,12 @@ sops-nix.nixosModules.sops ]; }; + nixos-pxeboot = nixpkgs.lib.nixosSystem { + modules = [ + ./pxeboot/configuration.nix + sops-nix.nixosModules.sops + ]; + }; nixos-server = nixpkgs.lib.nixosSystem { modules = [ ./server/configuration.nix @@ -46,7 +51,6 @@ { home-manager = { extraSpecialArgs = { inherit inputs; }; - sharedModules = [ inputs.sops-nix.homeManagerModules.sops ]; useGlobalPkgs = true; useUserPackages = true; users.root = ./home/root.nix; diff --git a/home/bogale.nix b/home/bogale.nix index 95e97c2..f4f91ea 100644 --- a/home/bogale.nix +++ b/home/bogale.nix @@ -20,6 +20,7 @@ qbittorrent telegram-desktop thunderbird + wl-mirror ]; pointerCursor = { enable = true; diff --git a/mods/host.nix b/mods/host.nix new file mode 100644 index 0000000..c981deb --- /dev/null +++ b/mods/host.nix @@ -0,0 +1,62 @@ +{ config, pkgs, ... }: { + boot = { + extraModulePackages = [ config.boot.kernelPackages.amneziawg ]; + kernelModules = [ "amneziawg" ]; + }; + fileSystems = { + "/".options = [ "noatime" ]; + "/boot".options = [ "noatime" ]; + }; + imports = [ + ../common.nix + ./pxeboot.nix + ./vps-init.nix + ]; + networking = { + networkmanager = { + dns = "dnsmasq"; + ensureProfiles = { + environmentFiles = [ config.sops.secrets.wifi-env.path ]; + profiles.home-wifi = { + connection = { + id = "home-wifi"; + type = "wifi"; + }; + ipv4 = { + gateway = "10.1.0.1"; + method = "manual"; + }; + ipv6 = { + gateway = "fc01::1"; + method = "manual"; + }; + wifi-security = { + key-mgmt = "sae"; + psk = "$BOGALE_5_PSK"; + }; + wifi.ssid = "bogale_5"; + }; + }; + }; + wg-quick.interfaces.awg0.type = "amneziawg"; + }; + services.dnsmasq = { + enable = true; + settings = { + bogus-priv = true; + cache-size = 4096; + domain-needed = true; + no-resolv = true; + server = [ + "1.0.0.2" + "1.1.1.2" + "2606:4700:4700::1002" + "2606:4700:4700::1112" + ]; + }; + }; + sops.secrets = { + awg-obf = { }; + wifi-env = { }; + }; +} diff --git a/mods/pxeboot.nix b/mods/pxeboot.nix index 495dc21..df56462 100644 --- a/mods/pxeboot.nix +++ b/mods/pxeboot.nix @@ -16,33 +16,47 @@ nat = { enable = true; enableIPv6 = true; - internalInterfaces = [ "enp1s0" ]; + internalInterfaces = [ "br0" ]; }; - networkmanager.ensureProfiles.profiles.static-eth = { - connection = { - id = "static-eth"; + networkmanager.ensureProfiles.profiles = { + slave-ethernet.connection = { + controller = "br0"; + id = "slave-ethernet"; type = "ethernet"; }; - ipv4 = { - addresses = "10.2.0.1/16"; - method = "manual"; + static-bridge = { + connection = { + id = "static-bridge"; + interface-name = "br0"; + type = "bridge"; + }; + ipv4 = { + addresses = "10.2.0.1/16"; + method = "manual"; + }; + ipv6 = { + addresses = "fc02::1/64"; + method = "manual"; + }; }; - ipv6 = { - addresses = "fc02::1/64"; - method = "manual"; + dhcp-bridge.connection = { + id = "dhcp-bridge"; + interface-name = "br0"; + type = "bridge"; }; }; }; services = { dnsmasq.settings = { - bind-dynamic = true; + bind-interfaces = true; dhcp-boot = "grubx64.efi"; dhcp-range = [ "10.2.0.2,10.2.255.254,12h" "fc02::2,fc02::ffff:ffff:ffff:ffff,12h" ]; + enable-ra = true; enable-tftp = true; - interface = "enp1s0"; + interface = "br0"; tftp-root = "/srv/tftp"; }; nfs.server = { @@ -62,7 +76,7 @@ grub2_efi xz ]; - requiredBy = [ "nfs-server.service" ]; + #requiredBy = [ "nfs-server.service" ]; script = '' if [ ! -e /srv/nfs/nixos ]; then mkdir -p /srv/nfs/nixos diff --git a/pxeboot/configuration.nix b/pxeboot/configuration.nix new file mode 100644 index 0000000..4fc7e96 --- /dev/null +++ b/pxeboot/configuration.nix @@ -0,0 +1,7 @@ +{ config, pkgs, ... }: { + imports = [ + ../common.nix + ./hardware.nix + ]; + networking.hostName = "nixos-pxeboot"; +} diff --git a/pxeboot/hardware.nix b/pxeboot/hardware.nix new file mode 100644 index 0000000..6636fe4 --- /dev/null +++ b/pxeboot/hardware.nix @@ -0,0 +1,15 @@ +{ + config, + lib, + modulesPath, + ... +}: +{ + boot.initrd.network.enable = true; + fileSystems."/" = { + device = ""; + fsType = "nfs"; + }; + imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; +} diff --git a/server/configuration.nix b/server/configuration.nix index 245c4f7..c2165ea 100644 --- a/server/configuration.nix +++ b/server/configuration.nix @@ -1,7 +1,7 @@ { config, pkgs, ... }: { boot.kernelParams = [ "consoleblank=60" ]; imports = [ - ../common.nix + ../mods/host.nix ./hardware.nix ./mods/mail.nix ./mods/system.nix @@ -23,13 +23,7 @@ ipv4.addresses = "10.1.0.2/16"; ipv6.addresses = "fc01::2/64"; }; - wg-quick.interfaces.awg0 = { - address = [ - "10.0.0.2/32" - "fc00::2/128" - ]; - configFile = config.sops.templates.awg1-conf.path; - }; + wg-quick.interfaces.awg0.configFile = config.sops.templates.awg1-conf.path; }; security.acme = { acceptTerms = true; diff --git a/server/mods/web.nix b/server/mods/web.nix index d37b011..fc388f6 100644 --- a/server/mods/web.nix +++ b/server/mods/web.nix @@ -82,8 +82,10 @@ localNetworks = '' allow 10.0.0.0/16; allow 10.1.0.0/24; + allow 10.2.0.0/24; allow fc00::/64; allow fc01::/96; + allow fc02::/96; deny all; ''; phpPool = ''