aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-14 17:06:20 +0000
committertv <tv@krebsco.de>2026-11-14 17:06:20 +0000
commit275b9f6102e6f3011099752ec1023a11b326fc45 (patch)
tree96427c4a1824942a2422941f5577f137b37da4f9
parentfe79e21268973b9dcebe428fe17482e20b5c6154 (diff)
README: pin the minimal example by its tag and a hash the reader gets
The example fetched krops 1.25.0 by a hash, which a release can't put in its own README, since the hash covers the README. It names the tag of the release, which a release can, and the reader gets the hash with nix-prefetch-git, or from Nix, evaluating the example with lib.fakeHash. Evaluating the tests checks that the tag is the newest version in the changelog, or, with unreleased changes, at least as new as the newest release, so a release can't leave it behind.
-rw-r--r--README.md15
-rw-r--r--tests/default.nix23
2 files changed, 33 insertions, 5 deletions
diff --git a/README.md b/README.md
index 7347e24..f9d594b 100644
--- a/README.md
+++ b/README.md
@@ -14,14 +14,17 @@ krops is a lightweight toolkit to deploy NixOS systems, remotely or locally.
## Minimal Example
-Create a file named `krops.nix` (name doesn't matter) with following content:
+Create a file named `krops.nix` (name doesn't matter) with following content,
+with the hash that `nix-prefetch-git --url https://cgit.krebsco.de/krops
+--rev refs/tags/v2.0.0` prints, which Nix also reports when evaluating it
+with `lib.fakeHash`:
```nix
let
krops = (import <nixpkgs> {}).fetchgit {
- url = https://cgit.krebsco.de/krops/;
- rev = "v1.25.0";
- sha256 = "07mg3iaqjf1w49vmwfchi7b1w55bh7rvsbgicp2m47gnj9alwdb6";
+ url = "https://cgit.krebsco.de/krops";
+ rev = "refs/tags/v2.0.0";
+ hash = (import <nixpkgs> {}).lib.fakeHash;
};
pkgs = import "${krops}/pkgs" {};
@@ -374,7 +377,9 @@ nix-build tests -A only --argstr only 'lock-hooks-.*' # scenarios by name
```
`-A only` selects from all of populate's scenarios and krops' own, all
-running through `pkgs.populate`.
+running through `pkgs.populate`. Evaluating the tests also checks that the
+minimal example fetches the newest version in the [changelog](CHANGELOG.md),
+or, with unreleased changes, one at least as new as the newest release.
## References
diff --git a/tests/default.nix b/tests/default.nix
index 6c3bc59..95f3856 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -134,10 +134,33 @@ let
throw "tests: no scenario's name matches ${builtins.toJSON only}"
else
selected;
+ # The version of krops the README's example fetches, which is the
+ # CHANGELOG's newest, or, with unreleased changes, at least the newest
+ # released, so a release can't leave the README behind. The README can't
+ # name the release's hash, which covers the README.
+ checkReadmeVersion = let
+ lines = file: lib.splitString "\n" (builtins.readFile file);
+ matches = regex: file: lib.concatMap
+ (line: let m = builtins.match regex line; in
+ if m == null then [] else m)
+ (lines file);
+ readme = matches ''.*rev = "refs/tags/v([0-9.]+)";.*'' ../README.md;
+ headings = matches "## (.*)" ../CHANGELOG.md;
+ newest = lib.findFirst (heading: heading != "Unreleased") null headings;
+ in
+ if builtins.length readme != 1 then
+ throw "tests: README.md doesn't name one version of krops to fetch"
+ else if lib.head headings == "Unreleased" then
+ builtins.compareVersions (lib.head readme) newest >= 0 ||
+ throw "tests: README.md fetches krops ${lib.head readme}, older than the newest release in CHANGELOG.md, ${newest}"
+ else
+ lib.head readme == newest ||
+ throw "tests: README.md fetches krops ${lib.head readme}, but the newest release in CHANGELOG.md is ${newest}";
in
# The remote target must not count as local wherever this gets evaluated.
assert !(krops.isLocalTarget (targets.remote "/"));
+assert checkReadmeVersion;
testsOf false ""
# Not built by nix-build tests either, which runs these scenarios anyway.