summaryrefslogtreecommitdiff
path: root/pkgs/ipxe/default.nix
blob: 390a27120c533284eee400442e8c7775b036c3ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{
  ipxe,
  lib,
  writeText,
  stage2-url ? "http://[fe80::b007:b007]/\${netX/mac}/stage2.ipxe",
}: {
  minimal = ipxe.override {
    embedScript = "..."; # TODO
    pname = "ipxe-minimal";
    enabledOptions = [];

    preConfigure = ''
      sed -i \
        '/^#define\s\+\<[A-Z0-9_]\+\>\s*\(\/\*.*\*\/\)\?$/ { /CONFIG_GENERAL_H/! { s/^/\/\// } }' \
        src/config/general.h
    '';
  };

  with-script =
    (ipxe.override {
      embedScript = writeText "ipxe-shim-script" ''
        #!ipxe
        echo stage1: chainloading from ${stage2-url}...
        ifconf --configurator ipv6 --timeout 1000 || goto try-v4
        goto try-boot
        :try-v4
        echo stage1: failed to bring IPv6 up, trying DHCP...
        ifconf --configurator dhcp --timeout 1000 || goto fail
        :try-boot
        isset ''${netX/gateway}  && isset ''${syslog}  || set syslog  ''${netX/gateway}
        isset ''${netX/gateway6} && isset ''${syslog6} || set syslog6 ''${netX/gateway6}
        show syslog
        show syslog6
        echo stage1: network up
        route ||
        chain --timeout 10000 --replace ${stage2-url} ||
        :fail
        echo stage1: failed, rebooting in 5s...
        sleep 5
        reboot --warm
      '';
    }).overrideAttrs (finalAtrs: prevAttrs: {
      pname = "ipxe-with-embedded-script";
      enabledOptions = [
        "DOWNLOAD_PROTO_HTTP"
        "NET_PROTO_IPV4"
        "NET_PROTO_IPV6"
        "REBOOT_CMD"
      ];

      preConfigure = ''
        sed -i \
          's/^\s*#define\s\+LOG_LEVEL\>.*$/#define LOG_LEVEL LOG_ALL/; /#define\s\+CONSOLE_SYSLOG\>/ { s/\/\/#/#/; }' \
          src/config/console.h
      '';
    });
}