{ pkgs, lib, modulesPath, config, target, ... }: with lib; let installer = pkgs.callPackage ./installer.nix { inherit target; }; auto-installer = let # This removes the direct dependency from the installer to the target image. # The install script is realized later during runtime using the cache. # To make this work, the cache must provide the real installer script. installer-path = builtins.unsafeDiscardStringContext (toString installer); in pkgs.writers.writeBash "auto-installer" '' set -o errexit set -o nounset set -o pipefail set -x ${pkgs.retry}/bin/retry \ --times 10 \ --delay 15 \ -- ${pkgs.nix}/bin/nix-store \ --realize \ --add-root /tmp/installer \ "${installer-path}" /tmp/installer reboot ''; in { imports = [ "${modulesPath}/installer/netboot/netboot-minimal.nix" ../shared/users.nix ../shared/network.nix ../shared/cache.nix ]; _module.args = { name = "installer"; }; networking.useDHCP = mkForce true; services.getty.autologinUser = lib.mkForce "root"; systemd.services."auto-install" = { description = "Automated NixOS installer"; wants = [ "network-online.target" ]; after = [ "network-online.target" ]; conflicts = [ "getty@tty1.service" ]; wantedBy = [ "multi-user.target" ]; path = with pkgs; [ bash nix ]; unitConfig = { FailureAction = "force-reboot"; }; serviceConfig = { Type = "oneshot"; ExecStart = auto-installer; StandardInput = "none"; StandardOutput = "journal+console"; StandardError = "journal+console"; }; }; # Expose the installer script system.build.installer = installer; system.stateVersion = config.system.nixos.release; }