From ddf4347dc4f86e92437d61bc6812595166306972 Mon Sep 17 00:00:00 2001 From: Richie Cahill Date: Thu, 2 Jul 2026 14:07:55 -0400 Subject: [PATCH] refactor(ci): auto-discover nixosConfigurations from systems directory Replace the hardcoded list of systems in flake.nix with automatic discovery of host directories under ./systems, and generate the CI build matrix dynamically by evaluating nixosConfigurations rather than maintaining a duplicate list in the workflow. --- .github/workflows/build_systems.yml | 22 ++++++++++---- flake.nix | 45 +++++++++-------------------- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/.github/workflows/build_systems.yml b/.github/workflows/build_systems.yml index 71cedf1..6db5d55 100644 --- a/.github/workflows/build_systems.yml +++ b/.github/workflows/build_systems.yml @@ -8,16 +8,28 @@ on: - cron: "0 22 * * *" jobs: + matrix: + name: generate-matrix + runs-on: self-hosted + outputs: + systems: ${{ steps.systems.outputs.systems }} + steps: + - uses: actions/checkout@v4 + - name: Collect nixosConfigurations + id: systems + run: | + systems="$(nix eval --accept-flake-config --json \ + '.#nixosConfigurations' \ + --apply 'builtins.attrNames')" + echo "systems=$systems" >> "$GITHUB_OUTPUT" + build: name: build-${{ matrix.system }} + needs: matrix runs-on: self-hosted strategy: matrix: - system: - - "bob" - - "brain" - - "jeeves" - - "rhapsody-in-green" + system: ${{ fromJSON(needs.matrix.outputs.systems) }} continue-on-error: true steps: - uses: actions/checkout@v4 diff --git a/flake.nix b/flake.nix index 6d8a1d2..21ac018 100644 --- a/flake.nix +++ b/flake.nix @@ -95,37 +95,18 @@ } ); - nixosConfigurations = { - bob = lib.nixosSystem { - modules = [ - ./systems/bob - ]; - specialArgs = { inherit inputs outputs; }; - }; - brain = lib.nixosSystem { - modules = [ - ./systems/brain - ]; - specialArgs = { inherit inputs outputs; }; - }; - jeeves = lib.nixosSystem { - modules = [ - ./systems/jeeves - ]; - specialArgs = { inherit inputs outputs; }; - }; - rhapsody-in-green = lib.nixosSystem { - modules = [ - ./systems/rhapsody-in-green - ]; - specialArgs = { inherit inputs outputs; }; - }; - iso = lib.nixosSystem { - modules = [ - ./systems/iso - ]; - specialArgs = { inherit inputs outputs; }; - }; - }; + nixosConfigurations = + let + hosts = builtins.attrNames ( + lib.filterAttrs (_: type: type == "directory") (builtins.readDir ./systems) + ); + mkHost = + name: + lib.nixosSystem { + modules = [ ./systems/${name} ]; + specialArgs = { inherit inputs outputs; }; + }; + in + lib.genAttrs hosts mkHost; }; }