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.

100 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. 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. sleep 2
  41. sanboot -n -d 0x80
  42. '';
  43. in
  44. {
  45. services.nginx = {
  46. enable = true;
  47. virtualHosts."boot.${config.networking.domain}" = {
  48. locations."/" = {
  49. root = pkgs.linkFarm "root" {
  50. "bzImage" = installer.config.system.build.kernel + "/bzImage";
  51. "initrd" = installer.config.system.build.netbootRamdisk + "/initrd";
  52. };
  53. };
  54. };
  55. };
  56. services.pixiecore =
  57. {
  58. enable = true;
  59. debug = true;
  60. dhcpNoBind = true;
  61. port = 5080;
  62. mode = "boot";
  63. kernel = toString ipxe-script;
  64. openFirewall = true;
  65. };
  66. networking.extraHosts = ''
  67. 127.0.0.1 boot.${config.networking.domain}
  68. '';
  69. networking.firewall.allowedTCPPorts = [
  70. 80 # HTTP
  71. ];
  72. }