From 542e3969499d184ba39fd7b3c201ead5bddfdd76 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 31 May 2023 16:31:11 +0200 Subject: [PATCH] Add lower bound to lib version --- flake.nix | 9 ++++++++- lib.nix | 22 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 190d8f2..8b934f6 100644 --- a/flake.nix +++ b/flake.nix @@ -6,7 +6,14 @@ }; outputs = { nixpkgs-lib, ... }: { - lib = import ./lib.nix { inherit (nixpkgs-lib) lib; }; + lib = import ./lib.nix { + inherit (nixpkgs-lib) lib; + # Extra info for version check message + revInfo = + if nixpkgs-lib?rev + then " (nixpkgs-lib.rev: ${nixpkgs-lib.rev})" + else ""; + }; templates = { default = { path = ./template/default; diff --git a/lib.nix b/lib.nix index f99f0cc..908ebfa 100644 --- a/lib.nix +++ b/lib.nix @@ -1,4 +1,8 @@ -{ lib }: +{ lib + # Optionally a string with extra version info to be included in the error message + # in case is lib is out of date. Empty or starts with space. +, revInfo ? "" +}: let inherit (lib) mkOption @@ -207,5 +211,19 @@ let lib.setDefaultModuleLocation modulePath (import modulePath staticArgs); }; + # A best effort, lenient estimate. Please use a recent nixpkgs lib if you + # override it at all. + minVersion = "22.05"; + in -flake-parts-lib + +if builtins.compareVersions lib.version minVersion <= 0 +then + abort '' + The nixpkgs-lib dependency of flake-parts was overridden but is too old. + The minimum supported version of nixpkgs-lib is ${minVersion}, + but the actual version is ${lib.version}${revInfo}. + '' +else + + flake-parts-lib