diff --git a/builtinModules/devShells.nix b/builtinModules/devShells.nix index c42bbef..b822f5d 100644 --- a/builtinModules/devShells.nix +++ b/builtinModules/devShells.nix @@ -10,7 +10,7 @@ let inherit (lib.types) coercedTo functionTo lazyAttrsOf lines listOf nullOr package str submodule; inherit (flakelight) supportedSystem; - inherit (flakelight.types) function optFunctionTo packageDef; + inherit (flakelight.types) function optCallWith optFunctionTo packageDef; devShellModule.options = { inputsFrom = mkOption { @@ -59,7 +59,7 @@ in }; devShells = mkOption { - type = lazyAttrsOf packageDef; + type = optCallWith moduleArgs (lazyAttrsOf packageDef); default = { }; }; }; diff --git a/builtinModules/flakelightModules.nix b/builtinModules/flakelightModules.nix index eb4f5ae..2c04c08 100644 --- a/builtinModules/flakelightModules.nix +++ b/builtinModules/flakelightModules.nix @@ -2,11 +2,11 @@ # Copyright (C) 2023 Archit Gupta # SPDX-License-Identifier: MIT -{ config, lib, flakelight, ... }: +{ config, lib, flakelight, moduleArgs, ... }: let inherit (lib) mkOption mkIf mkMerge; inherit (lib.types) lazyAttrsOf nullOr; - inherit (flakelight.types) module; + inherit (flakelight.types) module optCallWith; in { options = { @@ -16,7 +16,7 @@ in }; flakelightModules = mkOption { - type = lazyAttrsOf module; + type = optCallWith moduleArgs (lazyAttrsOf module); default = { }; }; }; diff --git a/builtinModules/homeConfigurations.nix b/builtinModules/homeConfigurations.nix index 4bf8f2c..f1987d2 100644 --- a/builtinModules/homeConfigurations.nix +++ b/builtinModules/homeConfigurations.nix @@ -34,7 +34,7 @@ let in { options.homeConfigurations = mkOption { - type = lazyAttrsOf (optCallWith moduleArgs attrs); + type = optCallWith moduleArgs (lazyAttrsOf (optCallWith moduleArgs attrs)); default = { }; }; diff --git a/builtinModules/homeModules.nix b/builtinModules/homeModules.nix index ada8d39..a462eca 100644 --- a/builtinModules/homeModules.nix +++ b/builtinModules/homeModules.nix @@ -2,11 +2,11 @@ # Copyright (C) 2023 Archit Gupta # SPDX-License-Identifier: MIT -{ config, lib, flakelight, ... }: +{ config, lib, flakelight, moduleArgs, ... }: let inherit (lib) mkOption mkIf mkMerge; inherit (lib.types) lazyAttrsOf nullOr; - inherit (flakelight.types) module; + inherit (flakelight.types) module optCallWith; in { options = { @@ -16,7 +16,7 @@ in }; homeModules = mkOption { - type = lazyAttrsOf module; + type = optCallWith moduleArgs (lazyAttrsOf module); default = { }; }; }; diff --git a/builtinModules/lib.nix b/builtinModules/lib.nix index a25c2f4..72e50b2 100644 --- a/builtinModules/lib.nix +++ b/builtinModules/lib.nix @@ -2,14 +2,15 @@ # Copyright (C) 2023 Archit Gupta # SPDX-License-Identifier: MIT -{ config, lib, ... }: +{ config, lib, flakelight, moduleArgs, ... }: let inherit (lib) mkOption mkIf; inherit (lib.types) attrsOf raw; + inherit (flakelight.types) optCallWith; in { options.lib = mkOption { - type = attrsOf raw; + type = optCallWith moduleArgs (attrsOf raw); default = { }; }; diff --git a/builtinModules/nixDir.nix b/builtinModules/nixDir.nix index b78b7da..895c9c4 100644 --- a/builtinModules/nixDir.nix +++ b/builtinModules/nixDir.nix @@ -23,27 +23,27 @@ in perSystem = autoImport' "perSystem"; withOverlays = autoImport' "withOverlays"; package = autoImport' "package"; - packages = autoImportArgs' "packages"; - overlays = autoImportArgs' "overlays"; + packages = autoImport' "packages"; + overlays = autoImport' "overlays"; devShell = autoImport' "devShell"; - devShells = autoImportArgs' "devShells"; + devShells = autoImport' "devShells"; app = autoImport' "app"; apps = autoImport' "apps"; checks = autoImport' "checks"; - template = autoImportArgs' "template"; - templates = autoImportArgs' "templates"; + template = autoImport' "template"; + templates = autoImport' "templates"; formatters = autoImport' "formatters"; bundler = autoImport' "bundler"; bundlers = autoImport' "bundlers"; nixosModule = autoImport' "nixosModule"; - nixosModules = autoImportArgs' "nixosModules"; - nixosConfigurations = autoImportArgs' [ "nixosConfigurations" "nixos" ]; + nixosModules = autoImport' "nixosModules"; + nixosConfigurations = autoImport' [ "nixosConfigurations" "nixos" ]; homeModule = autoImport' "homeModule"; - homeModules = autoImportArgs' "homeModules"; - homeConfigurations = autoImportArgs' [ "homeConfigurations" "home" ]; + homeModules = autoImport' "homeModules"; + homeConfigurations = autoImport' [ "homeConfigurations" "home" ]; flakelightModule = autoImport' "flakelightModule"; - flakelightModules = autoImportArgs' "flakelightModules"; - lib = autoImportArgs' "lib"; + flakelightModules = autoImport' "flakelightModules"; + lib = autoImport' "lib"; functor = autoImport' "functor"; in mkMerge [ diff --git a/builtinModules/nixosConfigurations.nix b/builtinModules/nixosConfigurations.nix index 96746cf..0669f74 100644 --- a/builtinModules/nixosConfigurations.nix +++ b/builtinModules/nixosConfigurations.nix @@ -28,7 +28,7 @@ let in { options.nixosConfigurations = mkOption { - type = lazyAttrsOf (optCallWith moduleArgs attrs); + type = optCallWith moduleArgs (lazyAttrsOf (optCallWith moduleArgs attrs)); default = { }; }; diff --git a/builtinModules/nixosModules.nix b/builtinModules/nixosModules.nix index 6df17b7..57fa488 100644 --- a/builtinModules/nixosModules.nix +++ b/builtinModules/nixosModules.nix @@ -2,11 +2,11 @@ # Copyright (C) 2023 Archit Gupta # SPDX-License-Identifier: MIT -{ config, lib, flakelight, ... }: +{ config, lib, flakelight, moduleArgs, ... }: let inherit (lib) mkOption mkIf mkMerge; inherit (lib.types) lazyAttrsOf nullOr; - inherit (flakelight.types) module; + inherit (flakelight.types) module optCallWith; in { options = { @@ -16,7 +16,7 @@ in }; nixosModules = mkOption { - type = lazyAttrsOf module; + type = optCallWith moduleArgs (lazyAttrsOf module); default = { }; }; }; diff --git a/builtinModules/overlays.nix b/builtinModules/overlays.nix index 19cadcb..160f66c 100644 --- a/builtinModules/overlays.nix +++ b/builtinModules/overlays.nix @@ -2,11 +2,11 @@ # Copyright (C) 2023 Archit Gupta # SPDX-License-Identifier: MIT -{ config, lib, flakelight, ... }: +{ config, lib, flakelight, moduleArgs, ... }: let inherit (lib) mkMerge mkOption mkIf; inherit (lib.types) lazyAttrsOf nullOr; - inherit (flakelight.types) overlay; + inherit (flakelight.types) optCallWith overlay; in { options = { @@ -16,7 +16,7 @@ in }; overlays = mkOption { - type = lazyAttrsOf overlay; + type = optCallWith moduleArgs (lazyAttrsOf overlay); default = { }; }; }; diff --git a/builtinModules/packages.nix b/builtinModules/packages.nix index 68aaea6..d3a1c0c 100644 --- a/builtinModules/packages.nix +++ b/builtinModules/packages.nix @@ -2,14 +2,14 @@ # Copyright (C) 2023 Archit Gupta # SPDX-License-Identifier: MIT -{ config, lib, inputs, flakelight, genSystems, ... }: +{ config, lib, inputs, flakelight, genSystems, moduleArgs, ... }: let inherit (builtins) parseDrvName tryEval; inherit (lib) filterAttrs findFirst mapAttrs mapAttrs' mkIf mkMerge mkOption nameValuePair optionalAttrs; inherit (lib.types) lazyAttrsOf nullOr str uniq; inherit (flakelight) supportedSystem; - inherit (flakelight.types) overlay packageDef; + inherit (flakelight.types) optCallWith overlay packageDef; genPkg = pkgs: pkg: pkgs.callPackage pkg { }; genPkgs = pkgs: mapAttrs (_: genPkg pkgs) config.packages; @@ -22,7 +22,7 @@ in }; packages = mkOption { - type = lazyAttrsOf packageDef; + type = optCallWith moduleArgs (lazyAttrsOf packageDef); default = { }; }; diff --git a/builtinModules/templates.nix b/builtinModules/templates.nix index c02a75b..95823ec 100644 --- a/builtinModules/templates.nix +++ b/builtinModules/templates.nix @@ -2,12 +2,13 @@ # Copyright (C) 2023 Archit Gupta # SPDX-License-Identifier: MIT -{ config, lib, ... }: +{ config, lib, flakelight, moduleArgs, ... }: let inherit (builtins) isPath isString; inherit (lib) mkOption mkOptionType mkIf mkMerge; inherit (lib.types) lazyAttrsOf nullOr; inherit (lib.options) mergeEqualOption; + inherit (flakelight.types) optCallWith; template = mkOptionType { name = "template"; @@ -22,12 +23,12 @@ in { options = { template = mkOption { - type = nullOr template; + type = nullOr (optCallWith moduleArgs template); default = null; }; templates = mkOption { - type = lazyAttrsOf template; + type = optCallWith moduleArgs (lazyAttrsOf template); default = { }; }; }; diff --git a/default.nix b/default.nix index d2a7995..ea5748c 100644 --- a/default.nix +++ b/default.nix @@ -9,7 +9,7 @@ let inherit (nixpkgs.lib) attrNames composeManyExtensions evalModules filter findFirst fix genAttrs getValues hasSuffix isFunction isList mapAttrs mapAttrsToList mkDefault mkOptionType pathExists pipe removePrefix - removeSuffix singleton; + removeSuffix singleton warn; inherit (nixpkgs.lib.types) coercedTo functionTo listOf; inherit (nixpkgs.lib.options) mergeEqualOption mergeOneOption; @@ -126,9 +126,13 @@ let then importDir (dir + "/${name}") else null; - autoImportArgs = dir: args: name: - let v = autoImport dir name; in - if isFunction v then v args else v; + autoImportArgs = dir: args: name: warn + ("The autoImportArgs function is deprecated. " + + "Wrap the target type in flakelight.types.optCallWith instead.") + ( + let v = autoImport dir name; in + if isFunction v then v args else v + ); selectAttr = attr: mapAttrs (_: v: v.${attr} or { }); in