set release to 2026.09.21, date-ordered remote checks
123456345611 unmodified lines1819202126272223243025262728295 unmodified lines{ pkgs ? import <nixpkgs> { }, # baked into the binary as the rpc version string; the flake passes # "<rev>+<epoch>" and a plain nix-build reports "dev" - the epoch is what # remote upgrade checks compare, so older builds never overwrite newer ones rev ? "dev",}:let inherit (pkgs) lib; # non-flake eval has no git-tree filter and the repo collects state that11 unmodified lines version = "0.1.0"; inherit src; vendorHash = "sha256-qbOGgVRsO0/F1dB/vIERm6EsUjgWGzT2z938pnKVbcI="; nativeBuildInputs = [ pkgs.zstd ]; # one build path shared with manual runs; VERSION replaces the script's # git describe because the sandbox has no .git # one build path shared with manual runs buildPhase = '' runHook preBuild VERSION=${rev} bash scripts/build-universal.sh ./dist bash scripts/build-universal.sh ./dist runHook postBuild ''; installPhase = '' runHook preInstall5 unmodified lines8 unmodified lines91011121314151617181913141516178 unmodified lines8 unmodified lines outputs = inp: inp.parts.lib.mkFlake { inputs = inp; } { systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; perSystem = { pkgs, ... }: { packages.default = import ./default.nix { inherit pkgs; # the "+epoch" suffix is what remote upgrade checks compare rev = let r = inp.self.shortRev or inp.self.dirtyShortRev or "dev"; in "${r}+${toString inp.self.lastModified}"; }; packages.default = import ./default.nix { inherit pkgs; };
devShells.default = pkgs.mkShell { packages = with pkgs; [ go8 unmodified lines12345675910111213141567891027 unmodified lines#!/usr/bin/env bashset -euo pipefail
# usage: build-universal.sh [out-dir] (default: .)# env: VERSION - stamped into every slice and the host binary; defaults to# `git describe`, but nix passes it explicitly because the sandbox has# no .git to describeout_dir="${1:-.}"VERSION="${VERSION:-$(git describe --always --dirty 2>/dev/null || echo dev)}"# every build carries a comparison epoch; nix passes one alreadycase "${VERSION}" in *+*) ;; *) VERSION="${VERSION}+$(git log -1 --format=%ct 2>/dev/null || echo 0)" ;;esacLDFLAGS="-s -w -X tobi/internal/remote.Version=${VERSION}"LDFLAGS="-s -w"
targets=( "linux/amd64" "linux/arm64"27 unmodified lines157 unmodified linesExpand all15815916016116216216316416516616516616716816917016716816917017117217317417517617717817917318018118218318466 unmodified lines251252253254248249255256257258259260261262263264265199 unmodified linesExpand all157 unmodified linesExpand allvar archAlias = map[string]string{"x86_64": "amd64", "aarch64": "arm64"}
var ( remoteInstalled sync.Map Version = "dev" // the declared release; bump it (or append "+n" for a same-day // re-release) to ship, remotes refuse older builds Version = "2026.09.21")
// versionEpoch parses the "+<unix time>" build suffix of a version like// "9e3d87f-dirty+1758451200"; builds without one report -1func versionEpoch(v string) int64 { if i := strings.LastIndexByte(v, '+'); i >= 0 { if e, err := strconv.ParseInt(v[i+1:], 10, 64); err == nil { return e// verTuple parses a declared version - "2026.09.21" or "2026.09.21+2", the// suffix counting same-day re-releases; undated builds sort before dated onesfunc verTuple(v string) (string, int) { if len(v) >= 10 && v[4] == '.' && v[7] == '.' { if len(v) == 10 { return v, 0 } if v[10] == '+' { if n, err := strconv.Atoi(v[11:]); err == nil && n >= 0 { return v[:10], n } } } return -1 return "", 0}
type sshOpts struct { cmd string66 unmodified lines // rpc too, or the check 127s on hosts where tobi is not in default PATH check := remotePathEnv + " " + peerEnv() + `command -v tobi >/dev/null 2>&1 && ` + remotePathEnv + ` TOBI_RPC=version tobi` if out, err := sshRun(ctx, dest, nil, sshOpts{cmd: check, batch: true, master: true, timeout: "3"}); err == nil { remoteVer := strings.TrimSpace(out) if remoteVer == Version || versionEpoch(Version) <= versionEpoch(remoteVer) { if versionEpoch(remoteVer) > versionEpoch(Version) { ldate, lseq := verTuple(Version) rdate, rseq := verTuple(remoteVer) newer := rdate != "" && (rdate > ldate || (rdate == ldate && rseq > lseq)) if ldate == "" || rdate != "" && (rdate > ldate || rdate == ldate && rseq >= lseq) { if ldate == "" && rdate != "" { fmt.Fprintf(os.Stderr, "not downgrading %s: remote tobi %s is versioned, the local build is not\n", dest, remoteVer) } else if newer { fmt.Fprintf(os.Stderr, "not downgrading %s: remote tobi %s is newer than local %s\n", dest, remoteVer, Version) } remoteInstalled.Store(dest, true) return nil199 unmodified linesExpand all