home

My NixOS systems configurations.
Log | Files | Refs | LICENSE

commit 80b1b66680c9446466104d2161419a63b99806d1
parent c7efe62a54bfbcf98709a67960dd191203a972ca
Author: Vincent Demeester <vincent@sbr.pm>
Date:   Fri,  1 Dec 2023 16:07:47 +0100

nix/packages: remove unused tools/bus

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Diffstat:
Mnix/packages/default.nix | 1-
Dtools/bus/default.nix | 8--------
Dtools/bus/go.mod | 5-----
Dtools/bus/go.sum | 3---
Dtools/bus/main.go | 127-------------------------------------------------------------------------------
5 files changed, 0 insertions(+), 144 deletions(-)

diff --git a/nix/packages/default.nix b/nix/packages/default.nix @@ -5,7 +5,6 @@ rec { scripts = pkgs.callPackage ./my/scripts { }; vrsync = pkgs.callPackage ./my/vrsync { }; vde-thinkpad = pkgs.callPackage ./my/vde-thinkpad { }; - bus = pkgs.callPackage ../../tools/bus { }; bekind = pkgs.callPackage ../../tools/bekind { }; chmouzies.kubernetes = pkgs.callPackage ./chmouzies/kubernetes.nix { }; diff --git a/tools/bus/default.nix b/tools/bus/default.nix @@ -1,8 +0,0 @@ -{ stdenv, lib, buildGoModule }: - -buildGoModule rec { - name = "bus"; - src = ./.; - - vendorSha256 = "05iqr46pm05jxfcss23cxdqng1wpnqp46v5vyw8f65sq0vsfv4xh"; -} diff --git a/tools/bus/go.mod b/tools/bus/go.mod @@ -1,5 +0,0 @@ -module home/tools/bus - -go 1.14 - -require gopkg.in/yaml.v2 v2.3.0 diff --git a/tools/bus/go.sum b/tools/bus/go.sum @@ -1,3 +0,0 @@ -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/tools/bus/main.go b/tools/bus/main.go @@ -1,127 +0,0 @@ -// bus is a smal CLI tool that triggers home builds on build.sr.ht. -// It is designed to be run in a cron or systemd timer. -package main - -import ( - "bytes" - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "net/http" - "os" - "path/filepath" - "strings" - - yaml "gopkg.in/yaml.v2" -) - -var ( - branch = flag.String("branch", "master", "branch to schedule") - secret = flag.String("secret", "/etc/secrets/srht-token", "path to find sr.ht secret") - builds = flag.String("builds", "/etc/nixos/.builds", "path to find builds manifests") -) - -// Represents a builds.sr.ht build object as described on -// https://man.sr.ht/builds.sr.ht/api.md -type Build struct { - Manifest string `json:"manifest"` - Note string `json:"note"` - Tags []string `json:"tags"` -} - -// Represents a build trigger object as described on <the docs for -// this are currently down> -type Trigger struct { - Action string `json:"action"` - Condition string `json:"condition"` - To string `json:"to"` -} - -// Represents a build manifest for sourcehut. -type Manifest struct { - Image string `json:"image"` - Sources []string `json:"sources"` - Secrets []string `json:"secrets"` - Tasks [](map[string]string) `json:"tasks"` - Triggers []Trigger `json:"triggers"` -} - -func triggerBuild(token, name, manifest, branch string) { - build := Build{ - Manifest: manifest, - Note: fmt.Sprintf("Nightly build of '%s' on '%s'", name, branch), - Tags: []string{ - // my branch names tend to contain slashes, which are not valid - // identifiers in sourcehut. - "home", "nightly", strings.ReplaceAll(branch, "/", "_"), name, - }, - } - - body, _ := json.Marshal(build) - reader := ioutil.NopCloser(bytes.NewReader(body)) - - req, err := http.NewRequest("POST", "https://builds.sr.ht/api/jobs", reader) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to create an HTTP request: %s", err) - os.Exit(1) - } - - req.Header.Add("Authorization", "token "+token) - req.Header.Add("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - // This might indicate a temporary error on the sourcehut side, do - // not fail the whole program. - fmt.Fprintf(os.Stderr, "failed to send build.sr.ht request: %s", err) - return - } - defer resp.Body.Close() - - if resp.StatusCode != 200 { - respBody, _ := ioutil.ReadAll(resp.Body) - fmt.Fprintf(os.Stderr, "received non-success response from builds.sr.ht: %s (%v)", respBody, resp.Status) - os.Exit(1) - } else { - fmt.Fprintf(os.Stdout, "triggered builds.sr.ht job for branch '%s'\n", branch) - } -} - -func prepareManifest(manifest []byte) ([]byte, error) { - var m Manifest - if err := yaml.Unmarshal(manifest, &m); err != nil { - return manifest, err - } - m.Sources = append(m.Sources, "https://git.sr.ht/~vdemeester/home") - return yaml.Marshal(m) -} - -func main() { - flag.Parse() - token, err := ioutil.ReadFile(*secret) - if err != nil { - fmt.Fprint(os.Stderr, "sourcehut token could not be read.") - os.Exit(1) - } - files, err := ioutil.ReadDir(*builds) - if err != nil { - fmt.Fprintf(os.Stderr, "cannot list builds manifest from %s: %v.\n", *builds, err) - os.Exit(1) - } - fmt.Fprintf(os.Stdout, "triggering builds for %v\n", *branch) - for _, f := range files { - path := filepath.Join(*builds, f.Name()) - manifest, err := ioutil.ReadFile(path) - if err != nil { - fmt.Fprintf(os.Stderr, "cannot read manifest %s: %v.\n", path, err) - os.Exit(1) - } - manifest, err = prepareManifest(manifest) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to prepare manifest %s: %v.\n", path, err) - os.Exit(1) - } - triggerBuild(string(token), f.Name(), string(manifest), *branch) - } -}