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.

86 lines
1.8 KiB

  1. { pkgs, lib, modulesPath, config, target, ... }:
  2. with lib;
  3. let
  4. installer = pkgs.callPackage ./installer.nix { inherit target; };
  5. auto-installer =
  6. let
  7. # This removes the direct dependency from the installer to the target image.
  8. # The install script is realized later during runtime using the cache.
  9. # To make this work, the cache must provide the real installer script.
  10. installer-path = builtins.unsafeDiscardStringContext (toString installer);
  11. in
  12. pkgs.writers.writeBash "auto-installer" ''
  13. set -o errexit
  14. set -o nounset
  15. set -o pipefail
  16. set -x
  17. ${pkgs.retry}/bin/retry \
  18. --times 10 \
  19. --delay 15 \
  20. -- ${pkgs.nix}/bin/nix-store \
  21. --realize \
  22. --add-root /tmp/installer \
  23. "${installer-path}"
  24. /tmp/installer
  25. reboot
  26. '';
  27. in
  28. {
  29. imports = [
  30. "${modulesPath}/installer/netboot/netboot-minimal.nix"
  31. ../shared/users.nix
  32. ../shared/network.nix
  33. ../shared/cache.nix
  34. ];
  35. _module.args = {
  36. name = "installer";
  37. };
  38. networking.useDHCP = mkForce true;
  39. services.getty.autologinUser = lib.mkForce "root";
  40. systemd.services."auto-install" = {
  41. description = "Automated NixOS installer";
  42. wants = [ "network-online.target" ];
  43. after = [ "network-online.target" ];
  44. conflicts = [ "getty@tty1.service" ];
  45. wantedBy = [ "multi-user.target" ];
  46. path = with pkgs; [ bash nix ];
  47. unitConfig = {
  48. FailureAction = "force-reboot";
  49. };
  50. serviceConfig = {
  51. Type = "oneshot";
  52. ExecStart = auto-installer;
  53. StandardInput = "none";
  54. StandardOutput = "journal+console";
  55. StandardError = "journal+console";
  56. };
  57. };
  58. # Expose the installer script
  59. system.build.installer = installer;
  60. system.stateVersion = config.system.nixos.release;
  61. }