embed the build version and auto-upgrade remote installs whose tobi does not match it
8 unmodified lines91011121313141516171819201921222324251 unmodified line2728293029313233343512 unmodified lines8 unmodified lines outputs = inp: inp.parts.lib.mkFlake { inputs = inp; } { systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; perSystem = { pkgs, ... }: { packages.default = pkgs.buildGoModule { packages.default = let rev = inp.self.shortRev or inp.self.dirtyShortRev or "dev"; in pkgs.buildGoModule { pname = "tobi"; version = "0.1.0"; src = ./.; vendorHash = "sha256-qbOGgVRsO0/F1dB/vIERm6EsUjgWGzT2z938pnKVbcI="; subPackages = [ "." ]; ldflags = [ "-s" "-w" ]; ldflags = [ "-s" "-w" "-X tobi/internal/version.Version=${rev}" ]; nativeBuildInputs = [ pkgs.zstd ]; # cross-compile the remote-install carrier slices before the main # build embeds them (same slices as scripts/build-universal.sh) preBuild = ''1 unmodified line for target in linux/amd64 linux/arm64 darwin/arm64; do os=''${target%%/*} arch=''${target##*/} echo "building carrier slice for $os/$arch" CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -trimpath -ldflags="-s -w" -o internal/remote/payloads/tobi-$os-$arch . CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -trimpath -ldflags="-s -w -X tobi/internal/version.Version=${rev}" -o internal/remote/payloads/tobi-$os-$arch . zstd -19 -q --rm internal/remote/payloads/tobi-$os-$arch done ''; };12 unmodified lines5 unmodified lines6789101112131415164 unmodified lines21222324222526272829303132303334355 unmodified lines "linux/arm64" "darwin/arm64")
VERSION="$(git describe --always --dirty 2>/dev/null || echo dev)"LDFLAGS="-s -w -X tobi/internal/version.Version=${VERSION}"
tmp_dir="$(mktemp -d /tmp/tobi-slices-XXXXXX)"trap 'rm -rf "${tmp_dir}"' EXIT
mkdir -p internal/remote/payloads4 unmodified lines os="${target%%/*}" arch="${target##*/}" out="${tmp_dir}/tobi-${os}-${arch}" echo " -> compiling ${os}/${arch}..." CGO_ENABLED=0 GOOS="${os}" GOARCH="${arch}" go build -trimpath -ldflags="-s -w" -o "${out}" . CGO_ENABLED=0 GOOS="${os}" GOARCH="${arch}" go build -trimpath -ldflags="${LDFLAGS}" -o "${out}" . zstd -19 -q --rm "${out}"done
echo "copying zstd compressed slices into payloads/..."mv "${tmp_dir}"/*.zst internal/remote/payloads/
echo "building final carrier binary..."CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o tobi-universal .CGO_ENABLED=0 go build -trimpath -ldflags="${LDFLAGS}" -o tobi-universal .
echo "done! tobi-universal contains slices for: ${targets[*]}"19 unmodified lines202122232425262728285 unmodified linesExpand all31431531631731831931731832032132232332432582 unmodified lines40840941041141241341441541641741874 unmodified lines19 unmodified lines
"github.com/klauspost/compress/zstd" "github.com/samber/lo" "tobi/internal/session" "tobi/internal/version")
//go:embed payloads/*var embeddedPayloads embed.FS285 unmodified linesExpand all if _, ok := remoteInstalled.Load(host); ok { return nil }
// skip the upload only when the host already runs THIS build; an older // (or newer, or foreign) install gets upgraded in place checkCmd := fmt.Sprintf(`%s command -v tobi >/dev/null 2>&1 && echo %s`, remotePathEnv, haveMarker) if out, err := sshRun(ctx, host, checkCmd, "3", nil, true); err == nil && strings.Contains(out, haveMarker) { checkCmd := fmt.Sprintf(`%s command -v tobi >/dev/null 2>&1 && TOBI_RPC=version tobi 2>/dev/null`, remotePathEnv) if out, err := sshRun(ctx, host, checkCmd, "3", nil, true); err == nil && strings.TrimSpace(out) == version.Version { remoteInstalled.Store(host, true) return nil }
82 unmodified lines case "list": return json.NewEncoder(os.Stdout).Encode(session.ListLocal()) case "spawn": return runSpawnRPC(os.Stdin) case "version": fmt.Println(version.Version) return nil }
conn, err := net.Dial("unix", session.SocketPath(id)) if err != nil {74 unmodified lines1234567// Package version carries the build-stamped tobi version, used to decide// when a remote host's installed tobi needs upgrading.package version
// Version is stamped at build time via -ldflags (flake or// scripts/build-universal.sh); a plain `go build` produces "dev".var Version = "dev"