diff --git a/.gitignore b/.gitignore index bbe3246..c51599b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ isolinux.cfg Vagrantfile .direnv result +packer_config/ # Generated distros distros/fedora/rawhide/*.hcl diff --git a/.gitlab-ci-build.yml.in b/.gitlab-ci-build.yml.in index cf9f0cf..2849ac3 100644 --- a/.gitlab-ci-build.yml.in +++ b/.gitlab-ci-build.yml.in @@ -31,17 +31,8 @@ stages: PACKER_CONFIG_DIR: ./packer_config/ PACKER_CACHE_DIR: ./cache/ PACKER_LOG: 1 - COMMAND: > - packer build ${only} - -var-file="${distro}" - -var build=${BUILD} - -var cpus=2 - -var memory=4096 - ${EXCEPT} - sources script: - - echo $COMMAND > build.sh - - bash build.sh || exit 1 + - nix run ".#\"${buildcmd}\"" || exit 1 qemu.amd64: extends: .build @@ -67,9 +58,18 @@ hyperv-iso.amd64: <<: *variables only: '-only="hyperv-iso.amd64"' tag: hyperv + COMMAND: > + packer build ${only} + -var-file="${distro}" + -var build=${BUILD} + -var cpus=2 + -var memory=4096 + ${EXCEPT} + sources parallel: matrix: HYPERV_MATRIX script: + - packer init sources - echo $env:COMMAND > build.ps1 - echo 'if (-not $?) { throw "Error in build"}' >> build.ps1 - pwsh .\build.ps1 diff --git a/distros/almalinux/9/amd64.pkrvars.hcl b/distros/almalinux/9/amd64.pkrvars.hcl index 235dc15..d499e7d 100644 --- a/distros/almalinux/9/amd64.pkrvars.hcl +++ b/distros/almalinux/9/amd64.pkrvars.hcl @@ -8,7 +8,7 @@ boot_command = [ "e", "", " inst.text inst.ks=cdrom:/ks.cfg", - " console=ttyS0 inst.notmux", + " inst.notmux", "x" ] cd_files = [ "distros/almalinux/9/disc/*" ] diff --git a/distros/alpine/3.19.0/amd64.pkrvars.hcl b/distros/alpine/3.19.0/amd64.pkrvars.hcl index 894f4fd..b475795 100644 --- a/distros/alpine/3.19.0/amd64.pkrvars.hcl +++ b/distros/alpine/3.19.0/amd64.pkrvars.hcl @@ -1,8 +1,8 @@ distro = "alpine" version = "3.19.0" iso = { - url = "https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-standard-3.19.0-x86_64.iso" - checksum = "4cf7cd3bad64122a8a2423e78369a486a02334d4d88645aab9d08120bb76b0f9" + url = "http://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-extended-3.19.2-x86_64.iso" + checksum = "508944822217be4c2c7b947a64220271055b1883a025e5cb351950b27f046a15" } boot_command = [ "root", diff --git a/distros/alpine/3.20/amd64.pkrvars.hcl b/distros/alpine/3.20/amd64.pkrvars.hcl new file mode 100644 index 0000000..42369d8 --- /dev/null +++ b/distros/alpine/3.20/amd64.pkrvars.hcl @@ -0,0 +1,19 @@ +distro = "alpine" +version = "3.20" +iso = { + url = "http://dl-cdn.alpinelinux.org/alpine/v3.20/releases/x86_64/alpine-standard-3.20.1-x86_64.iso" + checksum = "c3043af6421b6e0ab22994b01d10785728888b37d976a754f12f23b42aecd95e" +} +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.20/http/" +boot_wait = "20s" +shutdown_command = "sudo poweroff" diff --git a/distros/alpine/3.20/finalize.sh b/distros/alpine/3.20/finalize.sh new file mode 100644 index 0000000..5a01809 --- /dev/null +++ b/distros/alpine/3.20/finalize.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +set -ex \ No newline at end of file diff --git a/distros/alpine/3.20/http/answers.cfg.sh b/distros/alpine/3.20/http/answers.cfg.sh new file mode 100644 index 0000000..a430023 --- /dev/null +++ b/distros/alpine/3.20/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 \ No newline at end of file diff --git a/distros/alpine/3.20/http/in-chroot.sh b/distros/alpine/3.20/http/in-chroot.sh new file mode 100644 index 0000000..4300f7d --- /dev/null +++ b/distros/alpine/3.20/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 < net.ifnames=0 biosdevnames=0 console=ttyS0", + "e net.ifnames=0 biosdevnames=0 ", "", # Wait for system to come up? "curl -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/install.sh", "", diff --git a/distros/centos-stream/9/amd64.pkrvars.hcl.sh b/distros/centos-stream/9/amd64.pkrvars.hcl.sh index 2e5c192..336417d 100755 --- a/distros/centos-stream/9/amd64.pkrvars.hcl.sh +++ b/distros/centos-stream/9/amd64.pkrvars.hcl.sh @@ -24,7 +24,7 @@ boot_command = [ "e", "", " inst.text inst.ks=cdrom:/ks.cfg", - " inst.notmux console=ttyS0", + " inst.notmux ", "x" ] cd_files = [ "distros/centos-stream/9/disc/*" ] diff --git a/distros/centos/7/amd64.pkrvars.hcl b/distros/centos/7/amd64.pkrvars.hcl index 1926391..c81d3bc 100644 --- a/distros/centos/7/amd64.pkrvars.hcl +++ b/distros/centos/7/amd64.pkrvars.hcl @@ -1,14 +1,14 @@ distro = "centos" version = "7" iso = { - url = "http://mirror.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-NetInstall-2009.iso" + url = "http://vault.centos.org/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-NetInstall-2009.iso" checksum = "b79079ad71cc3c5ceb3561fff348a1b67ee37f71f4cddfec09480d4589c191d6" } boot_command = [ "e", "", " inst.ks=cdrom:/ks.cfg", - " inst.notmux console=ttyS0", + " inst.notmux ", "x" ] cd_files = ["distros/centos/7/disc/*"] diff --git a/distros/centos/7/disc/ks.cfg b/distros/centos/7/disc/ks.cfg index e68c971..8da018b 100644 --- a/distros/centos/7/disc/ks.cfg +++ b/distros/centos/7/disc/ks.cfg @@ -2,8 +2,9 @@ install text reboot network --bootproto=dhcp --activate -url --url=http://mirror.centos.org/centos/7/os/x86_64/ -repo --name=updates --baseurl=http://mirror.centos.org/centos/7/updates/x86_64/ +url --url=http://vault.centos.org/7.9.2009/os/x86_64/ +repo --name=base --baseurl=http://vault.centos.org/7.9.2009/os/x86_64/ --install +repo --name=updates --baseurl=http://vault.centos.org/7.9.2009/updates/x86_64/ --install lang en_US.UTF-8 keyboard us timezone --utc Etc/UTC @@ -42,6 +43,11 @@ nmcli c %end %post --erroronfail + +echo "gpgkey=https://vault.centos.org/7.9.2009/os/x86_64/RPM-GPG-KEY-CentOS-7" >> /etc/yum.repos.d/base.repo +echo "gpgkey=https://vault.centos.org/7.9.2009/os/x86_64/RPM-GPG-KEY-CentOS-7" >> /etc/yum.repos.d/updates.repo +rm -f /etc/yum.repos.d/CentOS* + yum -y update cat < /etc/sudoers.d/vagrant diff --git a/distros/debian/10/amd64.pkrvars.hcl b/distros/debian/10/amd64.pkrvars.hcl index 94d2556..7a1aeb1 100644 --- a/distros/debian/10/amd64.pkrvars.hcl +++ b/distros/debian/10/amd64.pkrvars.hcl @@ -16,7 +16,6 @@ boot_command = [ "debconf/frontend=noninteractive ", "hostname={{.Name}} ", "domain=vagrant ", - "console=ttyS0 ", "" ] http_directory = "distros/debian/10/http/" diff --git a/distros/debian/11/amd64.pkrvars.hcl b/distros/debian/11/amd64.pkrvars.hcl index e93396e..795b6cb 100644 --- a/distros/debian/11/amd64.pkrvars.hcl +++ b/distros/debian/11/amd64.pkrvars.hcl @@ -16,7 +16,6 @@ boot_command = [ "debconf/frontend=noninteractive ", "hostname={{.Name}} ", "domain=vagrant ", - "console=ttyS0 ", "" ] http_directory = "distros/debian/11/http/" diff --git a/distros/debian/12/amd64.pkrvars.hcl b/distros/debian/12/amd64.pkrvars.hcl index 3278968..e77c0b5 100644 --- a/distros/debian/12/amd64.pkrvars.hcl +++ b/distros/debian/12/amd64.pkrvars.hcl @@ -1,8 +1,8 @@ distro = "debian" version = "12" iso = { - url = "http://cdimage.debian.org/cdimage/release/12.5.0/amd64/iso-cd/debian-12.5.0-amd64-netinst.iso" - checksum = "013f5b44670d81280b5b1bc02455842b250df2f0c6763398feb69af1a805a14f" + url = "http://cdimage.debian.org/cdimage/release/12.6.0/amd64/iso-cd/debian-12.6.0-amd64-netinst.iso" + checksum = "ade3a4acc465f59ca2496344aab72455945f3277a52afc5a2cae88cdc370fa12" } boot_command = [ "e", @@ -16,7 +16,6 @@ boot_command = [ "debconf/frontend=noninteractive ", "hostname={{.Name}} ", "domain=vagrant ", - "console=ttyS0 ", "" ] http_directory = "distros/debian/12/http/" diff --git a/distros/fedora/39/amd64.pkrvars.hcl b/distros/fedora/39/amd64.pkrvars.hcl index 6c3821c..b7be6a1 100644 --- a/distros/fedora/39/amd64.pkrvars.hcl +++ b/distros/fedora/39/amd64.pkrvars.hcl @@ -6,7 +6,7 @@ iso = { } boot_command = [ "e ", - "net.ifnames=0 biosdevnames=0 inst.ks=cdrom:/amd64-ks.cfg inst.notmux console=ttyS0" + "net.ifnames=0 biosdevnames=0 inst.ks=cdrom:/amd64-ks.cfg inst.notmux " ] cd_files = [ "distros/fedora/39/*.cfg" diff --git a/distros/fedora/40/amd64.pkrvars.hcl b/distros/fedora/40/amd64.pkrvars.hcl index 76fd884..a2e322a 100644 --- a/distros/fedora/40/amd64.pkrvars.hcl +++ b/distros/fedora/40/amd64.pkrvars.hcl @@ -6,7 +6,7 @@ iso = { } boot_command = [ "e ", - "net.ifnames=0 biosdevnames=0 inst.ks=cdrom:/amd64-ks.cfg inst.notmux console=ttyS0" + "net.ifnames=0 biosdevnames=0 inst.ks=cdrom:/amd64-ks.cfg inst.notmux " ] cd_files = [ "distros/fedora/40/*.cfg" diff --git a/distros/fedora/rawhide/amd64.pkrvars.hcl.sh b/distros/fedora/rawhide/amd64.pkrvars.hcl.sh index fa06d83..a6be8b2 100755 --- a/distros/fedora/rawhide/amd64.pkrvars.hcl.sh +++ b/distros/fedora/rawhide/amd64.pkrvars.hcl.sh @@ -35,7 +35,7 @@ iso = { } boot_command = [ "e", - "net.ifnames=0 biosdevnames=0 inst.ks=cdrom:/amd64-ks.cfg inst.notmux console=ttyS0" + "net.ifnames=0 biosdevnames=0 inst.ks=cdrom:/amd64-ks.cfg inst.notmux " ] cd_files = [ "distros/fedora/rawhide/*.cfg" diff --git a/distros/nixos/24.05/amd64.pkrvars.hcl.sh b/distros/nixos/24.05/amd64.pkrvars.hcl.sh new file mode 100755 index 0000000..3939820 --- /dev/null +++ b/distros/nixos/24.05/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.05" + +# 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.05/finalize.sh b/distros/nixos/24.05/finalize.sh new file mode 100644 index 0000000..4cfad53 --- /dev/null +++ b/distros/nixos/24.05/finalize.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +set -ex diff --git a/distros/nixos/24.05/http/configuration.nix b/distros/nixos/24.05/http/configuration.nix new file mode 100644 index 0000000..2cc98aa --- /dev/null +++ b/distros/nixos/24.05/http/configuration.nix @@ -0,0 +1,67 @@ +{config, pkgs, lib, ...}: + +{ + imports = [ + ./hardware-configuration.nix + ./guest-agent.nix + ]; + + system.stateVersion = "24.05"; + + # 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 = { + package = pkgs.nixFlakes; + settings = { + experimental-features = "nix-command flakes"; + }; + }; +} diff --git a/distros/nixos/24.05/http/flake.nix b/distros/nixos/24.05/http/flake.nix new file mode 100644 index 0000000..f8b0e18 --- /dev/null +++ b/distros/nixos/24.05/http/flake.nix @@ -0,0 +1,15 @@ +{ + description = "A basic NixOS Vagrant install"; + + inputs = { + nixstable.url = "github:nixos/nixpkgs/nixos-24.05"; + }; + + outputs = { nixstable, self, ... }@inputs: + { + nixosConfigurations.vagrant = nixstable.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ ./configuration.nix ]; + }; + }; +} diff --git a/distros/nixos/24.05/http/ga-kvm.nix b/distros/nixos/24.05/http/ga-kvm.nix new file mode 120000 index 0000000..15276b3 --- /dev/null +++ b/distros/nixos/24.05/http/ga-kvm.nix @@ -0,0 +1 @@ +ga-qemu.nix \ No newline at end of file diff --git a/distros/nixos/24.05/http/ga-microsoft.nix b/distros/nixos/24.05/http/ga-microsoft.nix new file mode 100644 index 0000000..a477797 --- /dev/null +++ b/distros/nixos/24.05/http/ga-microsoft.nix @@ -0,0 +1,4 @@ +{...}: +{ + virtualisation.hypervGuest.enable = true; +} \ No newline at end of file diff --git a/distros/nixos/24.05/http/ga-oracle.nix b/distros/nixos/24.05/http/ga-oracle.nix new file mode 100644 index 0000000..6f304b0 --- /dev/null +++ b/distros/nixos/24.05/http/ga-oracle.nix @@ -0,0 +1,6 @@ +{...}: +{ + virtualisation.virtualbox.guest = { + enable = true; + }; +} diff --git a/distros/nixos/24.05/http/ga-qemu.nix b/distros/nixos/24.05/http/ga-qemu.nix new file mode 100644 index 0000000..7389b6d --- /dev/null +++ b/distros/nixos/24.05/http/ga-qemu.nix @@ -0,0 +1,4 @@ +{...}: +{ + services.qemuGuest.enable = true; +} \ No newline at end of file diff --git a/distros/nixos/24.05/http/ga-vmware.nix b/distros/nixos/24.05/http/ga-vmware.nix new file mode 100644 index 0000000..8599f81 --- /dev/null +++ b/distros/nixos/24.05/http/ga-vmware.nix @@ -0,0 +1,7 @@ +{...}: +{ + virtualisation.vmware.guest = { + enable = true; + headless = false; + } +} \ No newline at end of file diff --git a/distros/nixos/24.05/http/in-chroot.sh b/distros/nixos/24.05/http/in-chroot.sh new file mode 100644 index 0000000..60c21f1 --- /dev/null +++ b/distros/nixos/24.05/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.05/http/install.sh b/distros/nixos/24.05/http/install.sh new file mode 100644 index 0000000..abd1c6c --- /dev/null +++ b/distros/nixos/24.05/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 \ No newline at end of file diff --git a/distros/nixos/24.05/qemu.sh b/distros/nixos/24.05/qemu.sh new file mode 100644 index 0000000..087d718 --- /dev/null +++ b/distros/nixos/24.05/qemu.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +set -ex \ No newline at end of file diff --git a/distros/nixos/24.05/virtualbox.sh b/distros/nixos/24.05/virtualbox.sh new file mode 100644 index 0000000..087d718 --- /dev/null +++ b/distros/nixos/24.05/virtualbox.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +set -ex \ No newline at end of file diff --git a/distros/nixos/24.05/vmware.sh b/distros/nixos/24.05/vmware.sh new file mode 100644 index 0000000..087d718 --- /dev/null +++ b/distros/nixos/24.05/vmware.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +set -ex \ No newline at end of file diff --git a/distros/nixos/default.nix b/distros/nixos/default.nix index f9e89b8..e4294ff 100644 --- a/distros/nixos/default.nix +++ b/distros/nixos/default.nix @@ -6,4 +6,8 @@ version = "23.11"; arch = "amd64"; eol = false; +} { + version = "24.05"; + arch = "amd64"; + eol = false; } ] diff --git a/distros/opensuse/15.5/amd64.pkrvars.hcl b/distros/opensuse/15.5/amd64.pkrvars.hcl index ce2b718..4132d37 100644 --- a/distros/opensuse/15.5/amd64.pkrvars.hcl +++ b/distros/opensuse/15.5/amd64.pkrvars.hcl @@ -1,15 +1,14 @@ distro = "opensuse" version = "15.5" iso = { - url = "https://download.opensuse.org/distribution/leap/15.5/iso/openSUSE-Leap-15.5-NET-x86_64-Media.iso" - checksum = "a2f7f2f1b6b3d3ef96f5c8f804d87ebd01e5cf982357c533f4c39c33cd20ec56" + url = "http://download.opensuse.org/distribution/leap/15.5/iso/openSUSE-Leap-15.5-DVD-x86_64-Current.iso" + checksum = "53bcbcb82361c5261c9d0994ab0f94101bf28e61c06fe12d320984601be35a8f" } boot_command = [ "e", "", "", " autoyast=http://{{ .HTTPIP }}:{{ .HTTPPort }}/autoinst.xml textmode=1", - " console=ttyS0", "x" ] http_directory = "distros/opensuse/15.5/http/" diff --git a/distros/opensuse/15.6/amd64.pkrvars.hcl b/distros/opensuse/15.6/amd64.pkrvars.hcl index 8e158a1..0032d71 100644 --- a/distros/opensuse/15.6/amd64.pkrvars.hcl +++ b/distros/opensuse/15.6/amd64.pkrvars.hcl @@ -1,15 +1,14 @@ distro = "opensuse" version = "15.6" iso = { - url = "https://download.opensuse.org/distribution/leap/15.6/iso/openSUSE-Leap-15.6-NET-x86_64-Media.iso" - checksum = "4631636c43297951f1a0a3a2a804e30f4bf1790f892d0f0ac46f62ec82ac2075" + url = "https://download.opensuse.org/distribution/leap/15.6/iso/openSUSE-Leap-15.6-DVD-x86_64-Current.iso" + checksum = "a74d4072e639c75ca127df3d869c1e57bcc44a093a969550f348a3ead561fe4f" } boot_command = [ "e", "", "", " autoyast=http://{{ .HTTPIP }}:{{ .HTTPPort }}/autoinst.xml textmode=1", - " console=ttyS0", "x" ] http_directory = "distros/opensuse/15.6/http/" diff --git a/distros/opensuse/default.nix b/distros/opensuse/default.nix index 01de93d..d8245ba 100644 --- a/distros/opensuse/default.nix +++ b/distros/opensuse/default.nix @@ -2,6 +2,10 @@ version = "15.5"; arch = "amd64"; eol = false; +} { + version = "15.6"; + arch = "amd64"; + eol = false; } { version = "tumbleweed"; arch = "amd64"; diff --git a/distros/opensuse/tumbleweed/amd64.pkrvars.hcl.sh b/distros/opensuse/tumbleweed/amd64.pkrvars.hcl.sh index 9a6fe9c..191c91b 100755 --- a/distros/opensuse/tumbleweed/amd64.pkrvars.hcl.sh +++ b/distros/opensuse/tumbleweed/amd64.pkrvars.hcl.sh @@ -26,7 +26,6 @@ boot_command = [ "e", "", " autoyast=http://{{ .HTTPIP }}:{{ .HTTPPort }}/autoinst.xml textmode=1", - " console=ttyS0", "x" ] http_directory = "distros/opensuse/tumbleweed/http/" diff --git a/distros/rockylinux/9/amd64.pkrvars.hcl b/distros/rockylinux/9/amd64.pkrvars.hcl index 12da5e9..3d7f316 100644 --- a/distros/rockylinux/9/amd64.pkrvars.hcl +++ b/distros/rockylinux/9/amd64.pkrvars.hcl @@ -8,7 +8,7 @@ boot_command = [ "e", "", " inst.text inst.ks=cdrom:/ks.cfg", - " inst.notmux console=ttyS0", + " inst.notmux ", "x" ] cd_files = [ "distros/rockylinux/9/disc/*" ] diff --git a/distros/ubuntu/20.04/amd64.pkrvars.hcl b/distros/ubuntu/20.04/amd64.pkrvars.hcl index a95048e..406e681 100644 --- a/distros/ubuntu/20.04/amd64.pkrvars.hcl +++ b/distros/ubuntu/20.04/amd64.pkrvars.hcl @@ -7,7 +7,6 @@ iso = { boot_wait = "3s" boot_command = [ "e", - "console=ttyS0 ", "fsck.mode=skip ", "locale=en_US ", "auto=true ", diff --git a/distros/ubuntu/22.04/amd64.pkrvars.hcl b/distros/ubuntu/22.04/amd64.pkrvars.hcl index 51baf9b..e4f5b04 100644 --- a/distros/ubuntu/22.04/amd64.pkrvars.hcl +++ b/distros/ubuntu/22.04/amd64.pkrvars.hcl @@ -6,7 +6,6 @@ iso = { } boot_command = [ "e", - "console=ttyS0 ", "fsck.mode=skip ", "locale=en_US ", "auto=true ", diff --git a/distros/ubuntu/23.10/amd64.pkrvars.hcl b/distros/ubuntu/23.10/amd64.pkrvars.hcl index 59d3759..00aeb9b 100644 --- a/distros/ubuntu/23.10/amd64.pkrvars.hcl +++ b/distros/ubuntu/23.10/amd64.pkrvars.hcl @@ -6,7 +6,6 @@ iso = { } boot_command = [ "e", - "console=ttyS0 ", "fsck.mode=skip ", "locale=en_US ", "auto=true ", diff --git a/distros/ubuntu/24.04/amd64.pkrvars.hcl b/distros/ubuntu/24.04/amd64.pkrvars.hcl new file mode 100644 index 0000000..e99de25 --- /dev/null +++ b/distros/ubuntu/24.04/amd64.pkrvars.hcl @@ -0,0 +1,19 @@ +distro = "ubuntu" +version = "24.04" +iso = { + url = "http://releases.ubuntu.com/24.04/ubuntu-24.04-live-server-amd64.iso" + checksum = "8762f7e74e4d64d72fceb5f70682e6b069932deedb4949c6975d0f0fe0a91be3" +} +boot_command = [ + "e", + "fsck.mode=skip ", + "locale=en_US ", + "auto=true ", + "priority=critical ", + "autoinstall", + "", +] +cd_files = [ + "distros/ubuntu/24.04/disc/*" +] +vbox_os_type = "Ubuntu24_64" diff --git a/distros/ubuntu/24.04/disc/meta-data b/distros/ubuntu/24.04/disc/meta-data new file mode 100644 index 0000000..e69de29 diff --git a/distros/ubuntu/24.04/disc/user-data b/distros/ubuntu/24.04/disc/user-data new file mode 100644 index 0000000..4b96996 --- /dev/null +++ b/distros/ubuntu/24.04/disc/user-data @@ -0,0 +1,47 @@ +#cloud-config +# vim: set ft=yaml: +autoinstall: + version: 1 + network: # Should disable networking, workaround for unattended-updates failing in install + version: 2 + ethernets: + eth0: + match: + name: e* + dhcp4: yes + dhcp6: no + refresh-installer: + update: no + keyboard: + layout: us + toggle: null + variant: '' + locale: en_US.UTF-8 + identity: + hostname: vagrant + username: vagrant + password: $6$rounds=4096$mJTRlY/vwPMquLe0$s4Ld3ZnvF.pM86xzbAgQD7Xpi/NMVgyQNb5CEfabFgL6nLRsP56WtwA.o.Jg/xC6HaJmM2p5fCGIo37jmKVRI0 + ssh: + install-server: yes + authorized_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key + allow-pw: yes + user-data: + disable_root: false + package_update: false + package_upgrade: false + late-commands: + - echo 'Defaults:vagrant !requiretty' > /target/etc/sudoers.d/vagrant + - echo 'vagrant ALL=(ALL) NOPASSWD:ALL' >> /target/etc/sudoers.d/vagrant + - chmod 440 /target/etc/sudoers.d/vagrant + - >- + curtin in-target --target=/target -- + bash -c 'if [ "$(systemd-detect-virt)" == "microsoft" ]; then + apt-get update; + apt-get install -y linux-azure; + fi' + - curtin in-target --target=/target -- logger "finished late-commands" + packages: + - ca-certificates + - curl + - sudo diff --git a/distros/ubuntu/24.04/finalize.sh b/distros/ubuntu/24.04/finalize.sh new file mode 100644 index 0000000..f79a717 --- /dev/null +++ b/distros/ubuntu/24.04/finalize.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -ex + +apt remove cloud-init -y + +apt update +apt upgrade -y + +# Make sshd faster +cat << EOF > /etc/ssh/sshd_config.d/00-vagrant_accept_pubkey.conf +UseDNS no +PubkeyAcceptedKeyTypes +ssh-rsa +EOF + +# Clean up after ourselves +apt-get clean diff --git a/distros/ubuntu/24.04/qemu.sh b/distros/ubuntu/24.04/qemu.sh new file mode 100644 index 0000000..4ef2dee --- /dev/null +++ b/distros/ubuntu/24.04/qemu.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -ex + +apt install -y qemu-guest-agent +systemctl start qemu-guest-agent +systemctl enable qemu-guest-agent diff --git a/distros/ubuntu/24.04/virtualbox.sh b/distros/ubuntu/24.04/virtualbox.sh new file mode 100644 index 0000000..2813d68 --- /dev/null +++ b/distros/ubuntu/24.04/virtualbox.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -ex + +apt install -y virtualbox-guest-utils diff --git a/distros/ubuntu/24.04/vmware.sh b/distros/ubuntu/24.04/vmware.sh new file mode 100644 index 0000000..9560300 --- /dev/null +++ b/distros/ubuntu/24.04/vmware.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -ex + +apt install -y open-vm-tools diff --git a/distros/ubuntu/default.nix b/distros/ubuntu/default.nix index c0643db..a45aa86 100644 --- a/distros/ubuntu/default.nix +++ b/distros/ubuntu/default.nix @@ -14,4 +14,8 @@ version = "23.10"; arch = "amd64"; eol = false; +} { + version = "24.04"; + arch = "amd64"; + eol = false; } ] diff --git a/flake.lock b/flake.lock index 45463b6..4e87450 100644 --- a/flake.lock +++ b/flake.lock @@ -100,11 +100,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1718870667, - "narHash": "sha256-jab3Kpc8O1z3qxwVsCMHL4+18n5Wy/HHKyu1fcsF7gs=", + "lastModified": 1720750130, + "narHash": "sha256-y2wc7CdK0vVSIbx7MdVoZzuMcUoLvZXm+pQf2RIr1OU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9b10b8f00cb5494795e5f51b39210fed4d2b0748", + "rev": "6794d064edc69918bb0fc0e0eda33ece324be17a", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 0febf82..4912db9 100644 --- a/flake.nix +++ b/flake.nix @@ -30,6 +30,11 @@ name = d: "-${d.distro}-${d.arch}-${d.provider}-${d.version}"; distroFile = d: "distros/${d.distro}/${d.version}/${d.arch}.pkrvars.hcl"; cmd = d: '' + # This is a workaround for a goofy behavior in CI + if [ -e "''${PACKER_CONFIG_DIR}" ]; then + find "''${PACKER_CONFIG_DIR}" -name '*_linux_amd64' -exec chmod +x '{}' ";" + fi + packer init sources version="''${1:-1}" packer build -var "build=$version" -only=${d.provider}.${d.arch} -var-file=${distroFile d}''; in flake-parts.lib.mkFlake { inherit inputs; } @@ -80,7 +85,10 @@ env = [{ name = "EFI_DIR"; value = "${pkgs.OVMF.fd}/FV/"; - }]; + } { + name = "PACKER_CONFIG_DIR"; + value = "./packer_config"; + } ]; }; # This is not special, this is just flakes @@ -88,6 +96,7 @@ base = { runtimeInputs = with pkgs; [ packer + findutils qemu_full vagrant ]; @@ -105,24 +114,33 @@ vagrant box add --provider ${vp d} ./output/${vp d}/${d.distro}-${d.version}.box --name test_box --force ''; }); + cibuild = d: pkgs.writeShellApplication (base // { + name = "ci${name d}"; + text = '' + set -x + ${cmd d} -except=upload sources/ + ''; + }); upload = d: pkgs.writeShellApplication (base // { name = "upload${name d}"; text = '' - set -x - ${cmd d} sources/ + set -x + ${cmd d} sources/ ''; - }); + }); builds = lib.lists.foldr (d: acc: acc // { "build${name d}" = (build d); }) {} withProviders; uploads = lib.lists.foldr (d: acc: acc // { "upload${name d}" = (upload d); }) {} withProviders; - qemu_list = builtins.toJSON (builtins.map (d: { distro = distroFile d; }) (builtins.filter (x: x.provider == "qemu") active)); - vbox_list = builtins.toJSON (builtins.map (d: { distro = distroFile d; }) (builtins.filter (x: x.provider == "virtualbox-iso") active)); + cibuilds = lib.lists.foldr (d: acc: acc // { "ci${name d}" = (cibuild d); }) {} withProviders; + qemu_list = builtins.toJSON (builtins.map (d: { buildcmd = "ci${name d}"; }) (builtins.filter (x: x.provider == "qemu") active)); + vbox_list = builtins.toJSON (builtins.map (d: { buildcmd = "ci${name d}"; }) (builtins.filter (x: x.provider == "virtualbox-iso") active)); hyperv_list = builtins.toJSON (builtins.map (d: { distro = distroFile d; }) (builtins.filter (x: x.provider == "hyperv-iso") active)); - in builds // uploads // { + in builds // uploads // cibuilds // { continue = pkgs.writeText "continue.yml" (builtins.replaceStrings ["QEMU_MATRIX" "VBOX_MATRIX" "HYPERV_MATRIX"] [qemu_list vbox_list hyperv_list] (builtins.readFile ./.gitlab-ci-build.yml.in) ); cache = pkgs.callPackage (import ./nix/cache.nix) { inherit active distroFile; }; + validate = pkgs.callPackage (import ./nix/validate.nix) {}; cache-restore = pkgs.writeShellApplication { name = "cache-restore"; runtimeInputs = with pkgs; [ @@ -161,19 +179,6 @@ shellcheck -e SC2239 "''${scripts[@]}" ''; }; - validate = pkgs.writeShellApplication { - name = "validate"; - runtimeInputs = with pkgs; [ - packer - ]; - text = '' - shopt -s globstar - packer init sources - for vars in distros/**/*.pkrvars.hcl; do - packer validate -except=upload "-var-file=''${vars}" sources/ - done - ''; - }; }; # https://numtide.github.io/treefmt/ diff --git a/nix/cache.nix b/nix/cache.nix index daadc80..4add151 100644 --- a/nix/cache.nix +++ b/nix/cache.nix @@ -29,11 +29,12 @@ in writeShellApplication { map (d: '' url=$(echo var.iso.url | packer console -var-file="${distroFile d}" -config-type=hcl2 sources/) sha=$(echo var.iso.checksum | packer console -var-file="${distroFile d}" -config-type=hcl2 sources/) + distro=$(echo var.distro | packer console -var-file="${distroFile d}" -config-type=hcl2 sources/) # shellcheck disable=SC2143 - if [ -z "$(mc ls storage/isos/cache/ | grep "$sha")" ]; then + if [ -z "$(mc ls "storage/isos/cache/$distro" | grep "$sha")" ]; then curl -L --retry 3 --retry-all-errors -o "cache/$sha.iso" "$url" if [ "$push" == "yes" ]; then - mc put "cache/$sha.iso" "storage/isos/cache/$sha.iso" + mc put "cache/$sha.iso" "storage/isos/cache/$distro/$sha.iso" fi else echo "Skipping ${d.distro} - cache/$sha.iso" diff --git a/nix/validate.nix b/nix/validate.nix new file mode 100644 index 0000000..464fd1e --- /dev/null +++ b/nix/validate.nix @@ -0,0 +1,21 @@ +{ + writeShellApplication, + findutils, + packer, + ... +}: +writeShellApplication { + name = "validate"; + runtimeInputs = [ + findutils + packer + ]; + text = '' + shopt -s globstar + find "''${PACKER_CONFIG_DIR}" -name '*_linux_amd64' -exec chmod +x '{}' ";" + packer init sources + for vars in distros/**/*.pkrvars.hcl; do + packer validate -except=upload "-var-file=''${vars}" sources/ + done + ''; +} diff --git a/sources/build.pkr.hcl b/sources/build.pkr.hcl index 653f54f..69dd485 100644 --- a/sources/build.pkr.hcl +++ b/sources/build.pkr.hcl @@ -2,11 +2,11 @@ packer { required_plugins { qemu = { source = "github.com/hashicorp/qemu" - version = "= 1.0.10" + version = "= 1.1.0" } vagrant = { source = "github.com/hashicorp/vagrant" - version = "= 1.1.1" + version = "= 1.1.4" } vmware = { version = "= 1.0.11" diff --git a/sources/hyperv-iso.pkr.hcl b/sources/hyperv-iso.pkr.hcl index 0ce8ff9..c0798ec 100644 --- a/sources/hyperv-iso.pkr.hcl +++ b/sources/hyperv-iso.pkr.hcl @@ -1,5 +1,5 @@ source "hyperv-iso" "amd64" { - iso_urls = [ "s3::${var.storage_url}/isos/cache/${var.iso.checksum}.iso?aws_access_key_id=root&aws_access_key_secret=${var.minio_secret}" ] + iso_urls = [ local.iso_location ] iso_target_path = "cache/${var.iso.checksum}.iso" iso_checksum = var.iso.checksum output_directory = "output/hyperv/${local.name}" diff --git a/sources/inputs.pkr.hcl b/sources/inputs.pkr.hcl index 7234a1d..864c2ac 100644 --- a/sources/inputs.pkr.hcl +++ b/sources/inputs.pkr.hcl @@ -127,6 +127,7 @@ locals { version = var.version build = var.build }) + iso_location = "s3::${var.storage_url}/isos/cache/${var.distro}/${var.iso.checksum}.iso?aws_access_key_id=root&aws_access_key_secret=${var.minio_secret}" cpus = var.cpus memory = var.memory diff --git a/sources/qemu.pkr.hcl b/sources/qemu.pkr.hcl index d1b82ee..e166897 100644 --- a/sources/qemu.pkr.hcl +++ b/sources/qemu.pkr.hcl @@ -4,7 +4,7 @@ variable "qemu_accelerator" { } source "qemu" "amd64" { - iso_urls = [ "s3::${var.storage_url}/isos/cache/${var.iso.checksum}.iso?aws_access_key_id=root&aws_access_key_secret=${var.minio_secret}" ] + iso_urls = [ local.iso_location ] iso_target_path = "cache/${var.iso.checksum}.iso" iso_checksum = var.iso.checksum output_directory = "output/libvirt/${local.name}" diff --git a/sources/virtualbox-iso.pkr.hcl b/sources/virtualbox-iso.pkr.hcl index e2c9a56..11a2b84 100644 --- a/sources/virtualbox-iso.pkr.hcl +++ b/sources/virtualbox-iso.pkr.hcl @@ -1,5 +1,5 @@ source "virtualbox-iso" "amd64" { - iso_urls = [ "s3::${var.storage_url}/isos/cache/${var.iso.checksum}.iso?aws_access_key_id=root&aws_access_key_secret=${var.minio_secret}" ] + iso_urls = [ local.iso_location ] iso_target_path = "cache/${var.iso.checksum}.iso" iso_checksum = var.iso.checksum output_directory = "output/virtualbox/${local.name}"