Merge branch 'version-updates' into 'main'

Version updates

See merge request greg/vms!17
This commit is contained in:
Greg Hellings
2025-01-24 15:46:26 +00:00
30 changed files with 617 additions and 0 deletions
+19
View File
@@ -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<enter><wait1>",
"echo 'iface eth0 inet dhcp' > /etc/network/interfaces<enter><wait>",
"ifup eth0<enter><wait8>",
"wget -O answers.cfg.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/answers.cfg.sh<enter>",
"<wait3>",
"wget -O in-chroot.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/in-chroot.sh<enter>",
"<wait3>",
"/bin/ash ./answers.cfg.sh 2>&1 | tee install.log<enter>",
]
http_directory = "distros/alpine/3.21/http/"
boot_wait = "20s"
shutdown_command = "sudo poweroff"
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
set -ex
+61
View File
@@ -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
+57
View File
@@ -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 <<EOF
# For now the vagrant insecure key is an rsa key
# https://github.com/hashicorp/vagrant/issues/11783
PubkeyAcceptedKeyTypes=+ssh-rsa
EOF
ssh-keygen -A
# Create and configure the vagrant user
adduser vagrant -D
# Add the vagrant user to the `wheel` group
addgroup vagrant wheel
[ -d /home/vagrant ] || exit 1
echo "vagrant:vagrant" | chpasswd
echo "root:vagrant" | chpasswd
# Do host-specific things
virt="$(virt-what)"
# Values I've found so far
# "microsoft" == Hyper-V
# "oracle" == VirtualBox
# "KVM" == KVM/Qemu
case "${virt}" in
microsoft | hyperv)
apk add hvtools
rc-update add hv_fcopy_daemon
rc-update add hv_kvp_daemon
rc-update add hv_vss_daemon
target="0001" # Placeholder for now
;;
kvm | qemu)
apk add qemu-guest-agent
rc-update add qemu-guest-agent
target="$(efibootmgr | grep 'Misc' | awk '{print $1}' | sed -E 's/[^0-9]//g')"
;;
virtualbox*)
apk add virtualbox-guest-additions
rc-update add virtualbox-guest-additions boot
target="$(efibootmgr | grep 'VBOX HARD' | awk '{print $1}' | sed -E 's/[^0-9]//g')"
;;
esac
efibootmgr --bootnext "${target}"
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
set -ex
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
set -ex
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
set -ex
pacman -Sy --noconfirm open-vm-tools
+5
View File
@@ -9,4 +9,9 @@
arch = "amd64";
eol = false;
}
{
version = "3.21";
arch = "amd64";
eol = false;
}
]
+34
View File
@@ -0,0 +1,34 @@
#!env bash
set -ex
# Name of the file to write out
name="${0%.sh}"
baseurl="https://mirror.stream.centos.org/10-stream/BaseOS/x86_64/iso/CentOS-Stream-10-latest-x86_64-boot.iso"
checksums="$(mktemp)"
until curl -f -L "${baseurl}.SHA256SUM" > "${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 = [
"<up>e<wait>",
"<down><down><end><wait>",
" inst.text inst.ks=cdrom:/ks.cfg",
" inst.notmux ",
"<leftCtrlOn>x<leftCtrlOff>"
]
cd_files = [ "distros/centos-stream/10/disc/*" ]
vbox_os_type = "RedHat10_64"
HERPDERP
rm -f cache/CentOS-Stream-10-latest-x86_64-boot.iso
+161
View File
@@ -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 <<EOF
:%substitute/^.*\(PasswordAuthentication\) yes$/\1 yes/
:%substitute/^#\(UseDNS\) yes$/&\r\1 no/
:update
:quit
EOF
cat >>/etc/sysconfig/sshd <<EOF
echo << EOF > /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 - <<EOF
/etc/sudoers.d/vagrant
/etc/dracut.conf.d/vmware-fusion-drivers.conf
/etc/dracut.conf.d/hyperv-drivers.conf
/etc/dracut.conf.d/nofloppy.conf
EOF
virt="$(systemd-detect-virt)"
if [ "${virt}" == "microsoft" ]; then
systemctl enable hpervfcopyd
systemctl enable hypervkvpd
systemctl enable hypervvssd
fi
# Rerun dracut for the installed kernel (not the running kernel):
KERNEL_VERSION=$(rpm -q kernel --qf '%{version}-%{release}.%{arch}\n')
dracut -f /boot/initramfs-${KERNEL_VERSION}.img ${KERNEL_VERSION}
# Seal for deployment
rm -rf /etc/ssh/ssh_host_*
hostnamectl set-hostname localhost.localdomain
rm -rf /etc/udev/rules.d/70-*
%end
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -ex
dnf clean all
+6
View File
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -ex
dnf install -y qemu-guest-agent
systemctl start qemu-guest-agent
systemctl enable qemu-guest-agent
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -ex
packages=(bzip2 kernel-devel kernel-headers make perl gcc)
dnf install -y "${packages[@]}"
mount -t auto /home/vagrant/VBoxGuestAdditions.iso /mnt
/mnt/VBoxLinuxAdditions.run install --nox11 2>&1 | tee /root/vbox_addon_install.log
umount /mnt
rm /home/vagrant/VBoxGuestAdditions.iso
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -ex
dnf install -y open-vm-tools
+5
View File
@@ -9,4 +9,9 @@
arch = "amd64";
eol = false;
}
{
version = "10";
arch = "amd64";
eol = false;
}
]
+41
View File
@@ -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<enter>",
"<wait>",
"sudo bash /tmp/install.sh {{ .HTTPPort }} {{ .HTTPIP }}<enter>"
]
http_directory = "distros/nixos/${version}/http/"
boot_wait = "90s"
EOF
rm -r "${tmp}"
rm -f "cache/latest-nixos-minimal-x86_64-linux.iso"
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
set -ex
@@ -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";
};
};
}
+16
View File
@@ -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 ];
};
};
}
+4
View File
@@ -0,0 +1,4 @@
{ ... }:
{
services.qemuGuest.enable = true;
}
@@ -0,0 +1,4 @@
{ ... }:
{
virtualisation.hypervGuest.enable = true;
}
+6
View File
@@ -0,0 +1,6 @@
{ ... }:
{
virtualisation.virtualbox.guest = {
enable = true;
};
}
+4
View File
@@ -0,0 +1,4 @@
{ ... }:
{
services.qemuGuest.enable = true;
}
+7
View File
@@ -0,0 +1,7 @@
{ ... }:
{
virtualisation.vmware.guest = {
enable = true;
headless = false;
};
}
+10
View File
@@ -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
+64
View File
@@ -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
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
set -ex
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
set -ex
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
set -ex
+5
View File
@@ -14,4 +14,9 @@
arch = "amd64";
eol = false;
}
{
version = "24.11";
arch = "amd64";
eol = false;
}
]