From ede5720a0dde969cf83dd7cbbe54ad8c5ff7a97b Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 31 Oct 2023 13:38:29 +0100 Subject: [PATCH] flake/version overlay: review fixes * Improves the comments of `lib/flake-version-info.nix` and drops the `__`-prefix from the filename. * `lib'` -> `lib0` in `nixpkgs/lib`. * Drop the declaration of `trivial.version` in the overlay because this declaration already uses the final expressions of `versionSuffix` and `release` now. * No need to fall back to `self.lastModified` anymore, this was a workaround for pre2.4 Nix. Co-authored-by: Robert Hensing Co-authored-by: Silvan Mosberger --- flake.nix | 2 +- lib/__flake-version-info.nix | 17 ----------------- lib/flake-version-info.nix | 20 ++++++++++++++++++++ lib/flake.nix | 4 ++-- 4 files changed, 23 insertions(+), 20 deletions(-) delete mode 100644 lib/__flake-version-info.nix create mode 100644 lib/flake-version-info.nix diff --git a/flake.nix b/flake.nix index 23c9f09a174b..307eea0cd040 100644 --- a/flake.nix +++ b/flake.nix @@ -9,7 +9,7 @@ nixpkgs = self; }; - libVersionInfoOverlay = import ./lib/__flake-version-info.nix self; + libVersionInfoOverlay = import ./lib/flake-version-info.nix self; lib = (import ./lib).extend libVersionInfoOverlay; forAllSystems = lib.genAttrs lib.systems.flakeExposed; diff --git a/lib/__flake-version-info.nix b/lib/__flake-version-info.nix deleted file mode 100644 index 19ce4c351cf1..000000000000 --- a/lib/__flake-version-info.nix +++ /dev/null @@ -1,17 +0,0 @@ -# lib overlay to be used by the nixpkgs & nixpkgs/lib flakes -# to provide meaningful values for `lib.trivial.version` et al.. -# -# Internal and subject to change, don't use this anywhere else! - -self: # from the flake - -finalLib: prevLib: # lib overlay - -{ - trivial = prevLib.trivial // { - versionSuffix = - ".${finalLib.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}"; - version = finalLib.trivial.release + finalLib.trivial.versionSuffix; - revisionWithDefault = default: self.rev or default; - }; -} diff --git a/lib/flake-version-info.nix b/lib/flake-version-info.nix new file mode 100644 index 000000000000..de15be94bee8 --- /dev/null +++ b/lib/flake-version-info.nix @@ -0,0 +1,20 @@ +# This function produces a lib overlay to be used by the nixpkgs +# & nixpkgs/lib flakes to provide meaningful values for +# `lib.trivial.version` et al.. +# +# Internal and subject to change, don't use this anywhere else! +# Instead, consider using a public interface, such as this flake here +# in this directory, `lib/`, or use the nixpkgs flake, which applies +# this logic for you in its `lib` output attribute. + +self: # from the flake + +finalLib: prevLib: # lib overlay + +{ + trivial = prevLib.trivial // { + versionSuffix = + ".${finalLib.substring 0 8 (self.lastModifiedDate or "19700101")}.${self.shortRev or "dirty"}"; + revisionWithDefault = default: self.rev or default; + }; +} diff --git a/lib/flake.nix b/lib/flake.nix index 475aa13edafb..ca09ed5f4a42 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -3,8 +3,8 @@ outputs = { self }: let - lib' = import ./.; + lib0 = import ./.; in { - lib = lib'.extend (import ./__flake-version-info.nix self); + lib = lib0.extend (import ./flake-version-info.nix self); }; }