Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zombiezen/stamp.nix
Library for giving a derivation a version number based on Flake sourceInfo
https://github.com/zombiezen/stamp.nix
nix nix-flake
Last synced: about 2 months ago
JSON representation
Library for giving a derivation a version number based on Flake sourceInfo
- Host: GitHub
- URL: https://github.com/zombiezen/stamp.nix
- Owner: zombiezen
- License: apache-2.0
- Created: 2024-03-13T17:46:36.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-03-15T20:34:07.000Z (11 months ago)
- Last Synced: 2024-10-28T20:16:19.251Z (4 months ago)
- Topics: nix, nix-flake
- Language: Nix
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# The "stamp" Nix Flake
If you have a [Nix][]-built project that has a "live at head" vibe,
you probably want to give your derivation a version number
so it can be identified and upgraded correctly.
However, placing this information directly in the output path
can cause unnecessary rebuilds during development,
wasting time and disk space.This flake provides a function, `stamp`,
that generates a derivation with a timestamp-based `version`
that is a symlink to another derivation.
The version string is automatically generated from the `sourceInfo`
provided by a Nix Flake.[Nix]: https://nixos.org/
## Getting Started
```nix
# flake.nix
{
inputs = {
nixpkgs.url = "nixpkgs";
flake-utils.url = "flake-utils";
stamp.url = "github:zombiezen/stamp.nix";
};outputs = { self, nixpkgs, flake-utils, stamp, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
packages.default = stamp.lib.stamp {
inherit pkgs;
sourceInfo = self.sourceInfo;
wrapped = pkgs.hello;
};
}
);
}
```You can then check the version number with:
```shell
nix eval '.#default.version'
```This will result in a string like `20240313091500`.
If the flake is being built from a clean working copy,
then the string will have the commit at the end like `20240313091500+1234cafe`.## Reference
This flake has one function: `lib.stamp`.
| Parameter | Description |
| :----------- | :--------------------------------- |
| `pkgs` | nixpkgs for the appropriate system |
| `sourceInfo` | `self.sourceInfo` from the flake |
| `wrapped` | The derivation to wrap |`lib.stamp` returns a derivation
with the same `pname` and `meta` as the wrapped derivation.
The resulting derivation includes an additional `wrapped` attribute
that permits accessing the original derivation.## License
[Apache 2.0](LICENSE)