From bcef8e52a8ea840fd8d7eecaf72fd69da690815a Mon Sep 17 00:00:00 2001
From: zowoq <59103226+zowoq@users.noreply.github.com>
Date: Tue, 22 Oct 2024 17:58:57 +1000
Subject: [PATCH] terraform/hydra: split and refactor

---
 docs/package-sets.md        |   4 +
 terraform/hydra-nixpkgs.tf  |  94 ++++++++++++++++++++++++
 terraform/hydra-projects.tf | 143 ------------------------------------
 3 files changed, 98 insertions(+), 143 deletions(-)
 create mode 100644 terraform/hydra-nixpkgs.tf

diff --git a/docs/package-sets.md b/docs/package-sets.md
index 238f207..2869e8e 100644
--- a/docs/package-sets.md
+++ b/docs/package-sets.md
@@ -19,3 +19,7 @@ Built on `nixos-$RELEASE-small` for `x86_64-linux`:
 All of the above builds are pushed to the cache.
 
 See [here](./cache.md) for details.
+
+#### Hydra
+
+The hydra configuration for these package sets is managed in this [file](https://github.com/nix-community/infra/blob/master/terraform/hydra-nixpkgs.tf).
diff --git a/terraform/hydra-nixpkgs.tf b/terraform/hydra-nixpkgs.tf
new file mode 100644
index 0000000..2800fcc
--- /dev/null
+++ b/terraform/hydra-nixpkgs.tf
@@ -0,0 +1,94 @@
+locals {
+  jobset = {
+    cuda = {
+      name                 = "cuda"
+      description          = "Testing CUDA support. Come help the CUDA team! https://nixos.org/community/teams/cuda/"
+      nixpkgs_channel      = "https://github.com/NixOS/nixpkgs.git nixos-unstable-small"
+      nixpkgs_release_file = "pkgs/top-level/release-cuda.nix"
+      scheduling_shares    = 6000
+      supported_systems    = "[ \"x86_64-linux\" ]"
+    }
+    cuda_stable = {
+      name                 = "cuda-stable"
+      description          = "Testing CUDA support. Come help the CUDA team! https://nixos.org/community/teams/cuda/"
+      nixpkgs_channel      = "https://github.com/NixOS/nixpkgs.git nixos-24.05-small"
+      nixpkgs_release_file = "pkgs/top-level/release-cuda.nix"
+      scheduling_shares    = 6000
+      supported_systems    = "[ \"x86_64-linux\" ]"
+    }
+    rocm = {
+      name                 = "rocm"
+      description          = "Testing ROCm support."
+      nixpkgs_channel      = "https://github.com/NixOS/nixpkgs.git nixos-unstable-small"
+      nixpkgs_release_file = "pkgs/top-level/release-cuda.nix"
+      scheduling_shares    = 6000
+      supported_systems    = "[ \"x86_64-linux\" ]"
+      variant              = "rocm"
+    }
+  }
+}
+
+resource "hydra_jobset" "nixpkgs_jobset" {
+  for_each = local.jobset
+
+  project     = hydra_project.nixpkgs.name
+  state       = "enabled"
+  visible     = true
+  name        = each.value.name
+  type        = "legacy"
+  description = each.value.description
+
+  nix_expression {
+    file  = each.value.nixpkgs_release_file
+    input = "nixpkgs"
+  }
+
+  input {
+    name              = "nixpkgs"
+    type              = "git"
+    value             = each.value.nixpkgs_channel
+    notify_committers = false
+  }
+
+  dynamic "input" {
+    for_each = [for variant in [lookup(each.value, "variant", null)] : variant if variant != null]
+
+    content {
+      name              = "variant"
+      type              = "string"
+      value             = input.value
+      notify_committers = false
+    }
+  }
+
+  input {
+    name              = "officialRelease"
+    type              = "boolean"
+    value             = "false"
+    notify_committers = false
+  }
+
+  input {
+    name              = "supportedSystems"
+    type              = "nix"
+    value             = each.value.supported_systems
+    notify_committers = false
+  }
+
+  check_interval    = 1800
+  scheduling_shares = each.value.scheduling_shares
+  keep_evaluations  = 1
+
+  email_notifications = false
+  email_override      = ""
+}
+
+resource "hydra_project" "nixpkgs" {
+  name         = "nixpkgs"
+  display_name = "nixpkgs"
+  description  = "you know what this is"
+  homepage     = "https://github.com/NixOS/nixpkgs"
+  owner        = "admin"
+  enabled      = true
+  visible      = true
+}
diff --git a/terraform/hydra-projects.tf b/terraform/hydra-projects.tf
index 1d0b7b1..5f42ab9 100644
--- a/terraform/hydra-projects.tf
+++ b/terraform/hydra-projects.tf
@@ -69,146 +69,3 @@ resource "hydra_project" "simple_nixos_mailserver" {
     value = "https://gitlab.com/simple-nixos-mailserver/nixos-mailserver"
   }
 }
