Files
athenix/installer/auto-install.nix
2026-01-05 11:58:38 -05:00

70 lines
1.7 KiB
Nix

# This module defines a systemd service that automatically installs NixOS to the disk.
# It is intended to be used in an installation ISO.
# It expects `targetSystem` (the closure to install) and `diskoScript` (the partitioning script) to be passed as arguments.
{
config,
lib,
pkgs,
inputs,
hostName,
hostPlatform,
targetSystem,
diskoScript,
...
}:
{
# Ensure the entire system closure and all dependencies are included in the ISO
environment.systemPackages = [
pkgs.git
pkgs.bashInteractive
pkgs.curl
targetSystem
];
# Explicitly include the system closure in the ISO image to prevent any need to build or fetch
isoImage.contents = [
{
source = targetSystem;
target = "/system";
}
];
nixpkgs.hostPlatform = hostPlatform;
systemd.services.auto-install = {
description = "Automatic NixOS install for ${hostName}";
after = [
"network-online.target"
"systemd-udev-settle.service"
];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
StandardOutput = "journal+console";
StandardError = "journal+console";
Environment = "PATH=/run/current-system/sw/bin";
};
script = ''
echo "=== AUTO INSTALL START for ${hostName} ==="
echo ">>> Running disko script..."
${diskoScript}
echo ">>> Running nixos-install..."
# Use only local store - don't fetch from binary cache or build
nixos-install \
--no-root-passwd \
--root /mnt \
--system ${targetSystem} \
--option substitute false \
--option build-use-sandbox false
echo ">>> Done. Rebooting."
systemctl reboot
'';
};
}