Flakes: accessing self's revision?

How do I access the revision for “self” in a flake?

I want to extend system.nixos.label to include the git hash of the repo that it was built from, which doesn’t seem to be a thing by default (or am I missing something? I thought maybe there was some sort of support for getting “Back to the flake” from a system toplevel, but I can’t find that now.)

It seems like inputs.self.sourceInfo looks like this, and lacks the rev info (and this seems to be the same for different inputs too, that are locked from git repos). I was sure that there’s some way to get to this, right? Maybe I’ve previously accessed it through flake-compat since it parses the lock file?


Don’t you look for this?


1 Like

As far as I can tell that’s not available. It wasn’t there when I was evaluating and when I try to use it in my config it’s just null. For some reason it’s not there even though it seems like it ought to be.

self.rev is only non-null if your working tree is clean. You can use the nix command line flag --no-allow-dirty to prevent yourself from building from a dirty worktree. See also https://www.tweag.io/blog/2020-07-31-nixos-flakes/


Is there a way to get the git rev of the flake anyway? Even if it is dirty, it might be useful to have something like “1f421ec-dirty”.

1 Like

No, not at the moment, see e.g. Should a flake's `self.rev` return something useful in modified repos? · Issue #4682 · NixOS/nix · GitHub.