Make direct and auto-loaded configuration consistent

Many attributes can take moduleArgs when auto-loaded in order to
facilitate access to them from other files. Those same attributes could
not take moduleArgs when included directly, which was inconsistent.

With this change, all attributes that could take moduleArgs when
auto-loaded can now always do so. Auto-loading no longer needs special
cases.
This commit is contained in:
Archit Gupta 2024-01-14 19:17:50 -08:00
parent bb0080c21c
commit 589ee5ba7a
12 changed files with 45 additions and 39 deletions

View File

@ -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 = { };
};
};

View File

@ -2,11 +2,11 @@
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# 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 = { };
};
};

View File

@ -34,7 +34,7 @@ let
in
{
options.homeConfigurations = mkOption {
type = lazyAttrsOf (optCallWith moduleArgs attrs);
type = optCallWith moduleArgs (lazyAttrsOf (optCallWith moduleArgs attrs));
default = { };
};

View File

@ -2,11 +2,11 @@
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# 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 = { };
};
};

View File

@ -2,14 +2,15 @@
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# 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 = { };
};

View File

@ -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 [

View File

@ -28,7 +28,7 @@ let
in
{
options.nixosConfigurations = mkOption {
type = lazyAttrsOf (optCallWith moduleArgs attrs);
type = optCallWith moduleArgs (lazyAttrsOf (optCallWith moduleArgs attrs));
default = { };
};

View File

@ -2,11 +2,11 @@
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# 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 = { };
};
};

View File

@ -2,11 +2,11 @@
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# 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 = { };
};
};

View File

@ -2,14 +2,14 @@
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# 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 = { };
};

View File

@ -2,12 +2,13 @@
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# 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 = { };
};
};

View File

@ -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:
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;
if isFunction v then v args else v
);
selectAttr = attr: mapAttrs (_: v: v.${attr} or { });
in