I want to convert a Rust project into a flake, that uses the vergen crate to create version metadata from the git repository at build time. I use the git ref and git describe output. vergen is somehow aware of nix and will return VERGEN_IDEMPOTENT_OUTPUT if .git is not present and the metadata cannot be obtained (e.g. in a nix build).
To fully convert the project into a flake, I'd like to set both ${self.rev or self.dirtyRev or "dirty"} and ${self.version} as environment in the nix build and fallback on something like env!("NIX_FLAKE_REF") if vergen cannot calculate metadata from the git repo.
How can I set custom environment variables, that are available when building the project (and possibly also in devShells) when using the template flake?
I want to convert a Rust project into a flake, that uses the
vergen
crate to create version metadata from the git repository at build time. I use the git ref and git describe output.vergen
is somehow aware of nix and will returnVERGEN_IDEMPOTENT_OUTPUT
if.git
is not present and the metadata cannot be obtained (e.g. in a nix build).To fully convert the project into a flake, I'd like to set both
${self.rev or self.dirtyRev or "dirty"}
and${self.version}
as environment in the nix build and fallback on something likeenv!("NIX_FLAKE_REF")
if vergen cannot calculate metadata from the git repo.How can I set custom environment variables, that are available when building the project (and possibly also in devShells) when using the template flake?