Gitlab CI support added, in order to pre-cache build results in Minio.

This commit is contained in:
Greg Hellings
2025-02-04 13:50:04 +00:00
parent 57269935b0
commit 868e86cc6d
10 changed files with 162 additions and 6 deletions
+2 -1
View File
@@ -10,9 +10,10 @@ in
aacs = c ./aacs.nix { };
brew = c ./homebrew.nix { };
create_ssl = c ./create_ssl.nix { };
gen-build = c ./gen-build { };
hms = c ./hms { };
inject-darwin = c ./inject-darwin.nix { };
inject = c ./inject.nix { };
hms = c ./hms { };
qemu-hook = c ./qemu-hook.nix { };
setup-ssh = c ./setup-ssh { };
upgrade-pg-cluster = c ./upgrade-pg-cluster.nix { };
+14
View File
@@ -0,0 +1,14 @@
{
buildGoModule,
}:
let
src = ./.;
in
buildGoModule {
inherit src;
name = "gen-build";
vendorHash = "sha256-g+yaVIx4jxpAQ/+WrGKxhVeliYx7nLQe/zsGpxV4Fn4=";
meta.mainProgram = "main";
}
+109
View File
@@ -0,0 +1,109 @@
package main
import (
"encoding/json"
"fmt"
"os/exec"
"gopkg.in/yaml.v3"
)
type NixFlakeOutput struct {
Apps map[string]interface{} `json:"apps"`
Checks map[string]interface{} `json:"checks"`
DarwinConfigurations ArchTypes `json:"darwinConfigurations"`
DevShells map[string]interface{} `json:"devShells"`
HomeConfigurations map[string]interface{} `json:"homeConfigurations"`
NixosConfigurations map[string]interface{} `json:"nixosConfigurations"`
Packages ArchTypes `json:"packages"`
}
type ArchTypes struct {
X86_64 map[string]map[string]string `json:"x86_64-linux"`
Aarch64 map[string]map[string]string `json:"aarch64-linux"`
DarwinX86 map[string]map[string]string `json:"x86_64-darwin"`
DarwinArm map[string]map[string]string `json:"aarch64-darwin"`
}
func GetNixFlakeOutput() (*NixFlakeOutput, error) {
cmd := exec.Command("nix", "flake", "show", "--json")
output, err := cmd.Output()
if err != nil {
return nil, err
}
var flakeOutput NixFlakeOutput
err = json.Unmarshal(output, &flakeOutput)
if err != nil {
return nil, err
}
return &flakeOutput, nil
}
type GitlabCIJob struct {
Stage string `json:"stage"`
Tags []string `json:"tags"`
Script []string `json:"script"`
}
func NewGitlabCIJob(target string) GitlabCIJob {
return GitlabCIJob{
Stage: "build",
Tags: []string{"nix"},
Script: []string{
"nix build -L '.#" + target + "'",
},
}
}
func main() {
flakeOutput, err := GetNixFlakeOutput()
if err != nil {
panic(err)
}
// Some boilerplate that Go requires us to have
pipeline := make(map[string]interface{})
pipeline["stages"] = []string{"build"}
pipeline["Run flake check"] = GitlabCIJob{
Stage: "build",
Tags: []string{"nix"},
Script: []string{
"nix flake check --no-build",
},
}
// Since this is kinda a one-off thing, I can use this directly
// homeConfigurations are treated like they are not known as a
// flake output type. Therefore, it just informs you that it is
// part of the output, but does not evaluate deeper to tell you
// what the name of it is. I will just do this manually for now.
pipeline["Build Home config "] = NewGitlabCIJob("homeConfigurations.\"gregory.hellings\".activationPackage")
if flakeOutput.Apps != nil {
for appName := range flakeOutput.Apps {
pipeline[appName] = NewGitlabCIJob("apps." + appName)
}
}
if flakeOutput.Packages.X86_64 != nil {
for pkgName := range flakeOutput.Packages.X86_64 {
if flakeOutput.Packages.X86_64[pkgName]["type"] == "derivation" {
pipeline["Build package "+pkgName] = NewGitlabCIJob("packages.x86_64-linux." + pkgName)
}
}
}
if flakeOutput.NixosConfigurations != nil {
for configName := range flakeOutput.NixosConfigurations {
pipeline["Build NixOS config "+configName] = NewGitlabCIJob("nixosConfigurations." + configName + ".config.system.build.toplevel")
}
}
yamlData, err := yaml.Marshal(pipeline)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", yamlData)
}
+5
View File
@@ -0,0 +1,5 @@
module main
go 1.23.4
require gopkg.in/yaml.v3 v3.0.1
+4
View File
@@ -0,0 +1,4 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=