Deprecate autoImport lib function

As all options are now automatically used for nixDir, modules no longer
need to set up their own autoImports.
This commit is contained in:
Archit Gupta 2024-01-15 00:26:05 -08:00
parent 4e9f53ff4e
commit 3b7188863d
2 changed files with 22 additions and 7 deletions

View File

@ -5,10 +5,23 @@
{ config, options, src, lib, flakelight, ... }: { config, options, src, lib, flakelight, ... }:
let let
inherit (builtins) attrNames; 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 (lib.types) attrsOf listOf str;
inherit (flakelight) autoImport; inherit (flakelight) importDir;
inherit (flakelight.types) path; 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 in
{ {
options = { options = {

View File

@ -36,8 +36,8 @@ let
}; };
flakelight = { flakelight = {
inherit autoImport autoImportArgs mkFlake selectAttr supportedSystem inherit autoImport autoImportArgs importDir mkFlake selectAttr
types; supportedSystem types;
}; };
types = { types = {
@ -114,8 +114,10 @@ let
else if pathExists (path + "/${p}.nix") then "/${p}.nix" else if pathExists (path + "/${p}.nix") then "/${p}.nix"
else "/${p}"))); else "/${p}")));
autoImport = dir: name: autoImport = dir: name: warn
if isList name ("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) then findFirst (x: x != null) null (map (autoImport dir) name)
else else
if pathExists (dir + "/${name}.nix") if pathExists (dir + "/${name}.nix")
@ -124,7 +126,7 @@ let
then import (dir + "/${name}") then import (dir + "/${name}")
else if pathExists (dir + "/${name}") else if pathExists (dir + "/${name}")
then importDir (dir + "/${name}") then importDir (dir + "/${name}")
else null; else null);
autoImportArgs = dir: args: name: warn autoImportArgs = dir: args: name: warn
("The autoImportArgs function is deprecated. " + ("The autoImportArgs function is deprecated. " +