Skip to content

Commit

Permalink
Add update-nixpkgs.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
evenbrenden committed Dec 15, 2022
1 parent 21a895d commit c3474e7
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions update-nixpkgs.rb
@@ -0,0 +1,36 @@
#! /usr/bin/env nix-shell
#! nix-shell -p curl cacert ruby -i ruby --pure

require 'time'

CHANNEL = "nixos-22.05"
AT_LEAST_DAYS_OLD = 21
HASH_FILE = "nixpkgs.hash"

threshold = (DateTime.now - AT_LEAST_DAYS_OLD).to_time.to_i

# Download history
history_lines = `curl -s https://channels.nix.gsc.io/#{CHANNEL}/history`.split("\n")

class Release
attr_reader :sha, :epoch
def initialize(s)
@sha, epoch_str = s.split(" ")
@epoch = epoch_str.to_i
end
def to_s
[@sha, @epoch].to_s
end
end

release = history_lines
.map { |line| Release.new(line) }
.sort_by { |t| t.epoch }
.reverse
.find { |t| t.epoch < threshold }

puts "Picked first release older than #{AT_LEAST_DAYS_OLD} days: #{release.sha} (#{Time.at(release.epoch)})"

File.open(HASH_FILE, "w") do |file|
file.print release.sha
end

0 comments on commit c3474e7

Please sign in to comment.