Company
Date Published
Author
Guillaume St-Pierre
Word count
1832
Language
English
Hacker News points
None

Summary

The author is using Nix to build a derivation in a way that allows them to automatically generate the version of their tool based on the commit short SHA of the code repository. The process involves copying the entire repository, including the `.git` directory, into a temporary location, running `git rev-parse --short HEAD` within that context, and then using the result as the version number. After several attempts and iterations, they were able to successfully build the derivation with dynamic versioning using Nix's `copyPathToStore`, `runCommand`, and other functions. The final code leverages these functions to achieve this goal, which is a significant improvement over manual editing of the default.nix file. The author notes that while this journey was challenging, they learned valuable lessons about Nix's language features, such as its lazy evaluation and the importance of understanding how derivations work.