about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-01T11·47+0100
committerVincent Ambo <mail@tazj.in>2020-07-25T13·43+0100
commit987a90510aca61e429ac659e510cbc51de9ae0bb (patch)
tree0674915104a4ed296e75f7633a7128885fa3bf97
parentb4e0b55e5608ae2b394880e69912d9352fea2d9d (diff)
fix(popcount): Accommodate upstream changes on nixos.org
Channel serving has moved to a new subdomain, and the redirect
semantics have changed. Instead of serving temporary redirects,
permanent redirects are now issued.

I've reported this upstream as a bug, but this workaround will fix it
in the meantime.
-rw-r--r--tools/nixery/popcount/popcount.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/tools/nixery/popcount/popcount.go b/tools/nixery/popcount/popcount.go
index 992a88e874d1..d632090c0dc2 100644
--- a/tools/nixery/popcount/popcount.go
+++ b/tools/nixery/popcount/popcount.go
@@ -70,12 +70,16 @@ func channelMetadata(channel string) meta {
 		},
 	}
 
-	resp, err := c.Get(fmt.Sprintf("https://nixos.org/channels/%s", channel))
+	resp, err := c.Get(fmt.Sprintf("https://channels.nixos.org/%s", channel))
 	failOn(err, "failed to retrieve channel metadata")
 
 	loc, err := resp.Location()
 	failOn(err, "no redirect location given for channel")
-	if resp.StatusCode != 302 {
+
+	// TODO(tazjin): These redirects are currently served as 301s, but
+	// should (and used to) be 302s. Check if/when this is fixed and
+	// update accordingly.
+	if !(resp.StatusCode == 301 || resp.StatusCode == 302) {
 		log.Fatalf("Expected redirect for channel, but received '%s'\n", resp.Status)
 	}
 
@@ -85,6 +89,9 @@ func channelMetadata(channel string) meta {
 	defer commitResp.Body.Close()
 	commit, err := ioutil.ReadAll(commitResp.Body)
 	failOn(err, "failed to read commit from response")
+	if commitResp.StatusCode != 200 {
+		log.Fatalf("non-success status code when fetching commit: %s", string(commit), commitResp.StatusCode)
+	}
 
 	return meta{
 		name:   channel,