pxeboot with nixos host configured and tested

This commit is contained in:
bogale 2026-10-28 00:27:53 +09:00
commit 2d4cf0b147
9 changed files with 268 additions and 89 deletions

View file

@ -1,10 +1,16 @@
{ config, pkgs, ... }: { {
config,
lib,
modulesPath,
pkgs,
...
}:
{
boot = { boot = {
kernelPackages = pkgs.linuxPackages_latest; kernelPackages = pkgs.linuxPackages_latest;
loader.limine = { loader.limine = {
enable = true; enable = true;
panicOnChecksumMismatch = true; panicOnChecksumMismatch = true;
secureBoot.enable = true;
}; };
zswap = { zswap = {
enable = true; enable = true;
@ -25,25 +31,14 @@
speedtest-go speedtest-go
]; ];
i18n.defaultLocale = "ru_RU.UTF-8"; i18n.defaultLocale = "ru_RU.UTF-8";
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
networking.networkmanager.enable = true; networking.networkmanager.enable = true;
nix.settings.experimental-features = [ nix.settings.experimental-features = [
"flakes" "flakes"
"nix-command" "nix-command"
]; ];
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
services.swapspace.enable = true; services.swapspace.enable = true;
sops = {
age.keyFile = "/var/lib/sops-nix/key.txt";
defaultSopsFile = ./.secrets.yaml;
secrets.root-passwd = { };
};
system.stateVersion = "26.11"; system.stateVersion = "26.11";
systemd.tmpfiles.rules = [
"L /root/backup/base/nixos - - - - /etc/nixos"
"L /root/backup/base/sbctl - - - - /var/lib/sbctl"
"L /root/backup/base/sops-nix - - - - /var/lib/sops-nix"
"d /root/backup"
"d /root/backup/base"
];
time.timeZone = "Asia/Chita"; time.timeZone = "Asia/Chita";
users.users.root.hashedPasswordFile = config.sops.secrets.root-passwd.path;
} }

View file

@ -1,10 +1,4 @@
{ { config, lib, ... }: {
config,
lib,
modulesPath,
...
}:
{
boot = { boot = {
initrd = { initrd = {
availableKernelModules = [ availableKernelModules = [
@ -34,8 +28,6 @@
}; };
}; };
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
swapDevices = [ swapDevices = [
{ {
device = "/var/lib/swapfile"; device = "/var/lib/swapfile";

View file

@ -38,12 +38,7 @@
sops-nix.nixosModules.sops sops-nix.nixosModules.sops
]; ];
}; };
nixos-pxeboot = nixpkgs.lib.nixosSystem { nixos-pxeboot = nixpkgs.lib.nixosSystem { modules = [ ./pxeboot/configuration.nix ]; };
modules = [
./pxeboot/configuration.nix
sops-nix.nixosModules.sops
];
};
nixos-server = nixpkgs.lib.nixosSystem { nixos-server = nixpkgs.lib.nixosSystem {
modules = [ modules = [
./server/configuration.nix ./server/configuration.nix

View file

@ -2,6 +2,7 @@
boot = { boot = {
extraModulePackages = [ config.boot.kernelPackages.amneziawg ]; extraModulePackages = [ config.boot.kernelPackages.amneziawg ];
kernelModules = [ "amneziawg" ]; kernelModules = [ "amneziawg" ];
loader.limine.secureBoot.enable = true;
}; };
fileSystems = { fileSystems = {
"/".options = [ "noatime" ]; "/".options = [ "noatime" ];
@ -55,8 +56,20 @@
]; ];
}; };
}; };
sops.secrets = { sops = {
age.keyFile = "/var/lib/sops-nix/key.txt";
defaultSopsFile = ../.secrets.yaml;
secrets = {
awg-obf = { }; awg-obf = { };
root-passwd = { };
wifi-env = { }; wifi-env = { };
}; };
};
systemd.tmpfiles.rules = [
"L /root/backup/base/nixos - - - - /etc/nixos"
"L /root/backup/base/sbctl - - - - /var/lib/sbctl"
"L /root/backup/base/sops-nix - - - - /var/lib/sops-nix"
"d /root/backup/base"
];
users.users.root.hashedPasswordFile = config.sops.secrets.root-passwd.path;
} }

View file

@ -19,12 +19,21 @@
internalInterfaces = [ "br0" ]; internalInterfaces = [ "br0" ];
}; };
networkmanager.ensureProfiles.profiles = { networkmanager.ensureProfiles.profiles = {
dhcp-bridge = {
bridge.stp = false;
connection = {
id = "dhcp-bridge";
interface-name = "br0";
type = "bridge";
};
};
slave-ethernet.connection = { slave-ethernet.connection = {
controller = "br0"; controller = "br0";
id = "slave-ethernet"; id = "slave-ethernet";
type = "ethernet"; type = "ethernet";
}; };
static-bridge = { static-bridge = {
bridge.stp = false;
connection = { connection = {
id = "static-bridge"; id = "static-bridge";
interface-name = "br0"; interface-name = "br0";
@ -39,17 +48,12 @@
method = "manual"; method = "manual";
}; };
}; };
dhcp-bridge.connection = {
id = "dhcp-bridge";
interface-name = "br0";
type = "bridge";
};
}; };
}; };
services = { services = {
dnsmasq.settings = { dnsmasq.settings = {
bind-interfaces = true; bind-interfaces = true;
dhcp-boot = "grubx64.efi"; dhcp-boot = "efi/boot/BOOTX64.EFI";
dhcp-range = [ dhcp-range = [
"10.2.0.2,10.2.255.254,12h" "10.2.0.2,10.2.255.254,12h"
"fc02::2,fc02::ffff:ffff:ffff:ffff,12h" "fc02::2,fc02::ffff:ffff:ffff:ffff,12h"
@ -57,12 +61,12 @@
enable-ra = true; enable-ra = true;
enable-tftp = true; enable-tftp = true;
interface = "br0"; interface = "br0";
tftp-root = "/srv/tftp"; tftp-root = "/srv/pxe/nixos/boot";
}; };
nfs.server = { nfs.server = {
enable = true; enable = true;
exports."/srv/nfs/root"."10.2.0.0/16" = [ exports."/srv/pxe/export"."10.2.0.0/16" = [
"mp" "fsid=0"
"no_root_squash" "no_root_squash"
"rw" "rw"
]; ];
@ -70,31 +74,22 @@
}; };
systemd = { systemd = {
services.pxeboot = { services.pxeboot = {
before = [ "nfs-server.service" ];
path = with pkgs; [ path = with pkgs; [
curl nix
grub2_efi nixos-install
xz util-linux
]; ];
#requiredBy = [ "nfs-server.service" ];
script = '' script = ''
if [ ! -e /srv/nfs/nixos ]; then (printf '{\n boot.initrd.availableKernelModules = [\n'
mkdir -p /srv/nfs/nixos cd ${config.boot.kernelPackages.kernel.modules}/lib/modules/*/kernel/drivers/net/ethernet
until curl --head --max-time 3 https://bogaledev.ru; do sleep 5; done find -type f | sed 's/^.*\/\([^.]*\).*$/ "\1"/' | sort
# nixos-install ... printf ' ];\n}') > /etc/nixos/pxeboot/ethernet.nix
# extract initramfs, linux cd /srv/pxe
fi nixos-install --flake "/etc/nixos#nixos-pxeboot" \
cd /srv/tftp --no-channel-copy --no-root-passwd --root $PWD/nixos
if [ ! -e grubx64.efi ]; then mountpoint -q export || mount -B --mkdir nixos export
grub-mkstandalone -O x86_64-efi --compress=xz -o grubx64.efi \
--modules=efinet /boot/grub/grub.cfg=<(cat <<' EOF'
linux $cmdpath/linux rw ip=dhcp root=nfs4:$net_default_server:/srv/nfs/root
initrd $cmdpath/initramfs
boot
EOF)
fi
''; '';
}; };
tmpfiles.rules = [ "d /srv/tftp" ]; tmpfiles.rules = [ "d /srv/pxe/nixos/boot" ];
}; };
} }

View file

@ -1,7 +1,21 @@
{ config, pkgs, ... }: { { pkgs, ... }: {
boot = {
initrd = {
availableKernelModules = [ "nfsv4" ];
network.enable = true;
systemd.initrdBin = [ pkgs.nfs-utils ];
};
kernelParams = [ "ip=dhcp" ];
};
fileSystems."/" = {
device = "10.2.0.1:/";
fsType = "nfs4";
};
hardware.enableAllHardware = true;
imports = [ imports = [
../common.nix ../common.nix
./hardware.nix ./ethernet.nix
]; ];
networking.hostName = "nixos-pxeboot"; networking.hostName = "nixos-pxeboot";
services.getty.autologinUser = "root";
} }

198
pxeboot/ethernet.nix Normal file
View file

@ -0,0 +1,198 @@
{
boot.initrd.availableKernelModules = [
"3c59x"
"8139cp"
"8139too"
"8390"
"adin1110"
"adin1140"
"altera_tse"
"alx"
"amd8111e"
"amd-xgbe"
"atl1"
"atl1c"
"atl1e"
"atl2"
"atlantic"
"ax88796c"
"b44"
"bcmsysport"
"be2net"
"bna"
"bng_en"
"bnx2"
"bnx2x"
"bnxt_en"
"cassini"
"cavium_ptp"
"ch_ipsec"
"ch_ktls"
"cnic"
"cxgb"
"cxgb3"
"cxgb4"
"cxgb4vf"
"de2104x"
"dinghai10e"
"dl2k"
"dmfe"
"dwc-xlgmac"
"dwmac-dwc-qos-eth"
"dwmac-generic"
"dwmac-intel"
"dwmac-intel-plat"
"dwmac-motorcomm"
"e100"
"e1000"
"e1000e"
"ec_bhf"
"eea"
"ena"
"enc28j60"
"encx24j600"
"encx24j600-regmap"
"enic"
"epic100"
"et131x"
"ethoc"
"fbnic"
"fealnx"
"fm10k"
"forcedeth"
"funcore"
"funeth"
"gemini"
"genet"
"gve"
"hibmcge"
"hinic"
"hinic3"
"i40e"
"iavf"
"ice"
"idpf"
"igb"
"igbvf"
"igc"
"ionic"
"ixd"
"ixgbe"
"ixgbevf"
"jme"
"ks8842"
"ks8851_common"
"ks8851_par"
"ks8851_spi"
"ksz884x"
"lan743x"
"lan865x"
"lan966x-switch"
"libcxgb"
"libeth"
"libeth_xdp"
"libie"
"libie_adminq"
"libie_cp"
"libie_fwlog"
"libie_pci"
"libwx"
"liquidio"
"liquidio-core"
"liquidio_vf"
"litex_liteeth"
"ll_temac"
"macb"
"macb_pci"
"mana"
"mlx4_core"
"mlx4_en"
"mlx5_core"
"mlx5_dpll"
"mlxfw"
"mlxsw_core"
"mlxsw_i2c"
"mlxsw_minimal"
"mlxsw_pci"
"mlxsw_spectrum"
"mscc_ocelot"
"mscc_ocelot_switch_lib"
"mse102x"
"mvmdio"
"myri10ge"
"natsemi"
"ne2k-pci"
"netxen_nic"
"nfp"
"ngbe"
"ngbevf"
"nicpf"
"nicvf"
"niu"
"nixge"
"nps_enet"
"ns83820"
"oa_tc6"
"octeon_ep"
"octeon_ep_vf"
"pcnet32"
"pcnet_cs"
"pds_core"
"prestera"
"prestera_pci"
"qca_7k_common"
"qcaspi"
"qcauart"
"qcom-emac"
"qed"
"qede"
"qla3xxx"
"qlcnic"
"r6040"
"r8169"
"rmnet"
"rnpgbe"
"rocker"
"rtase"
"samsung-sxgbe"
"sc92031"
"sfc"
"sfc-falcon"
"sfc-siena"
"sis190"
"sis900"
"skge"
"sky2"
"slicoss"
"smsc911x"
"smsc9420"
"starfire"
"stmmac"
"stmmac_libpci"
"stmmac-pci"
"stmmac-platform"
"sundance"
"sungem"
"sunhme"
"tehuti"
"tg3"
"thunder_bgx"
"thunder_xcv"
"tlan"
"tn40xx"
"tsnep"
"tulip"
"txgbe"
"txgbevf"
"typhoon"
"uli526x"
"via-rhine"
"via-velocity"
"w5100"
"w5100-spi"
"winbond-840"
"xilinx_emac"
"xilinx_emaclite"
"xirc2ps_cs"
];
}

View file

@ -1,15 +0,0 @@
{
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";
}

View file

@ -1,10 +1,4 @@
{ { config, lib, ... }: {
config,
lib,
modulesPath,
...
}:
{
boot = { boot = {
initrd = { initrd = {
availableKernelModules = [ availableKernelModules = [
@ -36,6 +30,4 @@
}; };
}; };
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
} }