From f0adb4dccc25a7d7a06d5a6a47524acbdfc4a2ef Mon Sep 17 00:00:00 2001 From: arcnmx Date: Thu, 21 Nov 2024 16:25:20 -0800 Subject: [PATCH] fix(mugetsu): partial netboot install --- nixos/hw/c4130.nix | 39 +++++++++ nixos/hw/metal.nix | 11 +++ nixos/netboot/kyuuto.nix | 92 ++++++++++++++++++++++ systems/mugetsu/hardware-configuration.nix | 29 +++---- systems/mugetsu/nixos.nix | 1 + 5 files changed, 152 insertions(+), 20 deletions(-) create mode 100644 nixos/hw/c4130.nix create mode 100644 nixos/hw/metal.nix create mode 100644 nixos/netboot/kyuuto.nix diff --git a/nixos/hw/c4130.nix b/nixos/hw/c4130.nix new file mode 100644 index 00000000..94dbb01b --- /dev/null +++ b/nixos/hw/c4130.nix @@ -0,0 +1,39 @@ +{ + pkgs, + config, + lib, + ... +}: let + inherit (lib.modules) mkIf mkMerge mkDefault; +in { + imports = [ + ./metal.nix + ]; + + boot = { + loader = { + systemd-boot.enable = mkDefault true; + }; + initrd = { + systemd.network = mkIf config.networking.useNetworkd { + networks."40-eno1" = { + inherit (config.boot.initrd.systemd.network.links.eno1) matchConfig; + inherit (config.systemd.network.networks."40-eno1") address gateway DHCP networkConfig linkConfig; + }; + links.eno1 = { + matchConfig = { + inherit (config.systemd.network.links.eno1.matchConfig) Type MACAddress; + }; + }; + }; + availableKernelModules = mkMerge [ + ["ahci" "xhci_pci" "ehci_pci" "usbhid" "usb_storage" "sd_mod" "sr_mod"] + (mkIf config.boot.initrd.network.enable ["igb"]) + ]; + }; + }; + + environment.systemPackages = [ + pkgs.ipmitool + ]; +} diff --git a/nixos/hw/metal.nix b/nixos/hw/metal.nix new file mode 100644 index 00000000..ab87c23e --- /dev/null +++ b/nixos/hw/metal.nix @@ -0,0 +1,11 @@ +{ + pkgs, + config, + lib, + ... +}: { + environment.systemPackages = [ + pkgs.pciutils + pkgs.usbutils + ]; +} diff --git a/nixos/netboot/kyuuto.nix b/nixos/netboot/kyuuto.nix new file mode 100644 index 00000000..f9a71bbf --- /dev/null +++ b/nixos/netboot/kyuuto.nix @@ -0,0 +1,92 @@ +{ + config, + systemConfig, + access, + pkgs, + lib, + ... +}: let + inherit (lib.options) mkOption mkEnableOption mkPackageOption; + inherit (lib.modules) mkIf mkDefault mkMerge; + cfg = config.gensokyo-zone.netboot; + nfsEnabled = config.boot.initrd.supportedFilesystems.nfs or config.boot.initrd.supportedFilesystems.nfs4 or false; +in { + options.gensokyo-zone.netboot = with lib.types; { + # TODO: default = true; + boot.enable = mkEnableOption "nfs /boot"; + nfs = { + package = mkPackageOption pkgs "nfs-utils" { + example = "pkgs.mkinitcpio-nfs-utils"; + }; + security = mkOption { + type = str; + default = "sys"; + }; + flags = mkOption { + type = listOf str; + default = [ + "nolock" # required in order to mount in initrd when statd daemon isn't running + ]; + }; + }; + }; + config = { + boot = { + initrd = { + network = { + enable = mkDefault true; + ssh = { + # TODO: enable = true; + }; + }; + availableKernelModules = mkIf nfsEnabled [ + "nfsv4" "nfsv3" + ]; + extraUtilsCommands = mkIf (nfsEnabled && !config.boot.initrd.systemd.enable) '' + copy_bin_and_libs ${cfg.nfs.package}/sbin/mount.nfs + ''; + systemd = { + enable = mkDefault true; + emergencyAccess = mkDefault true; + initrdBin = mkMerge [ + (mkIf nfsEnabled [cfg.nfs.package]) + (mkIf config.boot.initrd.network.enable [ + pkgs.iproute2 + ]) + [ pkgs.util-linux pkgs.gnugrep ] + ]; + network = mkIf config.networking.useNetworkd { + enable = mkDefault true; + }; + }; + }; + loader = { + systemd-boot.enable = true; + efi.canTouchEfiVariables = false; + }; + }; + fileSystems = let + nfsUrl = access.proxyUrlFor { + serviceName = "nfs"; + scheme = ""; + defaultPort = 2049; + # XXX: consider using dns hostname here instead? (does this require the dns_resolver kernel module?) + getAddressFor = "getAddress4For"; + } + ":/srv/fs/kyuuto/systems/${systemConfig.name}"; + nfsOpts = [ + "sec=${cfg.nfs.security}" + ] ++ cfg.nfs.flags; + in { + "/" = { + device = "${nfsUrl}/root"; + fsType = "nfs"; + options = nfsOpts; + }; + "/boot" = mkIf cfg.boot.enable { + device = "${nfsUrl}/boot"; + fsType = "nfs"; + options = nfsOpts; + }; + }; + }; +} diff --git a/systems/mugetsu/hardware-configuration.nix b/systems/mugetsu/hardware-configuration.nix index 0b38e62d..259b7038 100644 --- a/systems/mugetsu/hardware-configuration.nix +++ b/systems/mugetsu/hardware-configuration.nix @@ -1,30 +1,19 @@ { + meta, config, - pkgs, ... }: { - environment.systemPackages = [ - pkgs.ipmitool + imports = let + inherit (meta) nixos; + in [ + nixos.hw.c4130 ]; - boot = { - initrd = { - availableKernelModules = ["ahci" "xhci_pci" "ehci_pci" "usbhid" "usb_storage" "sd_mod" "sr_mod"]; - kernelModules = []; - }; - kernelModules = []; - extraModulePackages = []; - loader = { - systemd-boot.enable = true; - efi.canTouchEfiVariables = true; - }; - }; - fileSystems = { - "/" = { - # TODO - device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888"; - fsType = "xfs"; + "/boot" = { + device = "/dev/disk/by-label/EFI"; + fsType = "vfat"; + options = ["fmask=0077" "dmask=0077"]; }; }; diff --git a/systems/mugetsu/nixos.nix b/systems/mugetsu/nixos.nix index b016ae43..c5084b9c 100644 --- a/systems/mugetsu/nixos.nix +++ b/systems/mugetsu/nixos.nix @@ -8,6 +8,7 @@ ./hardware-configuration.nix #nixos.sops nixos.base + nixos.netboot.kyuuto ]; system.stateVersion = "24.11";