From 8c4c8b3cccf0ca41cd6f4f466d858ba5c32d4d0d Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Sat, 30 Jan 2021 15:40:33 +0000 Subject: [PATCH] ops/nixos: add netboot for netbooting a basic system with my defaults --- ops/nixos/default.nix | 4 ++++ ops/nixos/netboot/default.nix | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 ops/nixos/netboot/default.nix diff --git a/ops/nixos/default.nix b/ops/nixos/default.nix index 71ebd59950..b3b21eedfe 100644 --- a/ops/nixos/default.nix +++ b/ops/nixos/default.nix @@ -52,8 +52,12 @@ let stockExporters ++ customExporters; in builtins.listToAttrs (builtins.concatLists (lib.mapAttrsToList exportersForSystem evaledSystems)); + + netbootSystem = systemFor "netboot" (import ./netboot); in systemDrvs // { systems = systemDrvs; systemExporters = systemExporters; tailscaleIPs = systemTailscaleIPs; + + netboot = netbootSystem.config.system.build.pixiecore; } diff --git a/ops/nixos/netboot/default.nix b/ops/nixos/netboot/default.nix new file mode 100644 index 0000000000..4410cad05c --- /dev/null +++ b/ops/nixos/netboot/default.nix @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2020 Luke Granger-Brown +# +# SPDX-License-Identifier: Apache-2.0 + +{ depot, lib, pkgs, rebuilder, config, ... }: +let + inherit (depot.ops) secrets; +in { + imports = [ + ../../../third_party/nixpkgs/nixos/modules/installer/netboot/netboot-minimal.nix + ]; + + environment.noXlibs = false; + services.getty.autologinUser = lib.mkForce "root"; + systemd.services.sshd.wantedBy = lib.mkOverride 0 [ "multi-user.target" ]; + boot.kernelPackages = pkgs.linuxPackages_latest; + + system.build.netbootWrap = pkgs.symlinkJoin { + name = "netboot"; + paths = with config.system.build; [ + netbootRamdisk + kernel + netbootIpxeScript + ]; + }; + system.build.pixiecore = pkgs.writeScript "netboot-pixiecore.sh" '' + n="$(realpath ${config.system.build.netbootWrap})" + init="$(grep -ohP 'init=\S+' "$n/netboot.ipxe")" + pixiecore="${pkgs.pixiecore}" + + exec "$pixiecore/bin/pixiecore" \ + boot "$n/bzImage" "$n/initrd" \ + --cmdline "$init loglevel=4" \ + --debug --dhcp-no-bind --port 64172 --status-port 64172 + ''; + + system.stateVersion = "21.05"; +}