What I’m trying to achieve:
Have the git commit SHA baked into the built binary, passed via ldFlags in buildGoModule.
Before flakes:
I used to read the current commit SHA through an ENV var with builtins.getEnv.
This was useful for Github actions and agnostic of git worktrees (bare repo) vs normal repos.
i.e. in a bare repo checkout where the worktree isn’t necessarily laying flat with the .git folder itself, you can’t just read .git/refs/heads/main.
With Flakes
Given flakes are hermetic, the build can’t read the ENV variable.
Any ideas of how to achieve this with flakes? Is anyone else doing something similar?
While self.rev is the correct answer, the whole answer should probably be self.rev or "no clue". The revision attribute only exists when you are in a clean checkout of the repository, and you’ll get errors if you don’t handle this case.
Thanks both! I’m assuming this should always be OK on the CI builds?
Locally I have a different flake output so can just hardcode version = “development”;