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.

80 lines
1.5 KiB

  1. { pkgs, lib, modulesPath, config, ... }:
  2. with lib;
  3. let
  4. auto-installer = pkgs.writers.writeBash "auto-installer" ''
  5. set -o errexit
  6. set -o nounset
  7. set -o pipefail
  8. set -x
  9. if [[ "$(cat /proc/cmdline)" =~ nixos\.install=([^ ]+) ]]; then
  10. INSTALL="''${BASH_REMATCH[1]}"
  11. else
  12. echo "No install derivation found" >&2
  13. exit 1
  14. fi
  15. ${pkgs.retry}/bin/retry \
  16. --times 10 \
  17. --delay 15 \
  18. -- ${pkgs.nix}/bin/nix-store \
  19. --realize \
  20. --add-root /tmp/installer \
  21. "$INSTALL"
  22. exec /tmp/installer
  23. '';
  24. in
  25. {
  26. imports = [
  27. "${modulesPath}/installer/netboot/netboot-minimal.nix"
  28. ./shared/network.nix
  29. ./shared/cache.nix
  30. ./shared/users.nix
  31. ];
  32. _module.args = {
  33. name = "installer";
  34. };
  35. networking.useDHCP = mkForce true;
  36. services.getty.autologinUser = lib.mkForce "root";
  37. systemd.services."auto-install" = {
  38. description = "Automated NixOS installer";
  39. wants = [ "network-online.target" ];
  40. after = [ "network-online.target" ];
  41. conflicts = [ "getty@tty1.service" ];
  42. wantedBy = [ "multi-user.target" ];
  43. path = with pkgs; [ bash nix ];
  44. unitConfig = {
  45. AssertKernelCommandLine = "nixos.install";
  46. FailureAction = "force-reboot";
  47. };
  48. serviceConfig = {
  49. Type = "oneshot";
  50. ExecStart = auto-installer;
  51. StandardInput = "none";
  52. StandardOutput = "journal+console";
  53. StandardError = "journal+console";
  54. };
  55. };
  56. system.stateVersion = config.system.nixos.release;
  57. }