From 41ec64361f80f00848b4d5c6bc0bfb1cb4ba2482 Mon Sep 17 00:00:00 2001 From: Archit Gupta Date: Wed, 21 Feb 2024 18:40:32 -0800 Subject: [PATCH] Allow using optFunctionTo on types with submodules --- builtinModules/devShells.nix | 5 ++--- default.nix | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/builtinModules/devShells.nix b/builtinModules/devShells.nix index 85ca49c..751e02e 100644 --- a/builtinModules/devShells.nix +++ b/builtinModules/devShells.nix @@ -5,7 +5,7 @@ { config, lib, flakelight, genSystems, moduleArgs, ... }: let inherit (lib) filterAttrs functionArgs mapAttrs mkIf mkMerge mkOption; - inherit (lib.types) attrs coercedTo functionTo lazyAttrsOf lines listOf + inherit (lib.types) coercedTo lazyAttrsOf lines listOf package str submodule; inherit (flakelight) supportedSystem; inherit (flakelight.types) function nullable optCallWith optFunctionTo; @@ -50,8 +50,7 @@ let else { overrideShell = val; }; devShellType = coercedTo function wrapFn - (coercedTo attrs (x: _: x) - (functionTo (submodule devShellModule))); + (optFunctionTo (submodule devShellModule)); genDevShell = pkgs: cfg: if cfg.overrideShell != null then cfg.overrideShell diff --git a/default.nix b/default.nix index d953fb8..a6a2c83 100644 --- a/default.nix +++ b/default.nix @@ -91,8 +91,18 @@ let optListOf = elemType: coercedTo elemType singleton (listOf elemType); - optFunctionTo = elemType: coercedTo elemType (x: _: x) - (functionTo elemType); + optFunctionTo = + let + nonFunction = mkOptionType { + name = "nonFunction"; + description = "non-function"; + descriptionClass = "noun"; + check = x: ! isFunction x; + merge = mergeOneOption; + }; + in + elemType: coercedTo nonFunction (x: _: x) + (functionTo elemType); optCallWith = args: elemType: coercedTo function (x: x args) elemType;