From 58f63e5d66cbc317fee76ab2c6dffe7b7b00984e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 5 Jul 2023 16:25:21 +0800 Subject: [PATCH] auto-install --- README | 37 +++++++-------------------------- default.nix | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 30 deletions(-) create mode 100644 default.nix diff --git a/README b/README index 49fe3b0..24d732a 100644 --- a/README +++ b/README @@ -1,33 +1,10 @@ -Installation commands for NUC: - -parted /dev/nvme0n1 -- mklabel gpt -parted /dev/nvme0n1 -- mkpart primary 512MiB 100% -parted /dev/nvme0n1 -- mkpart ESP fat32 1MiB 512MiB -parted /dev/nvme0n1 -- set 2 esp on -mkfs.ext4 -L nixos /dev/nvme0n1p1 -mkfs.fat -F 32 -n boot /dev/nvme0n1p2 -mount /dev/disk/by-label/nixos /mnt -mkdir -p /mnt/boot -mount /dev/disk/by-label/boot /mnt/boot -nixos-generate-config --root /mnt -# copy configuration to /mnt/etc/nixos -nix-env -iA nixos.git -# work around https://github.com/NixOS/nixpkgs/issues/209819 -rm /etc/nix/nix.conf -cp /etc/static/nix/nix.conf /etc/nix/nix.conf -vi /etc/nix/nix.conf -# set: -substituters = https://nixbld.m-labs.hk?priority=10 https://cache.nixos.org/ -trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nixbld.m-labs.hk-1:5aSRVA5b320xbNvu30tqxVPXpld73bhtOeH6uAjRyHc= -# -nixos-install --no-root-password --flake /mnt/etc/nixos#artiq -reboot -# run memtest86 - -After installation is finalized: -* copy device database to ~/artiq -* set timezone -* comment out openssh.authorizedKeys.keys +* Enter BIOS, disable secure boot, enable UEFI PXE network boot +* sudo auto-install +* sudo reboot +* Run memtest86 +* Copy device database to ~/artiq +* Set timezone +* Comment out openssh.authorizedKeys.keys * sudo nixos-rebuild boot * sudo nix-collect-garbage -d * history clear diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..4ce3499 --- /dev/null +++ b/default.nix @@ -0,0 +1,59 @@ +let + pkgs = import {}; + + # copied from nixpkgs/nixos/release.nix. Unfortunately, this isn't exported. + makeNetboot = { modules, system, ... }: + let + configEvaled = import { + inherit system modules; + }; + build = configEvaled.config.system.build; + kernelTarget = configEvaled.pkgs.stdenv.hostPlatform.linux-kernel.target; + in + pkgs.symlinkJoin { + name = "netboot"; + paths = [ + build.netbootRamdisk + build.kernel + build.netbootIpxeScript + ]; + postBuild = '' + mkdir -p $out/nix-support + echo "file ${kernelTarget} ${build.kernel}/${kernelTarget}" >> $out/nix-support/hydra-build-products + echo "file initrd ${build.netbootRamdisk}/initrd" >> $out/nix-support/hydra-build-products + echo "file ipxe ${build.netbootIpxeScript}/netboot.ipxe" >> $out/nix-support/hydra-build-products + ''; + preferLocalBuild = true; + }; + + autoInstall = pkgs.writeShellScriptBin "auto-install" + '' + set -e + parted /dev/nvme0n1 -- mklabel gpt + parted /dev/nvme0n1 -- mkpart primary 512MiB 100% + parted /dev/nvme0n1 -- mkpart ESP fat32 1MiB 512MiB + parted /dev/nvme0n1 -- set 2 esp on + mkfs.ext4 -L nixos /dev/nvme0n1p1 + mkfs.fat -F 32 -n boot /dev/nvme0n1p2 + mount /dev/disk/by-label/nixos /mnt + mkdir -p /mnt/boot + mount /dev/disk/by-label/boot /mnt/boot + nixos-generate-config --root /mnt + cp ${./final}/* /mnt/etc/nixos + nixos-install --no-root-password --flake /mnt/etc/nixos#artiq + ''; + + customModule = { + environment.systemPackages = [ autoInstall pkgs.git ]; + nix.settings.trusted-public-keys = ["nixbld.m-labs.hk-1:5aSRVA5b320xbNvu30tqxVPXpld73bhtOeH6uAjRyHc="]; + nix.settings.substituters = ["https://nixbld.m-labs.hk?priority=10"]; + }; + +in + makeNetboot { + modules = [ + + customModule + ]; + system = "x86_64-linux"; + }