mirror of
https://github.com/Gerg-L/nixos.git
synced 2025-12-10 00:43:56 -05:00
document __functor fun (badly)
This commit is contained in:
parent
c2154e01b7
commit
894080a801
1 changed files with 60 additions and 17 deletions
|
|
@ -51,24 +51,22 @@ rec {
|
||||||
addSchizophreniaToModule =
|
addSchizophreniaToModule =
|
||||||
x:
|
x:
|
||||||
let
|
let
|
||||||
|
# the imported module
|
||||||
imported = import x;
|
imported = import x;
|
||||||
in
|
in
|
||||||
|
/*
|
||||||
|
If the module isn't a function then
|
||||||
|
it doesn't need arguments and error
|
||||||
|
message locations will function correctly
|
||||||
|
*/
|
||||||
if !lib.isFunction imported then
|
if !lib.isFunction imported then
|
||||||
x
|
x
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
|
/*
|
||||||
allArgs = {
|
The names of all arguments which will be
|
||||||
inherit inputs self;
|
available to be inserted into the module arguments
|
||||||
_dir =
|
*/
|
||||||
let
|
|
||||||
dir = builtins.dirOf x;
|
|
||||||
in
|
|
||||||
if (dir == builtins.storeDir) then null else dir;
|
|
||||||
};
|
|
||||||
|
|
||||||
funcArgs = lib.functionArgs imported;
|
|
||||||
|
|
||||||
argNames = builtins.attrNames inputs ++ [
|
argNames = builtins.attrNames inputs ++ [
|
||||||
"inputs"
|
"inputs"
|
||||||
"inputs'"
|
"inputs'"
|
||||||
|
|
@ -76,24 +74,70 @@ rec {
|
||||||
"_dir"
|
"_dir"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/*
|
||||||
|
arguments to be passed minus
|
||||||
|
per system attributes
|
||||||
|
for example flake-parts-esque inputs'
|
||||||
|
*/
|
||||||
|
argsPre = {
|
||||||
|
inherit inputs self;
|
||||||
|
/*
|
||||||
|
_dir is the "self" derived
|
||||||
|
path to the directory containing the module
|
||||||
|
*/
|
||||||
|
_dir =
|
||||||
|
let
|
||||||
|
dir = builtins.dirOf x;
|
||||||
|
in
|
||||||
|
# Probably don't need this error check
|
||||||
|
if (dir == builtins.storeDir) then null else dir;
|
||||||
|
};
|
||||||
|
|
||||||
|
# all arguments defined in the module
|
||||||
|
funcArgs = lib.functionArgs imported;
|
||||||
|
|
||||||
|
/*
|
||||||
|
arguments which will be inserted
|
||||||
|
set to the before per-system values
|
||||||
|
*/
|
||||||
providedArgs = lib.pipe funcArgs [
|
providedArgs = lib.pipe funcArgs [
|
||||||
(lib.filterAttrs (n: _: builtins.elem n argNames))
|
(lib.filterAttrs (n: _: builtins.elem n argNames))
|
||||||
(lib.mapAttrs (n: _: allArgs.${n} or { }))
|
(lib.mapAttrs (n: _: argsPre.${n} or { }))
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/*
|
||||||
|
arguments which the module system
|
||||||
|
not provided here. either to be
|
||||||
|
provided by the module system or invalid
|
||||||
|
*/
|
||||||
neededArgs = lib.filterAttrs (n: _: !builtins.elem n argNames) funcArgs;
|
neededArgs = lib.filterAttrs (n: _: !builtins.elem n argNames) funcArgs;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
__functionArgs = neededArgs // {
|
||||||
|
/*
|
||||||
|
always require pkgs to be passed
|
||||||
|
to derive system from pkgs.stdenv.system
|
||||||
|
*/
|
||||||
|
pkgs = false;
|
||||||
|
};
|
||||||
|
|
||||||
__functor =
|
__functor =
|
||||||
|
/*
|
||||||
|
args is specialArgs + _module.args which are needed
|
||||||
|
and always pkgs
|
||||||
|
*/
|
||||||
_: args:
|
_: args:
|
||||||
imported (
|
imported (
|
||||||
|
# take module system provided arguments
|
||||||
(lib.filterAttrs (n: _: neededArgs ? ${n}) args)
|
(lib.filterAttrs (n: _: neededArgs ? ${n}) args)
|
||||||
# (formatter helping comment)
|
# add needed arguments
|
||||||
// (
|
// (
|
||||||
providedArgs
|
providedArgs
|
||||||
|
# add system dependent arguments
|
||||||
// (
|
// (
|
||||||
let
|
let
|
||||||
inputs' = constructInputs' args.pkgs.stdenv.system inputs;
|
inputs' = constructInputs' args.pkgs.stdenv.system inputs;
|
||||||
|
|
||||||
actuallyAllArgs = inputs' // {
|
actuallyAllArgs = inputs' // {
|
||||||
inherit inputs';
|
inherit inputs';
|
||||||
self' = inputs'.self;
|
self' = inputs'.self;
|
||||||
|
|
@ -104,12 +148,11 @@ rec {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
# add _file to the final module attribute set
|
||||||
// {
|
// {
|
||||||
_file = x;
|
_file = x;
|
||||||
};
|
};
|
||||||
__functionArgs = neededArgs // {
|
|
||||||
pkgs = false;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
gerg-utils =
|
gerg-utils =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue