Sorry, I don’t know if a bump is the right thing to do, or if I should recreate?
I find myself really needing this, as I’m adding a flake to something that has an established versioning and I cannot just use shortRev
etc because it needs the version format to be something like the output of git describe
. I’ve managed a horrible hack:
# Generate a user-friendly version number.
# Sadly currently nix flakes don't support git-describe like versions
# And yes, manually having to update `tagRevCount` and `tag` is very poor
tagRevCount = 858;
tag = "1.0.1";
shortDate = builtins.substring 0 8 lastModifiedDate;
shortRev = if self ? "shortRev" then "g${self.shortRev}" else "dirty";
revCount = if self ? "revCount" then toString (self.revCount - tagRevCount) else "dirty";
gitSuffix = if revCount == "0" then "" else "-${revCount}-${shortRev}+${shortDate}";
gitVersion = "${tag}${gitSuffix}";
but it is as I said horrible, especially because of manually needing to update tagRevCount
and tag
, still at least there are no problems with having to create a fixed-point hash if I were to use rev
. And assuming I’m going to tag the commit I’ve just updated the flake.nix
values tag
and tagRevCount
in, it should be safe as any parent of the commit will have the old tagRevCount
, and any child of the commit will have tagRevCount - revCount > 0
.
I having a git describe
-like output would be very useful, maybe it could be a function taking arguments like match
, dirty
and always
? But some things do depend on a git-describe like version, in this case it’s Elixir Version — Elixir v1.12.3.
I have also done a slightly nicer thing, in the flake I’m pulling this from:
rec {
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
inputs.myflake.type = "git";
inputs.myflake.url = "https://myflake.url/repo.git";
inputs.myflake.ref = "refs/tags/release/1.0.1";
outputs =
{ nixpkgs, myflake } @ flake-args: {
nixosConfigurations.gitlab-runner = nixpkgs.lib.nixosSystem rec {
system = "x86_64-linux";
modules = [
({ pkgs, lib, ... }: {
environment.systemPackages = [
(myflake.packages.x86_64-linux.default.override {
version = builtins.replaceStrings [ "refs/tags/release/" ] [ "" ] inputs.myflake.ref;
})
];
})
];
};
};
}
which doesn’t depend on the earlier hack, because it overwrites the version (the myflake
has nixpkgs.lib.makeOverridable { version ? gitVersion }: <derivation> {}
) but still, this is not nice. I would prefer it if flakes would support something like git describe
even if it means a higher likelihood of cache misses.
In terms of implementing this, I’ve had a quick look, it looks like the rev
is using getRev
, which is just a string attribute. I think it is populated here for revCount but I’ll have to have more of a think/proper read of the code.
But it seems like only string attrs are supported, presumably can be extended reasonably easily to also include attrsets, but probably not easily to support functions. Plus I suspect the attrs need to be serialised to the lock-file. So maybe putting an attrset of tags to revs and revcounts is a way to go? Then could have a helper function to create something like the git-describe. Of course, this means that you can have a nix flake update
that only updates the tags, but I think because the narHash
could stay the same it should prevent another fetch of the repo (the sources anyway, it might do rebuild). And self
isn’t in the lock file 
Anyway, sorry this is just my thoughts on it/quick look at how it could be done and it’s entirely possible I’ll not get around to implementing it, but who knows I might? And because it’s just a quick skim of the code, it’s possible I’ve misunderstood things. Any feedback?