From bb0080c21c603338ca49b59054e0c4f94bc0cf55 Mon Sep 17 00:00:00 2001 From: Archit Gupta Date: Sun, 14 Jan 2024 19:10:17 -0800 Subject: [PATCH] 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. --- builtinModules/core.nix | 6 +++--- builtinModules/functor.nix | 4 ++-- builtinModules/nixDir.nix | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtinModules/core.nix b/builtinModules/core.nix index 5b7fb23..6fc1453 100644 --- a/builtinModules/core.nix +++ b/builtinModules/core.nix @@ -2,13 +2,13 @@ # Copyright (C) 2023 Archit Gupta # SPDX-License-Identifier: MIT -{ config, inputs, lib, flakelight, ... }: +{ config, inputs, lib, flakelight, moduleArgs, ... }: let inherit (builtins) all head isAttrs length; inherit (lib) foldAttrs genAttrs getFiles getValues mapAttrs mergeAttrs mkOption mkOptionType showFiles showOption; inherit (lib.types) functionTo lazyAttrsOf listOf nonEmptyStr raw uniq; - inherit (flakelight.types) optListOf overlay; + inherit (flakelight.types) optCallWith optListOf overlay; outputs = mkOptionType { name = "outputs"; @@ -43,7 +43,7 @@ in }; outputs = mkOption { - type = lazyAttrsOf outputs; + type = optCallWith moduleArgs (lazyAttrsOf outputs); default = { }; }; diff --git a/builtinModules/functor.nix b/builtinModules/functor.nix index 79a4024..1697c9a 100644 --- a/builtinModules/functor.nix +++ b/builtinModules/functor.nix @@ -13,7 +13,7 @@ in default = null; }; - config.outputs = mkIf (config.functor != null) { + config.outputs = mkIf (config.functor != null) (_: { __functor = config.functor; - }; + }); } diff --git a/builtinModules/nixDir.nix b/builtinModules/nixDir.nix index cf02b2f..b78b7da 100644 --- a/builtinModules/nixDir.nix +++ b/builtinModules/nixDir.nix @@ -19,7 +19,7 @@ in config = let - outputs = autoImportArgs' "outputs"; + outputs = autoImport' "outputs"; perSystem = autoImport' "perSystem"; withOverlays = autoImport' "withOverlays"; package = autoImport' "package";