From 9c0e1c011a3b6916ac9cb50132578fd6d8b3914a Mon Sep 17 00:00:00 2001 From: bogale Date: Wed, 28 Oct 2026 13:28:36 +0900 Subject: [PATCH] bootable targets: drive, pxe --- bootable/common.nix | 9 +++ bootable/drive.nix | 12 ++++ {pxeboot => bootable}/ethernet.nix | 2 +- pxeboot/configuration.nix => bootable/pxe.nix | 6 +- desktop/hardware.nix | 15 +---- flake.nix | 3 +- install.sh | 13 ++--- mods/fs.nix | 15 +++++ mods/host.nix | 6 +- mods/pxeboot.nix | 56 +++++++++++++------ server/hardware.nix | 15 +---- 11 files changed, 88 insertions(+), 64 deletions(-) create mode 100644 bootable/common.nix create mode 100644 bootable/drive.nix rename {pxeboot => bootable}/ethernet.nix (99%) rename pxeboot/configuration.nix => bootable/pxe.nix (70%) create mode 100644 mods/fs.nix diff --git a/bootable/common.nix b/bootable/common.nix new file mode 100644 index 0000000..96281ef --- /dev/null +++ b/bootable/common.nix @@ -0,0 +1,9 @@ +{ + boot = { + initrd.systemd.tpm2.enable = false; + loader.timeout = 0; + }; + imports = [ ../common.nix ]; + services.getty.autologinUser = "root"; + systemd.tpm2.enable = false; +} diff --git a/bootable/drive.nix b/bootable/drive.nix new file mode 100644 index 0000000..9594aee --- /dev/null +++ b/bootable/drive.nix @@ -0,0 +1,12 @@ +{ + fileSystems = { + "/".device = "/dev/disk/by-label/bootdrive-root"; + "/boot".device = "/dev/disk/by-label/bootdrive-esp"; + }; + hardware.enableAllHardware = true; + imports = [ + ../mods/fs.nix + ./common.nix + ]; + networking.hostName = "nixos-bootdrive"; +} diff --git a/pxeboot/ethernet.nix b/bootable/ethernet.nix similarity index 99% rename from pxeboot/ethernet.nix rename to bootable/ethernet.nix index eea6597..79805b0 100644 --- a/pxeboot/ethernet.nix +++ b/bootable/ethernet.nix @@ -195,4 +195,4 @@ "xilinx_emaclite" "xirc2ps_cs" ]; -} \ No newline at end of file +} diff --git a/pxeboot/configuration.nix b/bootable/pxe.nix similarity index 70% rename from pxeboot/configuration.nix rename to bootable/pxe.nix index e74b4c1..4f0cb80 100644 --- a/pxeboot/configuration.nix +++ b/bootable/pxe.nix @@ -11,11 +11,9 @@ device = "10.2.0.1:/"; fsType = "nfs4"; }; - hardware.enableAllHardware = true; imports = [ - ../common.nix + ./common.nix ./ethernet.nix ]; - networking.hostName = "nixos-pxeboot"; - services.getty.autologinUser = "root"; + networking.hostName = "nixos-bootpxe"; } diff --git a/desktop/hardware.nix b/desktop/hardware.nix index 871a9bd..55b58f6 100644 --- a/desktop/hardware.nix +++ b/desktop/hardware.nix @@ -13,20 +13,7 @@ kernelModules = [ "kvm-amd" ]; kernelParams = [ "ttm.pages_limit=3014656" ]; }; - fileSystems = { - "/" = { - device = "/dev/mapper/root"; - fsType = "ext4"; - }; - "/boot" = { - device = "/dev/disk/by-uuid/2610-A769"; - fsType = "vfat"; - options = [ - "dmask=0077" - "fmask=0077" - ]; - }; - }; + fileSystems."/boot".device = "/dev/disk/by-uuid/2610-A769"; hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; swapDevices = [ { diff --git a/flake.nix b/flake.nix index ca8b842..3a00ff4 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,8 @@ { formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-tree; nixosConfigurations = { + nixos-bootdrive = nixpkgs.lib.nixosSystem { modules = [ ./bootable/drive.nix ]; }; + nixos-bootpxe = nixpkgs.lib.nixosSystem { modules = [ ./bootable/pxe.nix ]; }; nixos-desktop = nixpkgs.lib.nixosSystem { modules = [ ./desktop/configuration.nix @@ -38,7 +40,6 @@ sops-nix.nixosModules.sops ]; }; - nixos-pxeboot = nixpkgs.lib.nixosSystem { modules = [ ./pxeboot/configuration.nix ]; }; nixos-server = nixpkgs.lib.nixosSystem { modules = [ ./server/configuration.nix diff --git a/install.sh b/install.sh index aadf487..f2ff17c 100644 --- a/install.sh +++ b/install.sh @@ -1,15 +1,12 @@ gdisk $DISK -mkfs.fat -F 32 $ESPPART +mkfs.fat -F 32 -n $HOST-esp $ESPPART cryptsetup luksFormat $ROOTPART cryptsetup open $ROOTPART root -mkfs.ext4 /dev/mapper/root +mkfs.ext4 -L $HOST-root /dev/mapper/root mount /dev/mapper/root /mnt -mount $ESPPART --mkdir -o umask=077 /mnt/boot -mkdir -p /mnt/var/lib -mkswap -F -s $SWAPSIZE /mnt/var/swapfile -swapon /mnt/var/swapfile +mount --mkdir $ESPPART /mnt/boot +mkdir -p /mnt/var/lib # restore backup -nixos-generate-config --root /mnt --show-hardware-config > /mnt/etc/nixos/$HOSTNAME/hardware.nix -nixos-install --no-root-passwd --no-channel-copy --flake "/mnt/etc/nixos#nixos-$HOSTNAME" +nixos-install --no-root-passwd --no-channel-copy --flake "/mnt/etc/nixos#nixos-$HOST" sbctl enroll-keys --yolo systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=0+2+7 $ROOTPART diff --git a/mods/fs.nix b/mods/fs.nix new file mode 100644 index 0000000..fdb0eda --- /dev/null +++ b/mods/fs.nix @@ -0,0 +1,15 @@ +{ + fileSystems = { + "/" = { + fsType = "ext4"; + options = [ "noatime" ]; + }; + "/boot" = { + fsType = "vfat"; + options = [ + "noatime" + "umask=0077" + ]; + }; + }; +} diff --git a/mods/host.nix b/mods/host.nix index dde7ca0..982f920 100644 --- a/mods/host.nix +++ b/mods/host.nix @@ -4,12 +4,10 @@ kernelModules = [ "amneziawg" ]; loader.limine.secureBoot.enable = true; }; - fileSystems = { - "/".options = [ "noatime" ]; - "/boot".options = [ "noatime" ]; - }; + fileSystems."/".device = "/dev/mapper/root"; imports = [ ../common.nix + ./fs.nix ./pxeboot.nix ./vps-init.nix ]; diff --git a/mods/pxeboot.nix b/mods/pxeboot.nix index 8d35d4e..f55be9c 100644 --- a/mods/pxeboot.nix +++ b/mods/pxeboot.nix @@ -1,5 +1,4 @@ { config, pkgs, ... }: { - environment.systemPackages = [ pkgs.grub2_efi ]; networking = { firewall = { allowedTCPPorts = [ @@ -30,6 +29,7 @@ slave-ethernet.connection = { controller = "br0"; id = "slave-ethernet"; + port-type = "bridge"; type = "ethernet"; }; static-bridge = { @@ -52,7 +52,7 @@ }; services = { dnsmasq.settings = { - bind-interfaces = true; + bind-dynamic = true; dhcp-boot = "efi/boot/BOOTX64.EFI"; dhcp-range = [ "10.2.0.2,10.2.255.254,12h" @@ -73,22 +73,42 @@ }; }; systemd = { - services.pxeboot = { - path = with pkgs; [ - nix - nixos-install - util-linux - ]; - script = '' - (printf '{\n boot.initrd.availableKernelModules = [\n' - cd ${config.boot.kernelPackages.kernel.modules}/lib/modules/*/kernel/drivers/net/ethernet - find -type f | sed 's/^.*\/\([^.]*\).*$/ "\1"/' | sort - printf ' ];\n}') > /etc/nixos/pxeboot/ethernet.nix - cd /srv/pxe - nixos-install --flake "/etc/nixos#nixos-pxeboot" \ - --no-channel-copy --no-root-passwd --root $PWD/nixos - mountpoint -q export || mount -B --mkdir nixos export - ''; + services = { + pxeboot = { + before = [ "nfs-server.service" ]; + path = [ pkgs.util-linux ]; + preStop = '' + cd /srv/pxe + mountpoint -q export && umount export + ''; + requiredBy = [ "nfs-server.service" ]; + script = '' + cd /srv/pxe + if [ ! -e export ]; then + systemctl start pxeboot-install + fi + mountpoint -q export || mount -B --mkdir nixos export + ''; + serviceConfig = { + RemainAfterExit = true; + Type = "oneshot"; + }; + }; + pxeboot-install = { + path = with pkgs; [ + nix + nixos-install + ]; + script = '' + (printf '{\n boot.initrd.availableKernelModules = [\n' + cd ${config.boot.kernelPackages.kernel.modules}/lib/modules/*/kernel/drivers/net/ethernet + find -type f | sed 's/^.*\/\([^.]*\).*$/ "\1"/' | sort + printf ' ];\n}') > /etc/nixos/pxeboot/ethernet.nix + nixos-install --flake "/etc/nixos#nixos-pxeboot" \ + --no-channel-copy --no-root-passwd --root /srv/pxe/nixos + ''; + # delete --no-channel-copy later + }; }; tmpfiles.rules = [ "d /srv/pxe/nixos/boot" ]; }; diff --git a/server/hardware.nix b/server/hardware.nix index 0ed6311..fdda095 100644 --- a/server/hardware.nix +++ b/server/hardware.nix @@ -15,19 +15,6 @@ "memmap=0x4000%0xbfb7a000-4" ]; }; - fileSystems = { - "/" = { - device = "/dev/mapper/root"; - fsType = "ext4"; - }; - "/boot" = { - device = "/dev/disk/by-uuid/86F4-A8F1"; - fsType = "vfat"; - options = [ - "dmask=0077" - "fmask=0077" - ]; - }; - }; + fileSystems."/boot".device = "/dev/disk/by-uuid/86F4-A8F1"; hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; }