Say when a newer NixOS release is out
router-upgrade releases asks the channel server which stable releases exist (daily timer, and on every check). The Overview and Packages pages tell a router that follows a stable release when a newer one is out, and offer the newest two releases as channels instead of a fixed list. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -150,29 +151,106 @@ var upgradeTitles = map[string]string{
|
||||
type channelChoice struct{ Value, Label string }
|
||||
|
||||
type upgradeData struct {
|
||||
Version string // the running NixOS version
|
||||
Channel string
|
||||
Choices []channelChoice
|
||||
Check *UpgradeCheck
|
||||
Preview *UpgradePreview
|
||||
Run UpgradeRun
|
||||
Title string // what the running step does
|
||||
Updating bool // router-update is running
|
||||
Pending bool // a system waits for confirmation
|
||||
Version string // the running NixOS version
|
||||
Channel string
|
||||
Choices []channelChoice
|
||||
Check *UpgradeCheck
|
||||
Preview *UpgradePreview
|
||||
Run UpgradeRun
|
||||
Title string // what the running step does
|
||||
|
||||
NewerRelease string // a stable release newer than the followed channel exists
|
||||
ReleasesSeen string // when the channel server was last asked which exist
|
||||
Updating bool // router-update is running
|
||||
Pending bool // a system waits for confirmation
|
||||
}
|
||||
|
||||
// stableChannels are the stable NixOS releases the page offers (the branch
|
||||
// nixos-26.05 and so on). They are listed here until the router can ask the
|
||||
// channel server which exist; the release a router runs says nothing about it:
|
||||
// nixos-unstable already calls itself the release that comes next.
|
||||
// nixos-26.05 and so on) until the router has asked the channel server which
|
||||
// exist (router-upgrade releases, daily); the release a router runs says
|
||||
// nothing about it: nixos-unstable already calls itself the release that comes
|
||||
// next.
|
||||
var stableChannels = []string{"26.05"}
|
||||
|
||||
// ReleaseList is releases.json: the stable releases the channel server had.
|
||||
type ReleaseList struct {
|
||||
Time string `json:"time"`
|
||||
Releases []string `json:"releases"`
|
||||
}
|
||||
|
||||
var releaseNameRe = regexp.MustCompile(`^[0-9]{2}\.[0-9]{2}$`)
|
||||
|
||||
// releaseCmp orders releases like 25.11 and 26.05 (and 100.05) by number.
|
||||
func releaseCmp(a, b string) int {
|
||||
pa, pb := strings.SplitN(a, ".", 2), strings.SplitN(b, ".", 2)
|
||||
for i := range pa {
|
||||
if i >= len(pb) {
|
||||
return 1
|
||||
}
|
||||
x, _ := strconv.Atoi(pa[i])
|
||||
y, _ := strconv.Atoi(pb[i])
|
||||
if x != y {
|
||||
return x - y
|
||||
}
|
||||
}
|
||||
if len(pb) > len(pa) {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// seenReleases are the stable releases the channel server last answered with,
|
||||
// oldest first; none if it has not been asked yet.
|
||||
func (s System) seenReleases() ReleaseList {
|
||||
var l ReleaseList
|
||||
readUpgradeFile(filepath.Join(s.upgradeDir(), "releases.json"), &l)
|
||||
var ok []string
|
||||
for _, r := range l.Releases {
|
||||
if releaseNameRe.MatchString(r) {
|
||||
ok = append(ok, r)
|
||||
}
|
||||
}
|
||||
slices.SortFunc(ok, releaseCmp)
|
||||
l.Releases = slices.Compact(ok)
|
||||
return l
|
||||
}
|
||||
|
||||
// supportedReleases are the stable releases worth following: NixOS supports the
|
||||
// newest two. Before the router has asked, the ones built in.
|
||||
func supportedReleases(seen []string) []string {
|
||||
if len(seen) == 0 {
|
||||
return stableChannels
|
||||
}
|
||||
return seen[max(len(seen)-2, 0):]
|
||||
}
|
||||
|
||||
// newerRelease is the newest stable release that is newer than the one the
|
||||
// router follows, "" if it follows unstable (or nothing) or is up to date.
|
||||
func newerRelease(current string, seen []string) string {
|
||||
if !releaseNameRe.MatchString(current) || len(seen) == 0 {
|
||||
return ""
|
||||
}
|
||||
if newest := seen[len(seen)-1]; releaseCmp(newest, current) > 0 {
|
||||
return newest
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// releaseNotice says which newer release exists than the channel being followed.
|
||||
func (a *app) releaseNotice() string {
|
||||
s, err := loadSettings(a.sys.settingsPath())
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return newerRelease(s.channel(), a.sys.seenReleases().Releases)
|
||||
}
|
||||
|
||||
// channelChoices are the branches worth offering: none (the packages that came
|
||||
// with the release), unstable and the stable releases. A configured channel
|
||||
// that is none of these stays listed.
|
||||
func channelChoices(current string) []channelChoice {
|
||||
func channelChoices(current string, stable []string) []channelChoice {
|
||||
choices := []channelChoice{{"", "None: the packages that came with this release of nixos-router"}, {"unstable", "unstable (newest, may break)"}}
|
||||
for _, r := range stableChannels {
|
||||
for _, r := range stable {
|
||||
choices = append(choices, channelChoice{r, r + " (stable)"})
|
||||
}
|
||||
if current != "" && !slices.ContainsFunc(choices, func(c channelChoice) bool { return c.Value == current }) {
|
||||
@@ -188,7 +266,10 @@ func (a *app) upgradeData() upgradeData {
|
||||
if s, err := loadSettings(a.sys.settingsPath()); err == nil {
|
||||
d.Channel = s.channel()
|
||||
}
|
||||
d.Choices = channelChoices(d.Channel)
|
||||
seen := a.sys.seenReleases()
|
||||
d.Choices = channelChoices(d.Channel, supportedReleases(seen.Releases))
|
||||
d.NewerRelease = newerRelease(d.Channel, seen.Releases)
|
||||
d.ReleasesSeen = seen.Time
|
||||
if d.Run.Running {
|
||||
data, _ := os.ReadFile(filepath.Join(a.sys.upgradeDir(), "action"))
|
||||
if d.Title = upgradeTitles[strings.TrimSpace(string(data))]; d.Title == "" {
|
||||
|
||||
Reference in New Issue
Block a user