From 3f25286e53b05fdcaf3ec312d1c6fd44cfa75f92 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 17 May 2022 23:20:53 +0200 Subject: [PATCH] Polyfill functionTo where it is pressing --- lib.nix | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib.nix b/lib.nix index 8e7f252..0a3a9c3 100644 --- a/lib.nix +++ b/lib.nix @@ -3,9 +3,29 @@ let inherit (lib) mkOption types - functionTo ; + # Polyfill functionTo to make sure it has type merging. + # Remove 2022-12 + functionTo = + let sample = types.functionTo lib.types.str; + in + if sample.functor.wrapped._type or null == "option-type" + then types.functionTo + else + elemType: lib.mkOptionType { + name = "functionTo"; + description = "function that evaluates to a(n) ${elemType.description}"; + check = lib.isFunction; + merge = loc: defs: + fnArgs: (lib.mergeDefinitions (loc ++ [ "[function body]" ]) elemType (map (fn: { inherit (fn) file; value = fn.value fnArgs; }) defs)).mergedValue; + getSubOptions = prefix: elemType.getSubOptions (prefix ++ [ "[function body]" ]); + getSubModules = elemType.getSubModules; + substSubModules = m: functionTo (elemType.substSubModules m); + functor = (lib.defaultFunctor "functionTo") // { type = functionTo; wrapped = elemType; }; + nestedTypes.elemType = elemType; + }; + flake-modules-core-lib = { evalFlakeModule = { self @@ -30,7 +50,7 @@ let mkPerSystemType = module: - types.functionTo (types.submoduleWith { + functionTo (types.submoduleWith { modules = [ module ]; shorthandOnlyDefinesConfig = false; });