diff --git a/builtinModules/nixDir.nix b/builtinModules/nixDir.nix index 100963b..6819308 100644 --- a/builtinModules/nixDir.nix +++ b/builtinModules/nixDir.nix @@ -5,10 +5,23 @@ { config, options, src, lib, flakelight, ... }: let inherit (builtins) attrNames; - inherit (lib) genAttrs mkIf mkOption subtractLists; + inherit (lib) findFirst genAttrs isList mkIf mkOption pathExists + subtractLists; inherit (lib.types) attrsOf listOf str; - inherit (flakelight) autoImport; + inherit (flakelight) importDir; inherit (flakelight.types) path; + + autoImport = dir: name: + if isList name + then findFirst (x: x != null) null (map (autoImport dir) name) + else + if pathExists (dir + "/${name}.nix") + then import (dir + "/${name}.nix") + else if pathExists (dir + "/${name}/default.nix") + then import (dir + "/${name}") + else if pathExists (dir + "/${name}") + then importDir (dir + "/${name}") + else null; in { options = { diff --git a/default.nix b/default.nix index ea5748c..84f468d 100644 --- a/default.nix +++ b/default.nix @@ -36,8 +36,8 @@ let }; flakelight = { - inherit autoImport autoImportArgs mkFlake selectAttr supportedSystem - types; + inherit autoImport autoImportArgs importDir mkFlake selectAttr + supportedSystem types; }; types = { @@ -114,8 +114,10 @@ let else if pathExists (path + "/${p}.nix") then "/${p}.nix" else "/${p}"))); - autoImport = dir: name: - if isList name + autoImport = dir: name: warn + ("The autoImport function is deprecated. " + + "All options are now automatically auto-loaded.") + (if isList name then findFirst (x: x != null) null (map (autoImport dir) name) else if pathExists (dir + "/${name}.nix") @@ -124,7 +126,7 @@ let then import (dir + "/${name}") else if pathExists (dir + "/${name}") then importDir (dir + "/${name}") - else null; + else null); autoImportArgs = dir: args: name: warn ("The autoImportArgs function is deprecated. " +