-
-resource "hydra_project" "nixpkgs" {
-  name         = "nixpkgs"
-  display_name = "nixpkgs"
-  description  = "you know what this is"
-  homepage     = "https://github.com/NixOS/nixpkgs"
-  owner        = "admin"
-  enabled      = true
-  visible      = true
-}
-
-resource "hydra_jobset" "nixpkgs_cuda" {
-  project     = hydra_project.nixpkgs.name
-  state       = "enabled"
-  visible     = true
-  name        = "cuda"
-  type        = "legacy"
-  description = "Testing CUDA support. Come help the CUDA team! https://nixos.org/community/teams/cuda/"
-
-  nix_expression {
-    file  = "pkgs/top-level/release-cuda.nix"
-    input = "nixpkgs"
-  }
-
-  input {
-    name              = "nixpkgs"
-    type              = "git"
-    value             = "https://github.com/NixOS/nixpkgs.git nixos-unstable-small"
-    notify_committers = false
-  }
-
-  input {
-    name              = "officialRelease"
-    type              = "boolean"
-    value             = "false"
-    notify_committers = false
-  }
-
-  input {
-    name              = "supportedSystems"
-    type              = "nix"
-    value             = "[ \"x86_64-linux\" ]"
-    notify_committers = false
-  }
-
-  check_interval    = 1800
-  scheduling_shares = 6000
-  keep_evaluations  = 1
-
-  email_notifications = false
-  email_override      = ""
-}
-
-resource "hydra_jobset" "nixpkgs_cuda_stable" {
-  project     = hydra_project.nixpkgs.name
-  state       = "enabled"
-  visible     = true
-  name        = "cuda-stable"
-  type        = "legacy"
-  description = "Testing CUDA support. Come help the CUDA team! https://nixos.org/community/teams/cuda/"
-
-  nix_expression {
-    file  = "pkgs/top-level/release-cuda.nix"
-    input = "nixpkgs"
-  }
-
-  input {
-    name              = "nixpkgs"
-    type              = "git"
-    value             = "https://github.com/NixOS/nixpkgs.git nixos-24.05-small"
-    notify_committers = false
-  }
-
-  input {
-    name              = "officialRelease"
-    type              = "boolean"
-    value             = "false"
-    notify_committers = false
-  }
-
-  input {
-    name              = "supportedSystems"
-    type              = "nix"
-    value             = "[ \"x86_64-linux\" ]"
-    notify_committers = false
-  }
-
-  check_interval    = 1800
-  scheduling_shares = 6000
-  keep_evaluations  = 1
-
-  email_notifications = false
-  email_override      = ""
-}
-
-resource "hydra_jobset" "nixpkgs_rocm" {
-  project     = hydra_project.nixpkgs.name
-  state       = "enabled"
-  visible     = true
-  name        = "rocm"
-  type        = "legacy"
-  description = "Testing ROCm support."
-
-  nix_expression {
-    file  = "pkgs/top-level/release-cuda.nix"
-    input = "nixpkgs"
-  }
-
-  input {
-    name              = "variant"
-    type              = "string"
-    value             = "rocm"
-    notify_committers = false
-  }
-
-  input {
-    name              = "nixpkgs"
-    type              = "git"
-    value             = "https://github.com/NixOS/nixpkgs.git nixos-unstable-small"
-    notify_committers = false
-  }
-
-  input {
-    name              = "officialRelease"
-    type              = "boolean"
-    value             = "false"
-    notify_committers = false
-  }
-
-  input {
-    name              = "supportedSystems"
-    type              = "nix"
-    value             = "[ \"x86_64-linux\" ]"
-    notify_committers = false
-  }
-
-  check_interval    = 1800
-  scheduling_shares = 6000
-  keep_evaluations  = 1
-
-  email_notifications = false
-  email_override      = ""
-}