1
1
forked from extern/flakelight

Refactor autoloadArgs to moduleArgs

The set of args passed to modules is useful for more than just
autoloading. This renames it appropriately and makes it available
through pkgs arguments as well.
This commit is contained in:
Archit Gupta 2024-01-09 21:20:44 -08:00
parent afe17be81a
commit 0760edb005
7 changed files with 40 additions and 27 deletions

View File

@ -57,7 +57,7 @@ The following module arguments are available:
- `flakelight`: flakelight lib attribute - `flakelight`: flakelight lib attribute
- `inputs`: value of inputs option - `inputs`: value of inputs option
- `outputs`: resulting output (i.e. final flake attributes) - `outputs`: resulting output (i.e. final flake attributes)
- `autoloadArgs`: arguments passed to supported autoloaded files - `moduleArgs`: All of the above arguments (passed to auto-loaded files)
## Additional pkgs values ## Additional pkgs values
@ -65,8 +65,8 @@ Functions that take the package set as an argument, such as package definitions
or `perSystem` values, have several additional values available in the package or `perSystem` values, have several additional values available in the package
set. set.
The `src`, `inputs`, `outputs`, and `flakelight` attributes are the same as the The `src`, `flakelight`, `inputs`, `outputs`, and `moduleArgs` attributes are
above module arguments. the same as the above module arguments.
`inputs'` and `outputs'` are transformed versions of `inputs` and `outputs` with `inputs'` and `outputs'` are transformed versions of `inputs` and `outputs` with
system preselected. I.e., `inputs.emacs-overlay.packages.x86_64-linux.default` system preselected. I.e., `inputs.emacs-overlay.packages.x86_64-linux.default`
@ -692,7 +692,7 @@ outputs for NixOS systems and home-manager users.
They should be set to an attribute set of respective configurations. They should be set to an attribute set of respective configurations.
Alternatively, the configurations can be functions, in which case those Alternatively, the configurations can be functions, in which case those
functions will be passed `autoloadArgs` and must return a standard functions will be passed `moduleArgs` and must return a standard
configuration (this is useful when using autoloads with the `nixDir` feature). configuration (this is useful when using autoloads with the `nixDir` feature).
For example: For example:
@ -849,9 +849,8 @@ For a given supported attribute attr, the following is checked in order:
files imported files imported
Many of the values can additionally be a function that takes module args to Many of the values can additionally be a function that takes module args to
enable use of module args from imported files. The module args available are enable use of module args from imported files. For values without module args,
`lib`, `src`, `inputs`, `outputs`, and `flakelight`. For values without module these values can be obtained from the pkg set as `moduleArgs` or directly.
args, these values can be obtained from pkgs args.
To enable using a directory for an attrset that includes a `default` attribute, To enable using a directory for an attrset that includes a `default` attribute,
attr names can be escaped with an underscore. For example, attr names can be escaped with an underscore. For example,

View File

