Netboot: Difference between revisions

No edit summary
Kiesen (talk | contribs)
m Updated link from 23.11 to 24.11, as the old link is dead.
 
(2 intermediate revisions by 2 users not shown)
Line 65: Line 65:


=== Another example ===
=== Another example ===
File <code>netboot.nix</code>:
{{file|netboot.nix|nix|3={
<syntaxHighlight lang=nix copy>
  name ? "netboot",
{ name ? "netboot", arch ? "x86_64-linux"
  arch ? "x86_64-linux",
, configuration ? _: {} # --arg configuration 'import ./netboot-config.nix'
  configuration ? _: { }, # --arg configuration 'import ./netboot-config.nix'
, legacy ? false # variation with pxelinux and dnsmasq for older systems
  legacy ? false, # variation with pxelinux and dnsmasq for older systems
, cmdline ? []
  cmdline ? [ ],
, loglevel ? 4
  loglevel ? 4,
, pixiecoreport ? 64172
  pixiecoreport ? 64172,
, proxynets ? [ "192.168.0.0" ]
  proxynets ? [ "192.168.0.0" ],
, serialconsole ? false
  serialconsole ? false,
, serialport ? 0
  serialport ? 0,
, serialspeed ? 9600
  serialspeed ? 9600,
, nixpkgs ? import <nixpkgs> {}, ... }:
  nixpkgs ? import <nixpkgs> { },
with nixpkgs; with lib; let
  ...
}:
with nixpkgs;
with lib;
let


   example-configuration = {pkgs, config, ...}: with pkgs; {
   example-configuration =
    config = {
    { pkgs, config, ... }:
      environment.systemPackages = [
    with pkgs;
        mtr bridge-utils vlan ethtool jwhois sipcalc
    {
        netcat-openbsd tsocks psmisc pciutils usbutils
      config = {
        lm_sensors dmidecode microcom unar mkpasswd ripgrep
        environment.systemPackages = [
        wget rsync sshfs-fuse iperf3 mc mutt borgbackup
          mtr
        rxvt_unicode.terminfo
          bridge-utils
      ];
          vlan
      # users.users.nixos.openssh.authorizedKeys.keys = [ … ];
          ethtool
      # services.openssh = { ports = [2]; settings.PasswordAuthentication = false; };
          jwhois
      # virtualisation.lxc.enable = true;
          sipcalc
          netcat-openbsd
          tsocks
          psmisc
          pciutils
          usbutils
          lm_sensors
          dmidecode
          microcom
          unar
          mkpasswd
          ripgrep
          wget
          rsync
          sshfs-fuse
          iperf3
          mc
          mutt
          borgbackup
          rxvt_unicode.terminfo
        ];
        # users.users.nixos.openssh.authorizedKeys.keys = [ … ];
        # services.openssh = { ports = [2]; settings.PasswordAuthentication = false; };
        # virtualisation.lxc.enable = true;
      };
     };
     };
  };


   config = import <nixpkgs/nixos/lib/eval-config.nix> {
   config = import <nixpkgs/nixos/lib/eval-config.nix> {
Line 106: Line 133:
   };
   };


   version-module = { config, ... }: {
   version-module =
    system.stateVersion = config.system.nixos.version; # be quiet
    { config, ... }:
    system.nixos.tags = [ name ];
    {
  };
      system.stateVersion = config.system.nixos.version; # be quiet
      system.nixos.tags = [ name ];
    };


   run-pixiecore = writeShellScript "${name}-run-pixiecore" ''
   run-pixiecore = writeShellScript "${name}-run-pixiecore" ''
Line 125: Line 154:
   '';
   '';


   tftp-root = linkFarm "${name}-tftp-root"  
   tftp-root = linkFarm "${name}-tftp-root" (
     ( mapAttrsToList (name: path: { inherit name path; }) {
     mapAttrsToList (name: path: { inherit name path; }) {
       "pxelinux.cfg/default" = pxelinux-cfg;
       "pxelinux.cfg/default" = pxelinux-cfg;
       "pxelinux.0"           = "syslinux/pxelinux.0";
       "pxelinux.0" = "syslinux/pxelinux.0";
       "syslinux"             = "${syslinux}/share/syslinux";
       "syslinux" = "${syslinux}/share/syslinux";
       "bzImage"             = kernel;
       "bzImage" = kernel;
       "initrd"               = initrd;
       "initrd" = initrd;
     } );
     }
  );


   dnsmasq-conf = writeText "${name}-dnsmasq-conf" ''
   dnsmasq-conf = writeText "${name}-dnsmasq-conf" ''
Line 138: Line 168:
     local-service=net
     local-service=net
     dhcp-boot=pxelinux.0
     dhcp-boot=pxelinux.0
     ${ flip concatMapStrings proxynets (net: ''
     ${flip concatMapStrings proxynets (net: ''
       dhcp-range=${net},proxy
       dhcp-range=${net},proxy
     '')}
     '')}
Line 149: Line 179:
   '';
   '';


   cmd-line = concatStringsSep " "
   cmd-line = concatStringsSep " " (
     ([ "init=${build.toplevel}/init" "loglevel=${toString loglevel}" ]
     [
     ++ optional serialconsole
      "init=${build.toplevel}/init"
      "console=ttyS${toString serialport},${toString serialspeed}"
      "loglevel=${toString loglevel}"
     ++ cmdline );
    ]
     ++ optional serialconsole "console=ttyS${toString serialport},${toString serialspeed}"
     ++ cmdline
  );


   pxelinux-cfg = writeText "${name}-pxelinux.cfg" ''
   pxelinux-cfg = writeText "${name}-pxelinux.cfg" ''
     ${ optionalString serialconsole
     ${optionalString serialconsole "serial ${toString serialport} ${toString serialspeed}"}
      "serial ${toString serialport} ${toString serialspeed}" }
     console 1
     console 1
     prompt 1
     prompt 1
Line 172: Line 204:
   initrd = "${build.netbootRamdisk}/initrd";
   initrd = "${build.netbootRamdisk}/initrd";


in if legacy then run-dnsmasq else run-pixiecore
in
</syntaxHighlight>
if legacy then run-dnsmasq else run-pixiecore}}


Usage example:
Usage example:
Line 192: Line 224:


=== See also ===
=== See also ===
NixOS: [https://search.nixos.org/options?channel=23.11&from=0&size=30&sort=relevance&type=packages&query=services.pixiecore Pixiecore module].
NixOS: [https://search.nixos.org/options?channel=24.11&from=0&size=30&sort=relevance&type=packages&query=services.pixiecore Pixiecore module].


NixOS manual: [https://nixos.org/nixos/manual/index.html#sec-booting-from-pxe PXE booting].
NixOS manual: [https://nixos.org/nixos/manual/index.html#sec-booting-from-pxe PXE booting].