diff --git a/distros/alpine/3.21/amd64.pkrvars.hcl b/distros/alpine/3.21/amd64.pkrvars.hcl new file mode 100644 index 0000000..aff4755 --- /dev/null +++ b/distros/alpine/3.21/amd64.pkrvars.hcl @@ -0,0 +1,19 @@ +distro = "alpine" +version = "3.21" +iso = { + url = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-standard-3.21.2-x86_64.iso" + checksum = "706e9521cd21188786cb983131040ee68399e504924ea3318d600d1e04a93878" +} +boot_command = [ + "root", + "echo 'iface eth0 inet dhcp' > /etc/network/interfaces", + "ifup eth0", + "wget -O answers.cfg.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/answers.cfg.sh", + "", + "wget -O in-chroot.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/in-chroot.sh", + "", + "/bin/ash ./answers.cfg.sh 2>&1 | tee install.log", +] +http_directory = "distros/alpine/3.21/http/" +boot_wait = "20s" +shutdown_command = "sudo poweroff" diff --git a/distros/alpine/3.21/finalize.sh b/distros/alpine/3.21/finalize.sh new file mode 100644 index 0000000..eaaa81a --- /dev/null +++ b/distros/alpine/3.21/finalize.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +set -ex diff --git a/distros/alpine/3.21/http/answers.cfg.sh b/distros/alpine/3.21/http/answers.cfg.sh new file mode 100644 index 0000000..f743a28 --- /dev/null +++ b/distros/alpine/3.21/http/answers.cfg.sh @@ -0,0 +1,61 @@ +#!/bin/ash +# shellcheck shell=dash + +set -ex -o pipefail + +if [ -e /dev/vda ]; then + disk="/dev/vda" +else + disk="/dev/sda" +fi + +cat << EOF > answers.cfg +KEYMAPOPTS="us us" + +HOSTNAMEOPTS="vagrant" + +DEVDOPTS=mdev + +INTERFACESOPTS="auto lo +iface lo inet loopback + +auto eth0 +iface eth0 inet dhcp +hostname vagrant.local" + +TIMEZONEOPTS="UTC" + +PROXYOPTS="none" + +# Add first CDN mirror +APKREPOSOPTS="-1" + +USEROPTS="-a -u -g audio,video,netdev vagrant" + +SSHDOPTS=openssh + +NTPOPTS=none + +DISKOPTS="-m sys ${disk}" + +LBUOPTS=none + +APKCACHEOPTS=none +EOF + +setup-alpine -e -f answers.cfg -q +yes y | setup-disk -m sys "${disk}" || true +# It isn't setting up disk in initial run, but +# it also can't setup disk before the rest of it +# is setup properly. There might be a better workaround +# but this is what I'm choosing to do +setup-alpine -e -f answers.cfg -q + +mount "${disk}3" /mnt +mount "${disk}1" /mnt/boot + +mv in-chroot.sh /mnt +for fs in proc sys dev sys/firmware/efi/efivars; do mount -o bind /${fs} /mnt/${fs}; done +chroot /mnt /bin/ash /in-chroot.sh +rm /mnt/in-chroot.sh +reboot diff --git a/distros/alpine/3.21/http/in-chroot.sh b/distros/alpine/3.21/http/in-chroot.sh new file mode 100644 index 0000000..d127e9c --- /dev/null +++ b/distros/alpine/3.21/http/in-chroot.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env sh +set -ex + +# Enables packages like "sudo" +sed -i 's/#\(.*\/community\)/\1/' /etc/apk/repositories + +# Install bare minimal packages +apk add curl efibootmgr openssh sudo virt-what + +rc-update add sshd default + +# Configure systems +echo 'vagrant ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/vagrant-nopasswd +echo 'Defaults !requiretty' >> /etc/sudoers +sed -i 's/.*UseDNS.*/UseDNS no/' /etc/ssh/sshd_config +cat > /etc/ssh/sshd_config.d/10-vagrant-insecure-rsa-key.conf < "${checksums}"; do + sleep 1 +done +sha="$(awk '/SHA256/ {print $4}' "${checksums}")" +rm "${checksums}" + +cat << HERPDERP > "${name}" +distro = "centos-stream" +version = "10" +iso = { + url = "${baseurl}" + checksum = "${sha}" +} +boot_command = [ + "e", + "", + " inst.text inst.ks=cdrom:/ks.cfg", + " inst.notmux ", + "x" +] +cd_files = [ "distros/centos-stream/10/disc/*" ] +vbox_os_type = "RedHat10_64" +HERPDERP + +rm -f cache/CentOS-Stream-10-latest-x86_64-boot.iso diff --git a/distros/centos-stream/10/disc/ks.cfg b/distros/centos-stream/10/disc/ks.cfg new file mode 100644 index 0000000..8943c91 --- /dev/null +++ b/distros/centos-stream/10/disc/ks.cfg @@ -0,0 +1,161 @@ +url --metalink=https://mirrors.centos.org/metalink?arch=x86_64&repo=centos-baseos-10-stream +repo --name=AppStream --metalink=https://mirrors.centos.org/metalink?arch=x86_64&repo=centos-appstream-10-stream +network --bootproto=dhcp --activate +reboot + +text +keyboard --vckeymap us +lang en_US +skipx +rootpw --plaintext vagrant +firewall --disabled +timezone --utc UTC +services --enabled=vmtoolsd +# The biosdevname and ifnames options ensure we get "eth0" as our interface +# even in environments like virtualbox that emulate a real NW card +bootloader --timeout=1 --append="no_timer_check console=tty0 console=ttyS0,115200n8 net.ifnames=0 biosdevname=0 elevator=noop" +clearpart --all +autopart --type=plain +zerombr + +user --name=vagrant --plaintext --password=vagrant + +%packages --inst-langs=en +bash-completion +man-pages +bzip2 +rsync +nfs-utils +cifs-utils +chrony +yum-utils +hyperv-daemons +open-vm-tools +# Vagrant boxes aren't normally visible, no need for Plymouth +-plymouth +# Microcode updates cannot work in a VM +-microcode_ctl +# Firmware packages are not needed in a VM +-iwl100-firmware +-iwl1000-firmware +-iwl105-firmware +-iwl135-firmware +-iwl2000-firmware +-iwl2030-firmware +-iwl3160-firmware +-iwl3945-firmware +-iwl4965-firmware +-iwl5000-firmware +-iwl5150-firmware +-iwl6000-firmware +-iwl6000g2a-firmware +-iwl6050-firmware +-iwl7260-firmware +# Don't build rescue initramfs +-dracut-config-rescue +%end + +# kdump needs to reserve 160MB + 2bits/4kB RAM, and automatic allocation only +# works on systems with at least 2GB RAM (which excludes most Vagrant boxes) +# CBS doesn't support %addon yet https://bugs.centos.org/view.php?id=12169 +%addon com_redhat_kdump --disable +%end + +%post --erroronfail +dnf update -y + +# configure swap to a file +fallocate -l 2G /swapfile +chmod 600 /swapfile +mkswap /swapfile +echo "/swapfile none swap defaults 0 0" >> /etc/fstab + +# sudo +echo "%vagrant ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/vagrant +chmod 0440 /etc/sudoers.d/vagrant + +# Fix for https://github.com/CentOS/sig-cloud-instance-build/issues/38 +cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF +DEVICE="eth0" +BOOTPROTO="dhcp" +ONBOOT="yes" +TYPE="Ethernet" +PERSISTENT_DHCLIENT="yes" +EOF + +# sshd: disable password authentication and DNS checks +ex -s /etc/ssh/sshd_config <>/etc/sysconfig/sshd < /etc/ssh/sshd_config.d/00-vagrant_accept_pubkey.conf +PubkeyAcceptedKeyTypes +ssh-rsa +EOF + +# Decrease connection time by preventing reverse DNS lookups +# (see https://lists.centos.org/pipermail/centos-devel/2016-July/014981.html +# and man sshd for more information) +OPTIONS="-u0" +EOF + +# Fix for issue #76, regular users can gain admin privileges via su +ex -s /etc/pam.d/su <<'EOF' +# allow vagrant to use su, but prevent others from becoming root or vagrant +/^account\s\+sufficient\s\+pam_succeed_if.so uid = 0 use_uid quiet$/ +:append +account [success=1 default=ignore] \ + pam_succeed_if.so user = vagrant use_uid quiet +account required pam_succeed_if.so user notin root:vagrant +. +:update +:quit +EOF + +# systemd should generate a new machine id during the first boot, to +# avoid having multiple Vagrant instances with the same id in the local +# network. /etc/machine-id should be empty, but it must exist to prevent +# boot errors (e.g. systemd-journald failing to start). +:>/etc/machine-id + +echo 'vag' > /etc/yum/vars/infra + +# Blacklist the floppy module to avoid probing timeouts +echo blacklist floppy > /etc/modprobe.d/nofloppy.conf +chcon -u system_u -r object_r -t modules_conf_t /etc/modprobe.d/nofloppy.conf + +# Customize the initramfs +pushd /etc/dracut.conf.d +# Enable VMware PVSCSI support for VMware Fusion guests. +echo 'add_drivers+=" vmw_pvscsi "' > vmware-fusion-drivers.conf +echo 'add_drivers+=" hv_netvsc hv_storvsc hv_utils hv_vmbus hid-hyperv "' > hyperv-drivers.conf +# There's no floppy controller, but probing for it generates timeouts +echo 'omit_drivers+=" floppy "' > nofloppy.conf +popd +# Fix the SELinux context of the new files +restorecon -f - <&1 | tee /root/vbox_addon_install.log +umount /mnt +rm /home/vagrant/VBoxGuestAdditions.iso diff --git a/distros/centos-stream/10/vmware.sh b/distros/centos-stream/10/vmware.sh new file mode 100644 index 0000000..058afc2 --- /dev/null +++ b/distros/centos-stream/10/vmware.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -ex + +dnf install -y open-vm-tools diff --git a/distros/centos-stream/default.nix b/distros/centos-stream/default.nix index d17f358..415e3c4 100644 --- a/distros/centos-stream/default.nix +++ b/distros/centos-stream/default.nix @@ -9,4 +9,9 @@ arch = "amd64"; eol = false; } + { + version = "10"; + arch = "amd64"; + eol = false; + } ] 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; + } ]