@ -2,7 +2,7 @@
# 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, src, lib, inputs, outputs, flakelight, ... }: { config, src, lib, inputs, outputs, flakelight, moduleArgs, ... }:
let let
inherit (lib) isList mkOption mkOrder mapAttrs optionalAttrs; inherit (lib) isList mkOption mkOrder mapAttrs optionalAttrs;
inherit (lib.types) listOf nullOr oneOf str; inherit (lib.types) listOf nullOr oneOf str;
@ -29,7 +29,7 @@ in
inherit (prev.stdenv.hostPlatform) system; inherit (prev.stdenv.hostPlatform) system;
in in
{ {
inherit src inputs outputs flakelight system; inherit system moduleArgs src inputs outputs flakelight;
inputs' = mapAttrs (_: mapAttrs (_: v: v.${system} or { })) inputs; inputs' = mapAttrs (_: mapAttrs (_: v: v.${system} or { })) inputs;
outputs' = mapAttrs (_: v: v.${system} or { }) outputs; outputs' = mapAttrs (_: v: v.${system} or { }) outputs;

View File

@ -2,7 +2,7 @@
# 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, lib, flakelight, autoloadArgs, ... }: { config, lib, flakelight, moduleArgs, ... }:
let let
inherit (builtins) isAttrs mapAttrs; inherit (builtins) isAttrs mapAttrs;
inherit (lib) foldl mapAttrsToList mergeOneOption mkOption mkOptionType mkIf inherit (lib) foldl mapAttrsToList mergeOneOption mkOption mkOptionType mkIf
@ -18,7 +18,7 @@ let
merge = mergeOneOption; merge = mergeOneOption;
}; };
configs = mapAttrs (_: f: f autoloadArgs) config.homeConfigurations; configs = mapAttrs (_: f: f moduleArgs) config.homeConfigurations;
in in
{ {
options.homeConfigurations = mkOption { options.homeConfigurations = mkOption {

View File

@ -0,0 +1,18 @@
# flakelight -- Framework for simplifying flake setup
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# SPDX-License-Identifier: MIT
{ config
, options
, src
, lib
, flakelight
, inputs
, outputs
, specialArgs
, modulesPath
, moduleArgs
}@args:
{
_module.args.moduleArgs = args;
}

View File

@ -2,16 +2,14 @@
# 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, src, lib, flakelight, inputs, outputs, ... }: { config, src, lib, flakelight, moduleArgs, ... }:
let let
inherit (lib) mkOption mkIf mkMerge optionalAttrs; inherit (lib) mkOption mkIf mkMerge optionalAttrs;
inherit (flakelight) autoImport autoImportArgs; inherit (flakelight) autoImport autoImportArgs;
inherit (flakelight.types) path; inherit (flakelight.types) path;
autoloadArgs = { inherit lib src inputs outputs flakelight; };
autoImport' = autoImport config.nixDir; autoImport' = autoImport config.nixDir;
autoImportArgs' = autoImportArgs config.nixDir autoloadArgs; autoImportArgs' = autoImportArgs config.nixDir moduleArgs;
in in
{ {
options.nixDir = mkOption { options.nixDir = mkOption {
@ -49,8 +47,6 @@ in
functor = autoImport' "functor"; functor = autoImport' "functor";
in in
mkMerge [ mkMerge [
{ _module.args = { inherit autoloadArgs; }; }
(mkIf (outputs != null) { inherit outputs; }) (mkIf (outputs != null) { inherit outputs; })
(mkIf (perSystem != null) { inherit perSystem; }) (mkIf (perSystem != null) { inherit perSystem; })
(mkIf (withOverlays != null) { inherit withOverlays; }) (mkIf (withOverlays != null) { inherit withOverlays; })

View File

@ -2,7 +2,7 @@
# 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, lib, flakelight, autoloadArgs, ... }: { config, lib, flakelight, moduleArgs, ... }:
let let
inherit (builtins) isAttrs mapAttrs; inherit (builtins) isAttrs mapAttrs;
inherit (lib) foldl mapAttrsToList mergeOneOption mkIf mkOption mkOptionType inherit (lib) foldl mapAttrsToList mergeOneOption mkIf mkOption mkOptionType
@ -20,7 +20,7 @@ let
merge = mergeOneOption; merge = mergeOneOption;
}; };
configs = mapAttrs (_: f: f autoloadArgs) config.nixosConfigurations; configs = mapAttrs (_: f: f moduleArgs) config.nixosConfigurations;
in in
{ {
options.nixosConfigurations = mkOption { options.nixosConfigurations = mkOption {

View File

@ -69,15 +69,15 @@ in
})) }))
(f: f.test); (f: f.test);
outputs-autoloadArgs = test outputs-moduleArgs = test
(flakelight ./empty ({ autoloadArgs, ... }: { (flakelight ./empty ({ moduleArgs, ... }: {
outputs = { inherit autoloadArgs; }; outputs = { inherit moduleArgs; };
})) }))
(f: f.autoloadArgs ? lib (f: f.moduleArgs ? lib
&& f.autoloadArgs ? src && f.moduleArgs ? src
&& f.autoloadArgs ? inputs && f.moduleArgs ? inputs
&& f.autoloadArgs ? outputs && f.moduleArgs ? outputs
&& f.autoloadArgs ? flakelight); && f.moduleArgs ? flakelight);
extra-pkgs-vals = test extra-pkgs-vals = test
(flakelight ./empty { (flakelight ./empty {