Fix inconsistency when setting outputs.__functor

This edge case was inconsistent between setting outputs directly and
auto-loading. Setting directly did not support args, so just merged
sets, thus resulting in a __functor flake output. When autoloading, a
set with a __functor attr was treated as a function and passed module
args.

To correct this inconsistency, outputs now always supports taking args,
and has the autoloading behavior.

Code that relied on previous behavior is easy to fix, as the value needs
to be converted to a function, which can then return the set with
__functor.
This commit is contained in:
Archit Gupta 2024-01-14 19:10:17 -08:00
parent f2c32f5a42
commit bb0080c21c
3 changed files with 6 additions and 6 deletions

View File

@ -2,13 +2,13 @@
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com> # Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
{ config, inputs, lib, flakelight, ... }: { config, inputs, lib, flakelight, moduleArgs, ... }:
let let
inherit (builtins) all head isAttrs length; inherit (builtins) all head isAttrs length;
inherit (lib) foldAttrs genAttrs getFiles getValues mapAttrs mergeAttrs inherit (lib) foldAttrs genAttrs getFiles getValues mapAttrs mergeAttrs
mkOption mkOptionType showFiles showOption; mkOption mkOptionType showFiles showOption;
inherit (lib.types) functionTo lazyAttrsOf listOf nonEmptyStr raw uniq; inherit (lib.types) functionTo lazyAttrsOf listOf nonEmptyStr raw uniq;
inherit (flakelight.types) optListOf overlay; inherit (flakelight.types) optCallWith optListOf overlay;
outputs = mkOptionType { outputs = mkOptionType {
name = "outputs"; name = "outputs";
@ -43,7 +43,7 @@ in
}; };
outputs = mkOption { outputs = mkOption {
type = lazyAttrsOf outputs; type = optCallWith moduleArgs (lazyAttrsOf outputs);
default = { }; default = { };
}; };

View File

@ -13,7 +13,7 @@ in
default = null; default = null;
}; };
config.outputs = mkIf (config.functor != null) { config.outputs = mkIf (config.functor != null) (_: {
__functor = config.functor; __functor = config.functor;
}; });
} }

View File

@ -19,7 +19,7 @@ in
config = config =
let let
outputs = autoImportArgs' "outputs"; outputs = autoImport' "outputs";
perSystem = autoImport' "perSystem"; perSystem = autoImport' "perSystem";
withOverlays = autoImport' "withOverlays"; withOverlays = autoImport' "withOverlays";
package = autoImport' "package"; package = autoImport' "package";