update-scripts/version-info: convert to a script

This will allow us to do impure things if needed.
This commit is contained in:
Matt Sturgeon 2025-05-24 09:32:19 +01:00
parent 80934be3e9
commit a95db128a6
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
3 changed files with 43 additions and 32 deletions

View file

@ -43,7 +43,7 @@ writeShellApplication {
versionInfo() {
nix-build ./update-scripts -A version-info
install -m 644 -T "$(realpath result)" ./version-info.toml
./result
if [ -n "$commit" ]; then
git add version-info.toml
git commit "$@"

View file

@ -1,36 +1,20 @@
{
lib,
writers,
runCommand,
callPackage,
writeShellApplication,
}:
let
inherit (builtins)
all
match
attrNames
;
inherit (lib)
importJSON
;
lockFile = importJSON ../../flake.lock;
nixpkgsLock =
# Assert there is only one nixpkgs node
assert all (node: match "nixpkgs_[0-9]+" node == null) (attrNames lockFile.nodes);
lockFile.nodes.nixpkgs.original;
info = {
inherit (lib.trivial) release;
nixpkgs_rev = lib.trivial.revisionWithDefault (throw "nixpkgs revision not available");
unstable = lib.strings.hasSuffix "-unstable" nixpkgsLock.ref;
};
mainInfo = callPackage ./main.nix { };
in
runCommand "version-info.toml" { } ''
(
echo "# DO NOT MODIFY!"
echo "# This file was generated by ${
lib.strings.removePrefix (toString ../.. + "/") (toString ./default.nix)
}"
cat ${writers.writeTOML "version-info.toml" info}
) > $out
''
writeShellApplication {
name = "version-info";
text = ''
(
echo "# DO NOT MODIFY!"
echo "# This file was generated by ${
lib.strings.removePrefix (toString ../.. + "/") (toString ./default.nix)
}"
cat ${mainInfo}
) > version-info.toml
'';
}

View file

@ -0,0 +1,27 @@
{
lib,
writers,
}:
let
inherit (builtins)
all
match
attrNames
;
inherit (lib)
importJSON
;
lockFile = importJSON ../../flake.lock;
nixpkgsLock =
# Assert there is only one nixpkgs node
assert all (node: match "nixpkgs_[0-9]+" node == null) (attrNames lockFile.nodes);
lockFile.nodes.nixpkgs.original;
info = {
inherit (lib.trivial) release;
nixpkgs_rev = lib.trivial.revisionWithDefault (throw "nixpkgs revision not available");
unstable = lib.strings.hasSuffix "-unstable" nixpkgsLock.ref;
};
in
writers.writeTOML "version-info.toml" info