From 55dd99e155fe3f0470315eacd6f0ce8b68f92861 Mon Sep 17 00:00:00 2001 From: beatzaplenty Date: Mon, 21 Jul 2025 00:10:48 +1000 Subject: [PATCH] new file: auto-installer/flake.nix new file: auto-installer/installer.nix --- auto-installer/flake.nix | 22 ++++++++++++ auto-installer/installer.nix | 69 ++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 auto-installer/flake.nix create mode 100644 auto-installer/installer.nix diff --git a/auto-installer/flake.nix b/auto-installer/flake.nix new file mode 100644 index 0000000..ff61f92 --- /dev/null +++ b/auto-installer/flake.nix @@ -0,0 +1,22 @@ +# flake.nix +{ + description = "Auto-install NixOS ISO"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + nixos-generators.url = "github:nix-community/nixos-generators"; + }; + + outputs = { self, nixpkgs, flake-utils, nixos-generators, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + iso = nixos-generators.nixosGenerate { + inherit system; + format = "install-iso"; + modules = [ ./installer.nix ]; + }; + in { + packages.default = iso; + }); +} diff --git a/auto-installer/installer.nix b/auto-installer/installer.nix new file mode 100644 index 0000000..2f1a45d --- /dev/null +++ b/auto-installer/installer.nix @@ -0,0 +1,69 @@ +# installer.nix +{ config, pkgs, lib, ... }: +{ + imports = [ + "${pkgs.path}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix" + ]; + + networking.useDHCP = lib.mkDefault true; + time.timeZone = "Australia/Brisbane"; + + services.openssh.enable = true; + services.openssh.permitRootLogin = "yes"; + + environment.systemPackages = with pkgs; [ + git + curl + parted + e2fsprogs + btrfs-progs + util-linux + ]; + + # Your flake source (adjust as needed) + environment.etc."flake-url".text = "git+https://gitea.lan.ddnsgeek.com/beatzaplenty/nixos.git#nixos"; + + systemd.services.autoInstall = { + description = "Automatic NixOS installation"; + wantedBy = [ "multi-user.target" ]; + after = [ "network-online.target" ]; + serviceConfig = { + Type = "oneshot"; + ExecStart = pkgs.writeShellScript "auto-install.sh" '' + set -eux + + echo "Running auto-install from flake..." + + # Disk prep + + #create MBR table + parted /dev/sda -- mklabel msdos + #create nixos partition + parted /dev/sda -- mkpart primary 1MB -8GB + #set nixos partition to bootable + parted /dev/sda -- set 1 boot on + # create swap partition + parted /dev/sda -- mkpart primary linux-swap -8GB 100% + + #format OS partition + mkfs.ext4 -L nixos /dev/sda1 + #format swap + mkswap -L swap /dev/sda2 + + #activate swap + swapon /dev/sda2 + + #mount nixos partition + mount /dev/disk/by-label/nixos /mnt + + + # Install system using flake + nixos-install --flake "$(cat /etc/flake-url)" --no-root-password + + echo "Installation complete, rebooting in 10s..." + sleep 10 + reboot + ''; + }; + }; +}