How to make a flake input point to the latest release?

For example, I want to install https://github.com/utensils/mcp-nixos as a flake input, such that it points to https://github.com/utensils/mcp-nixos/releases/latest (which currently redirects to https://github.com/utensils/mcp-nixos/releases/tag/v1.0.1)

it seems that neither

  • "github:utensils/mcp-nixos/releases/latest"
  • "github:utensils/mcp-nixos/latest"
  • "github:utensils/mcp-nixos/?ref=latest"

works

FlakeHub proposes this (see `inputs.nixpkgs` from FlakeHub? - #10 by grahamc), but it uses a server-side routing feature and I am looking for a Nix-native way to achieve such bahavior

You want the main branch?

I don’t think its possible to do it like you expect it to. For eg. nixos/nix provides GitHub - NixOS/nix at latest-release a branch specifically tracking latest release, so that github:nixos/nix/latest-release can be used. or GitHub - cachix/cachix at latest which is a duplicated tag the upstream provides.

So the upstream project needs to maintain something similar or you have to maintain a fork yourself with a branch which tracks the latest release.

1 Like

Nope, not the main branch, but the latest release (https://github.com/utensils/mcp-nixos/releases/latest)

Well it looks like they tagged it so you could do this:

https://gitlab.com/ahoneybun/nix-configs/-/blob/main/flake.nix?ref_type=heads#L11

though you would need to update it to move to the new tag when they make a new release, other wise main/master would be the latest code so HEAD:

https://gitlab.com/ahoneybun/nix-configs/-/blob/main/flake.nix?ref_type=heads#L10

I found a lot of great information about Flakes here:

1 Like

Yes, precisely

I am in search of a way to make the input point to the latest release dynamically

Thanks for that resource, I will look into it!

That is not possible, at the moment, unless the target repository has a branch tracking the latest release. FWIW, I did start hacking on a simple server that works similar to Flakehub’s semver resolution thingy, but only needs a git repository with semver-like tags as backend (but that server would still need to be running somewhere). No README, but feel free to look around:

2 Likes

Okay, thanks!

Do you think it would be possible to make an utils for flake inputs that would be able to infer the latest release of a repository and chose it as an input target? potentially using the GitHub API

As of now at least, GitHub has no official API to obtain the latest created tag. It can pull the latest release, which for some repos will match the latest tag.

$ curl "https://api.github.com/repos/<OWNER>/<NAME>/releases/latest -s` | jq -r '.name'

You can also attempt to parse the tags manually and determine the latest.

$ git ls-remote --tags --refs "https://github.com/<OWNER>/<NAME>.git"

EDIT:

You could possibly glean some useful information from https://stackoverflow.com/questions/13208734/get-the-time-and-date-of-git-tags

1 Like

I was able to list all tags from a repository using the /repos/{owner}/{repo}/tags GitHub API Endpoint

It seems undocumented and I found it by chance
See the issue I just opened for it: MISSING: `/repos/{owner}/{repo}/tags` API endpoint · Issue #40396 · github/docs · GitHub

Note that this GitHub API Endpoint is different than the /repos/{owner}/{repo}/git/tags one

The topmost entry from the result object this endpoint returns seems to always refer to the latest tag

I tried /repos/{owner}/{repo}/tags/latest (similar to the releases/latest one), but it doesn’t seem to exist (but it is more acceptable given than releases has a concrete “latest” one, while it’s not a thing for tags)

Also, I couldn’t yet find which parameters / options could this endpoint take, so also couldn’t find a way for it to only return the latest tag for efficiency (maybe using a similar GraphQL endpoint?)

For now, I was only successful in listing every tags at once from a repository

This is indeed true, there are two endpoints making that possible:


So maybe that is possible:

3 Likes

You definetly could write a wrapper around nix flake update to implement your desired tag-following semantics and rewrites the flake.nix inputs just before you run nix flake update

At that point it’d no longer be a flake input, so they and any other users would have to carry the wrapper around separately.

There’s also alternatives like npins and nvfetcher which aren’t flake-specific.

2 Likes

Update

image


The returned list is ordered by the tag creation date (exactly in the same order than results from this page for example : Tags · NixOS/nix · GitHub), and not by SemVer

So there is a way to use the two global pagination parameters from their API (Using pagination in the REST API - GitHub Docs) to make it so you only return the latest pushed tag, but it wouldn’t guarantee it would also be the latest semver tag

Hi, would it be feasible to fork the repo and setup Dependabot to only sync commits on release tags?

1 Like

Sure, that should work! As long as it’s a branch you want to track, it doesn’t matter if that’s coming from an automatically synced fork or upstream.

1 Like

Interesting idea as well, but it technically is a middleman server

I was talking about the GitHub Dependabot and I don’t think that requires a middleman server.

require is* if you prefer

GitHub Actions are the middleman servers

A (suboptimal server-side) workaround GitHub - gmodena/nix-flatpak: Install flatpaks declaratively is using is a latest tag which is dynamically updated each time a new SemVer tag is pushed to point to it

Related

Found this