fix: use configuration-revision for current_rev in flake info metric
The nixos_flake_info metric's current_rev label was incorrectly showing the nixpkgs input revision (from /run/current-system/nixos-version) instead of the flake's own revision. Now reads from /run/current-system/configuration-revision which contains the flake's self.rev when system.configurationRevision is set in the NixOS configuration. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -15,11 +14,7 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
const nixosVersionPath = "/run/current-system/nixos-version"
|
||||
|
||||
// revisionPattern extracts the git hash from nixos-version.
|
||||
// Formats: "25.11.20260203.e576e3c" or "1994-294a625"
|
||||
var revisionPattern = regexp.MustCompile(`[.-]([a-f0-9]{7,40})$`)
|
||||
const configRevisionPath = "/run/current-system/configuration-revision"
|
||||
|
||||
type FlakeCollector struct {
|
||||
flakeURL string
|
||||
@@ -215,18 +210,16 @@ func fetchFlakeMetadata(flakeURL string) (*flakeMetadata, error) {
|
||||
}
|
||||
|
||||
func getCurrentSystemRevision() (string, error) {
|
||||
data, err := os.ReadFile(nixosVersionPath)
|
||||
data, err := os.ReadFile(configRevisionPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
// configuration-revision doesn't exist; user hasn't set system.configurationRevision
|
||||
return "", nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
version := strings.TrimSpace(string(data))
|
||||
matches := revisionPattern.FindStringSubmatch(version)
|
||||
if matches == nil {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
rev := matches[1]
|
||||
rev := strings.TrimSpace(string(data))
|
||||
if len(rev) > 7 {
|
||||
rev = rev[:7]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user