From 32a24181f3540b26040728dfbea4c8bf24423b4f Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Wed, 22 Jan 2025 09:53:33 -0600 Subject: [PATCH] Add NixOS 24.11 --- distros/nixos/24.11/amd64.pkrvars.hcl.sh | 41 ++++++++++++ distros/nixos/24.11/finalize.sh | 2 + distros/nixos/24.11/http/configuration.nix | 73 ++++++++++++++++++++++ distros/nixos/24.11/http/flake.nix | 16 +++++ distros/nixos/24.11/http/ga-kvm.nix | 4 ++ distros/nixos/24.11/http/ga-microsoft.nix | 4 ++ distros/nixos/24.11/http/ga-oracle.nix | 6 ++ distros/nixos/24.11/http/ga-qemu.nix | 4 ++ distros/nixos/24.11/http/ga-vmware.nix | 7 +++ distros/nixos/24.11/http/in-chroot.sh | 10 +++ distros/nixos/24.11/http/install.sh | 64 +++++++++++++++++++ distros/nixos/24.11/qemu.sh | 2 + distros/nixos/24.11/virtualbox.sh | 2 + distros/nixos/24.11/vmware.sh | 2 + distros/nixos/default.nix | 5 ++ 15 files changed, 242 insertions(+) create mode 100755 distros/nixos/24.11/amd64.pkrvars.hcl.sh create mode 100644 distros/nixos/24.11/finalize.sh create mode 100644 distros/nixos/24.11/http/configuration.nix create mode 100644 distros/nixos/24.11/http/flake.nix create mode 100644 distros/nixos/24.11/http/ga-kvm.nix create mode 100644 distros/nixos/24.11/http/ga-microsoft.nix create mode 100644 distros/nixos/24.11/http/ga-oracle.nix create mode 100644 distros/nixos/24.11/http/ga-qemu.nix create mode 100644 distros/nixos/24.11/http/ga-vmware.nix create mode 100644 distros/nixos/24.11/http/in-chroot.sh create mode 100644 distros/nixos/24.11/http/install.sh create mode 100644 distros/nixos/24.11/qemu.sh create mode 100644 distros/nixos/24.11/virtualbox.sh create mode 100644 distros/nixos/24.11/vmware.sh diff --git a/distros/nixos/24.11/amd64.pkrvars.hcl.sh b/distros/nixos/24.11/amd64.pkrvars.hcl.sh new file mode 100755 index 0000000..e1c5805 --- /dev/null +++ b/distros/nixos/24.11/amd64.pkrvars.hcl.sh @@ -0,0 +1,41 @@ +#!env bash +set -exo pipefail + +# Name of the file to write out +name="${0%.sh}" + +version="24.11" + +# Base URL +base="https://channels.nixos.org/nixos-${version}/latest-nixos-minimal-x86_64-linux.iso" + +# Working directory +tmp="$(mktemp -d)" +checksums="${tmp}/checksums" + +# Read the SHA256 sum value +curl -L -o "${checksums}" "${base}.sha256" +until curl -f -L -o "${checksums}" "${base}.sha256"; do + sleep 1 +done +sha="$(grep -e minimal "${checksums}" | cut -d' ' -f 1)" + +# Write out HCL file +cat << EOF > "${name}" +distro = "nixos" +version = "${version}" +iso = { + url = "${base}" + checksum = "${sha}" +} +boot_command = [ + "curl -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/install.sh", + "", + "sudo bash /tmp/install.sh {{ .HTTPPort }} {{ .HTTPIP }}" +] +http_directory = "distros/nixos/${version}/http/" +boot_wait = "90s" +EOF + +rm -r "${tmp}" +rm -f "cache/latest-nixos-minimal-x86_64-linux.iso" diff --git a/distros/nixos/24.11/finalize.sh b/distros/nixos/24.11/finalize.sh new file mode 100644 index 0000000..4cfad53 --- /dev/null +++ b/distros/nixos/24.11/finalize.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +set -ex diff --git a/distros/nixos/24.11/http/configuration.nix b/distros/nixos/24.11/http/configuration.nix new file mode 100644 index 0000000..192cad6 --- /dev/null +++ b/distros/nixos/24.11/http/configuration.nix @@ -0,0 +1,73 @@ +{ + pkgs, + lib, + ... +}: + +{ + imports = [ + ./hardware-configuration.nix + ./guest-agent.nix + ]; + + system.stateVersion = "24.11"; + + # Packages installed on the whole system + environment.systemPackages = with pkgs; [ + curl + nano + python3 + ]; + # Services that are running + services = { + openssh.enable = true; + #xserver.enable = true; + }; + # User setup + users.groups.vagrant = { }; + users.users.vagrant = { + isNormalUser = true; + group = "vagrant"; + extraGroups = [ "wheel" ]; + password = "vagrant"; + }; + security.sudo.extraRules = [ + { + users = [ "vagrant" ]; + groups = [ "vagrant" ]; + commands = [ + { + command = "ALL"; + options = [ "NOPASSWD" ]; + } + ]; + } + ]; + + boot.loader = { + systemd-boot = { + enable = true; + }; + efi.canTouchEfiVariables = true; + }; + networking = { + hostName = "vagrant"; + networkmanager.enable = true; + #proxy.default = "http://user:password@proxy:port/"; + #proxy.noProxy = "127.0.0.1,localhost,internal.domain"; + }; + time.timeZone = "UTC"; + + i18n.defaultLocale = "en_US.UTF-8"; + console = { + font = "Lat2-Terminux16"; + keyMap = lib.mkForce "us"; + useXkbConfig = true; + }; + + nix = { + settings = { + experimental-features = "nix-command flakes"; + }; + }; +} diff --git a/distros/nixos/24.11/http/flake.nix b/distros/nixos/24.11/http/flake.nix new file mode 100644 index 0000000..cf6aeb2 --- /dev/null +++ b/distros/nixos/24.11/http/flake.nix @@ -0,0 +1,16 @@ +{ + description = "A basic NixOS Vagrant install"; + + inputs = { + nixstable.url = "github:nixos/nixpkgs/nixos-24.11"; + }; + + outputs = + { nixstable, ... }: + { + nixosConfigurations.vagrant = nixstable.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ ./configuration.nix ]; + }; + }; +} diff --git a/distros/nixos/24.11/http/ga-kvm.nix b/distros/nixos/24.11/http/ga-kvm.nix new file mode 100644 index 0000000..65105c0 --- /dev/null +++ b/distros/nixos/24.11/http/ga-kvm.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + services.qemuGuest.enable = true; +} diff --git a/distros/nixos/24.11/http/ga-microsoft.nix b/distros/nixos/24.11/http/ga-microsoft.nix new file mode 100644 index 0000000..f924009 --- /dev/null +++ b/distros/nixos/24.11/http/ga-microsoft.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + virtualisation.hypervGuest.enable = true; +} diff --git a/distros/nixos/24.11/http/ga-oracle.nix b/distros/nixos/24.11/http/ga-oracle.nix new file mode 100644 index 0000000..e274dac --- /dev/null +++ b/distros/nixos/24.11/http/ga-oracle.nix @@ -0,0 +1,6 @@ +{ ... }: +{ + virtualisation.virtualbox.guest = { + enable = true; + }; +} diff --git a/distros/nixos/24.11/http/ga-qemu.nix b/distros/nixos/24.11/http/ga-qemu.nix new file mode 100644 index 0000000..65105c0 --- /dev/null +++ b/distros/nixos/24.11/http/ga-qemu.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + services.qemuGuest.enable = true; +} diff --git a/distros/nixos/24.11/http/ga-vmware.nix b/distros/nixos/24.11/http/ga-vmware.nix new file mode 100644 index 0000000..dbedb7d --- /dev/null +++ b/distros/nixos/24.11/http/ga-vmware.nix @@ -0,0 +1,7 @@ +{ ... }: +{ + virtualisation.vmware.guest = { + enable = true; + headless = false; + }; +} diff --git a/distros/nixos/24.11/http/in-chroot.sh b/distros/nixos/24.11/http/in-chroot.sh new file mode 100644 index 0000000..60c21f1 --- /dev/null +++ b/distros/nixos/24.11/http/in-chroot.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -ex + +# Set passwords +echo "vagrant:vagrant" | chpasswd +echo "root:vagrant" | chpasswd + +# Set ownership of things vagrant should own +chown -R vagrant:vagrant ~vagrant/ +chown -R vagrant:wheel /etc/nixos diff --git a/distros/nixos/24.11/http/install.sh b/distros/nixos/24.11/http/install.sh new file mode 100644 index 0000000..0afef82 --- /dev/null +++ b/distros/nixos/24.11/http/install.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +#vim: set ft=bash: +set -ex + +port="${1}" # HTTP port that packer is running on +host="${2}" + +if [ -e /dev/vda ]; then + disk="/dev/vda" +elif [ -e /dev/sda ]; then + disk="/dev/sda" +else + exit 1 # Need to teach the script which device to use in this case +fi + +# The sed bit is just to strip out the extra fluff, like comments +sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk ${disk} + g # create new GPT partition table + n # new + # default partition number + # default start + +512M # size + t # set type + 1 # EFI system partition + n # second partition + # default partition number + # start at first free sector + # default to full disk + p # print, for debugging + w # write the partition table and exit +EOF + +sleep 10 # Let me at least read it! + #t # set partition type + #1 # on partition 1 + #4 # BIOS boot + +# Format and mount partitions +mkfs.vfat "${disk}1" +mkfs.ext4 "${disk}2" + +mount "${disk}2" /mnt +mkdir -p /mnt/boot +mount "${disk}1" /mnt/boot + +# Bootstrap system +virt="$(systemd-detect-virt)" +nixos-generate-config --root /mnt +curl -o /mnt/etc/nixos/configuration.nix "http://${host}:${port}/configuration.nix" +curl -o /mnt/etc/nixos/flake.nix "http://${host}:${port}/flake.nix" +curl -o /mnt/etc/nixos/guest-agent.nix "http://${host}:${port}/ga-${virt}.nix" +sed -i -E -e "s,@BOOT_DEVICE@,${disk}," /mnt/etc/nixos/configuration.nix + +nixos-install --no-root-password --flake "/mnt/etc/nixos/#vagrant" + +# Run stuff in the chroot +curl -o /mnt/root/in-chroot.sh "http://${host}:${port}/in-chroot.sh" +nixos-enter --root /mnt -c 'bash /root/in-chroot.sh' +rm /mnt/root/in-chroot.sh + +umount /mnt/boot +umount /mnt +efibootmgr --bootnext "$(efibootmgr | grep Linux | awk '{print $1}' | sed -E 's/[^0-9]//g')" +reboot diff --git a/distros/nixos/24.11/qemu.sh b/distros/nixos/24.11/qemu.sh new file mode 100644 index 0000000..4cfad53 --- /dev/null +++ b/distros/nixos/24.11/qemu.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +set -ex diff --git a/distros/nixos/24.11/virtualbox.sh b/distros/nixos/24.11/virtualbox.sh new file mode 100644 index 0000000..4cfad53 --- /dev/null +++ b/distros/nixos/24.11/virtualbox.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +set -ex diff --git a/distros/nixos/24.11/vmware.sh b/distros/nixos/24.11/vmware.sh new file mode 100644 index 0000000..4cfad53 --- /dev/null +++ b/distros/nixos/24.11/vmware.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +set -ex diff --git a/distros/nixos/default.nix b/distros/nixos/default.nix index a308c55..fd22de0 100644 --- a/distros/nixos/default.nix +++ b/distros/nixos/default.nix @@ -14,4 +14,9 @@ arch = "amd64"; eol = false; } + { + version = "24.11"; + arch = "amd64"; + eol = false; + } ]