danderson / netboot

Packages and utilities for network booting
Apache License 2.0
1.47k stars 181 forks source link

Netboot with NixOS #136

Open gianarb opened 1 year ago

gianarb commented 1 year ago

Hello! Awesome project. Simple and it does what it should I love it!

TLDR: I am not sure about how to glue all of this together in a good way

I am writing this question because I think you are faimiliar with NixOS. I am following this guide to netboot a NixOS based operating system

https://nixos.wiki/wiki/Netboot

It generates a ipxe script file that contains the init cmdline

$ cat result/netboot.ipxe
#!ipxe
# Use the cmdline variable to allow the user to specify custom kernel params
# when chainloading this script from other iPXE scripts like netboot.xyz
kernel bzImage init=/nix/store/wc9fvfyhv649b4kxry5747rx5rw88v68-nixos-system-nixos-22.05.20220902.67e4507/init initrd=initrd loglevel=4 ${cmdline}
initrd initrd
boot

I am trying to figure out a way to teach pixiecore about this file or at least about the init location, ideally via services.pixiecore.cmdLine

blazp7 commented 4 months ago

I know this question is ancient, but for anyone wondering, this is what worked for me, taken from https://carjorvaz.com/posts/ipxe-booting-with-nixos

{inputs, ...}: let
  sys = inputs.nixpkgs.lib.nixosSystem {
    system = "x86_64-linux";
    modules = [
      ({
        config,
        pkgs,
        lib,
        modulesPath,
        ...
      }: {
        imports = [
          (modulesPath + "/installer/netboot/netboot-minimal.nix")
        ];
        config = {
          # custom installer configuration, most stuff is already configured by the imported module (it includes installation-device profile)
          users.users.root.initialPassword = lib.mkForce "pass123";
          users.users.nixos.initialPassword = lib.mkForce "pass123";
        };
      })
    ];
  };
  build = sys.config.system.build;
in {
  services.pixiecore = {
    enable = true;
    openFirewall = true;
    dhcpNoBind = true; # use existing DHCP server
    port = 64172;
    statusPort = 64172;

    mode = "boot";
    kernel = "${build.kernel}/bzImage";
    initrd = "${build.netbootRamdisk}/initrd";
    cmdLine = "init=${build.toplevel}/init loglevel=4";
    debug = true;
  };
}