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:
parent
afe17be81a
commit
0760edb005
13
API_GUIDE.md
13
API_GUIDE.md
@ -57,7 +57,7 @@ The following module arguments are available:
|
||||
- `flakelight`: flakelight lib attribute
|
||||
- `inputs`: value of inputs option
|
||||
- `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
|
||||
|
||||
@ -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
|
||||
set.
|
||||
|
||||
The `src`, `inputs`, `outputs`, and `flakelight` attributes are the same as the
|
||||
above module arguments.
|
||||
The `src`, `flakelight`, `inputs`, `outputs`, and `moduleArgs` attributes are
|
||||
the same as the above module arguments.
|
||||
|
||||
`inputs'` and `outputs'` are transformed versions of `inputs` and `outputs` with
|
||||
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.
|
||||
|
||||
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).
|
||||
|
||||
For example:
|
||||
@ -849,9 +849,8 @@ For a given supported attribute attr, the following is checked in order:
|
||||
files imported
|
||||
|
||||
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
|
||||
`lib`, `src`, `inputs`, `outputs`, and `flakelight`. For values without module
|
||||
args, these values can be obtained from pkgs args.
|
||||
enable use of module args from imported files. For values without module args,
|
||||
these values can be obtained from the pkg set as `moduleArgs` or directly.
|
||||
|
||||
To enable using a directory for an attrset that includes a `default` attribute,
|
||||
attr names can be escaped with an underscore. For example,
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
{ config, src, lib, inputs, outputs, flakelight, ... }:
|
||||
{ config, src, lib, inputs, outputs, flakelight, moduleArgs, ... }:
|
||||
let
|
||||
inherit (lib) isList mkOption mkOrder mapAttrs optionalAttrs;
|
||||
inherit (lib.types) listOf nullOr oneOf str;
|
||||
@ -29,7 +29,7 @@ in
|
||||
inherit (prev.stdenv.hostPlatform) system;
|
||||
in
|
||||
{
|
||||
inherit src inputs outputs flakelight system;
|
||||
inherit system moduleArgs src inputs outputs flakelight;
|
||||
inputs' = mapAttrs (_: mapAttrs (_: v: v.${system} or { })) inputs;
|
||||
outputs' = mapAttrs (_: v: v.${system} or { }) outputs;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
{ config, lib, flakelight, autoloadArgs, ... }:
|
||||
{ config, lib, flakelight, moduleArgs, ... }:
|
||||
let
|
||||
inherit (builtins) isAttrs mapAttrs;
|
||||
inherit (lib) foldl mapAttrsToList mergeOneOption mkOption mkOptionType mkIf
|
||||
@ -18,7 +18,7 @@ let
|
||||
merge = mergeOneOption;
|
||||
};
|
||||
|
||||
configs = mapAttrs (_: f: f autoloadArgs) config.homeConfigurations;
|
||||
configs = mapAttrs (_: f: f moduleArgs) config.homeConfigurations;
|
||||
in
|
||||
{
|
||||
options.homeConfigurations = mkOption {
|
||||
|
18
builtinModules/moduleArgs.nix
Normal file
18
builtinModules/moduleArgs.nix
Normal 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;
|
||||
}
|
@ -2,16 +2,14 @@
|
||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
{ config, src, lib, flakelight, inputs, outputs, ... }:
|
||||
{ config, src, lib, flakelight, moduleArgs, ... }:
|
||||
let
|
||||
inherit (lib) mkOption mkIf mkMerge optionalAttrs;
|
||||
inherit (flakelight) autoImport autoImportArgs;
|
||||
inherit (flakelight.types) path;
|
||||
|
||||
autoloadArgs = { inherit lib src inputs outputs flakelight; };
|
||||
|
||||
autoImport' = autoImport config.nixDir;
|
||||
autoImportArgs' = autoImportArgs config.nixDir autoloadArgs;
|
||||
autoImportArgs' = autoImportArgs config.nixDir moduleArgs;
|
||||
in
|
||||
{
|
||||
options.nixDir = mkOption {
|
||||
@ -49,8 +47,6 @@ in
|
||||
functor = autoImport' "functor";
|
||||
in
|
||||
mkMerge [
|
||||
{ _module.args = { inherit autoloadArgs; }; }
|
||||
|
||||
(mkIf (outputs != null) { inherit outputs; })
|
||||
(mkIf (perSystem != null) { inherit perSystem; })
|
||||
(mkIf (withOverlays != null) { inherit withOverlays; })
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
{ config, lib, flakelight, autoloadArgs, ... }:
|
||||
{ config, lib, flakelight, moduleArgs, ... }:
|
||||
let
|
||||
inherit (builtins) isAttrs mapAttrs;
|
||||
inherit (lib) foldl mapAttrsToList mergeOneOption mkIf mkOption mkOptionType
|
||||
@ -20,7 +20,7 @@ let
|
||||
merge = mergeOneOption;
|
||||
};
|
||||
|
||||
configs = mapAttrs (_: f: f autoloadArgs) config.nixosConfigurations;
|
||||
configs = mapAttrs (_: f: f moduleArgs) config.nixosConfigurations;
|
||||
in
|
||||
{
|
||||
options.nixosConfigurations = mkOption {
|
||||
|
@ -69,15 +69,15 @@ in
|
||||
}))
|
||||
(f: f.test);
|
||||
|
||||
outputs-autoloadArgs = test
|
||||
(flakelight ./empty ({ autoloadArgs, ... }: {
|
||||
outputs = { inherit autoloadArgs; };
|
||||
outputs-moduleArgs = test
|
||||
(flakelight ./empty ({ moduleArgs, ... }: {
|
||||
outputs = { inherit moduleArgs; };
|
||||
}))
|
||||
(f: f.autoloadArgs ? lib
|
||||
&& f.autoloadArgs ? src
|
||||
&& f.autoloadArgs ? inputs
|
||||
&& f.autoloadArgs ? outputs
|
||||
&& f.autoloadArgs ? flakelight);
|
||||
(f: f.moduleArgs ? lib
|
||||
&& f.moduleArgs ? src
|
||||
&& f.moduleArgs ? inputs
|
||||
&& f.moduleArgs ? outputs
|
||||
&& f.moduleArgs ? flakelight);
|
||||
|
||||
extra-pkgs-vals = test
|
||||
(flakelight ./empty {
|
||||
|
Loading…
Reference in New Issue
Block a user