From 4dd414cc099452e954bfb26b2efc310befae506f Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Sat, 13 Jul 2024 03:03:14 -0500 Subject: [PATCH] Use nix to do builds --- .gitlab-ci-build.yml.in | 21 +++++++++------------ .gitlab-ci.yml | 2 -- flake.lock | 6 +++--- flake.nix | 8 ++++++-- nix/validate.nix | 3 +++ 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.gitlab-ci-build.yml.in b/.gitlab-ci-build.yml.in index 4a13b3a..32c6f12 100644 --- a/.gitlab-ci-build.yml.in +++ b/.gitlab-ci-build.yml.in @@ -31,19 +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: - - find "${PACKER_CONFIG_DIR}" -name '*_linux_amd64' -exec chmod +x '{}' ";" - - packer init sources - - echo $COMMAND > build.sh - - bash build.sh || exit 1 + - nix run ".#${buildcmd}" || exit 1 qemu.amd64: extends: .build @@ -69,6 +58,14 @@ 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: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ce8d844..5ce6a85 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -45,8 +45,6 @@ validate: - sources/build.pkr.hcl paths: - ./packer_config/ - before_script: - - find "${PACKER_CONFIG_DIR}" -name '*_linux_amd64' -exec chmod +x '{}' ";" script: nix run ".#validate" # Makes sure that all of the ISO files we are looking for are 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 0e65b30..c06936e 100644 --- a/flake.nix +++ b/flake.nix @@ -30,6 +30,9 @@ 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 + find "''${PACKER_CONFIG_DIR}" -name '*_linux_amd64' -exec chmod +x '{}' ";" + 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; } @@ -88,6 +91,7 @@ base = { runtimeInputs = with pkgs; [ packer + findutils qemu_full vagrant ]; @@ -114,8 +118,8 @@ }); 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)); + qemu_list = builtins.toJSON (builtins.map (d: { buildcmd = "build${name d}"; }) (builtins.filter (x: x.provider == "qemu") active)); + vbox_list = builtins.toJSON (builtins.map (d: { buildcmd = "build${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 // { continue = pkgs.writeText "continue.yml" diff --git a/nix/validate.nix b/nix/validate.nix index 4159f80..13b9224 100644 --- a/nix/validate.nix +++ b/nix/validate.nix @@ -1,15 +1,18 @@ { 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/