From a95db128a65d2e4991c815d2f9d9d1620c5e383b Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 24 May 2025 09:32:19 +0100 Subject: [PATCH] update-scripts/version-info: convert to a script This will allow us to do impure things if needed. --- update-scripts/update.nix | 2 +- update-scripts/version-info/default.nix | 46 ++++++++----------------- update-scripts/version-info/main.nix | 27 +++++++++++++++ 3 files changed, 43 insertions(+), 32 deletions(-) create mode 100644 update-scripts/version-info/main.nix diff --git a/update-scripts/update.nix b/update-scripts/update.nix index c4900aa1..597869f5 100644 --- a/update-scripts/update.nix +++ b/update-scripts/update.nix @@ -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 "$@" diff --git a/update-scripts/version-info/default.nix b/update-scripts/version-info/default.nix index a59867f0..c7f15aea 100644 --- a/update-scripts/version-info/default.nix +++ b/update-scripts/version-info/default.nix @@ -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 + ''; +} diff --git a/update-scripts/version-info/main.nix b/update-scripts/version-info/main.nix new file mode 100644 index 00000000..5a083725 --- /dev/null +++ b/update-scripts/version-info/main.nix @@ -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