NixOS deployment for LinuxLab
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
1.9 KiB

  1. { pkgs, config, nodes, ... }:
  2. let
  3. installer = pkgs.nixos [
  4. ../../installer.nix
  5. ];
  6. installer-script =
  7. let
  8. target = nodes."client".config.system.build;
  9. in
  10. pkgs.writers.writeBash "installer" ''
  11. set -o errexit
  12. set -o nounset
  13. set -o pipefail
  14. set -x
  15. "${target.diskoScript}"
  16. "${target.nixos-install}/bin/nixos-install" \
  17. --root /mnt \
  18. --system "${target.toplevel}" \
  19. --no-channel-copy \
  20. --no-root-password \
  21. --verbose
  22. ${pkgs.util-linux}/bin/umount -R /mnt
  23. reboot
  24. '';
  25. ipxe-script = pkgs.writeText "boot-local.ipxe" ''
  26. #!ipxe
  27. sleep 2
  28. prompt --key 0x18 --timeout 5000 Press Ctrl-X to re-deploy system... || goto local
  29. echo Starting installer...
  30. sleep 2
  31. kernel --name kernel http://''${next-server:ipv4}/bzImage || goto err
  32. initrd --name initrd http://''${next-server:ipv4}/initrd || goto err
  33. boot kernel initrd=initrd init=${installer.config.system.build.toplevel}/init nixos.install=${installer-script} loglevel=4 || goto err
  34. :err
  35. :shell
  36. shell ||
  37. :local
  38. prompt --key 0x19 --timeout 2000 Booting local disk... && goto shell ||
  39. sanboot -d 0x80 || goto err
  40. '';
  41. in
  42. {
  43. services.nginx = {
  44. enable = true;
  45. virtualHosts."boot.${config.networking.domain}" = {
  46. locations."/" = {
  47. root = pkgs.linkFarm "root" {
  48. "bzImage" = installer.config.system.build.kernel + "/bzImage";
  49. "initrd" = installer.config.system.build.netbootRamdisk + "/initrd";
  50. };
  51. };
  52. };
  53. };
  54. services.pixiecore = {
  55. enable = true;
  56. debug = true;
  57. dhcpNoBind = true;
  58. port = 5080;
  59. mode = "boot";
  60. kernel = toString ipxe-script;
  61. openFirewall = true;
  62. };
  63. networking.extraHosts = ''
  64. 127.0.0.1 boot.${config.networking.domain}
  65. '';
  66. networking.firewall.allowedTCPPorts = [
  67. 80 # HTTP
  68. ];
  69. }