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.

99 lines
1.9 KiB

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