mirror of
https://github.com/hercules-ci/flake-parts.git
synced 2024-12-14 11:47:31 +00:00
Fix infinite recursion in inputs
This commit is contained in:
parent
8d0e2444ab
commit
bcb7065174
6 changed files with 75 additions and 15 deletions
18
ChangeLog.md
18
ChangeLog.md
|
@ -1,4 +1,22 @@
|
|||
|
||||
# 2022-12-17
|
||||
|
||||
- The old syntax `mkFlake { inherit self; }` is now strongly discouraged in
|
||||
favor of:
|
||||
|
||||
```nix
|
||||
outputs = inputs@{ flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } { /* module */ }
|
||||
```
|
||||
|
||||
This fixes an infinite recursion that occurs with the old syntax when
|
||||
using the `inputs` module argument in `imports`.
|
||||
|
||||
If you're under the impression that this already worked, that's probably
|
||||
because you were using `inputs` from the lexical scope (ie directly from
|
||||
the flake outputs function arguments), rather than in a separate module file.
|
||||
|
||||
|
||||
# 2022-12-07
|
||||
|
||||
- The `darwinModules` option has been removed. This was added in the early days
|
||||
|
|
|
@ -56,8 +56,8 @@ Otherwise, add the input,
|
|||
then slide `mkFlake` between your outputs function head and body,
|
||||
|
||||
```
|
||||
outputs = { self, flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit self; } {
|
||||
outputs = inputs@{ flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
flake = {
|
||||
# Put your original flake attributes here.
|
||||
};
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
let
|
||||
flake = builtins.getFlake (toString ./.);
|
||||
fmc-lib = (builtins.getFlake (toString ../.)).lib;
|
||||
args = {
|
||||
inherit self;
|
||||
} // flake.inputs;
|
||||
self = {
|
||||
inherit (flake) inputs;
|
||||
outPath = ../.; # used by pre-commit module, etc
|
||||
outputs = self.config.flake;
|
||||
} //
|
||||
fmc-lib.evalFlakeModule
|
||||
{ inherit self; }
|
||||
fmc-lib.mkFlake
|
||||
{ inputs = args; }
|
||||
./flake-module.nix;
|
||||
in
|
||||
self.config.flake // { inherit (flake) inputs; }
|
||||
|
|
49
lib.nix
49
lib.nix
|
@ -7,7 +7,9 @@ let
|
|||
isAttrs
|
||||
isFunction
|
||||
showOption
|
||||
throwIf
|
||||
types
|
||||
warnIf
|
||||
;
|
||||
inherit (lib.types)
|
||||
path
|
||||
|
@ -60,18 +62,55 @@ let
|
|||
}
|
||||
);
|
||||
|
||||
errorExample = ''
|
||||
For example:
|
||||
|
||||
outputs = inputs@{ flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } { /* module */ };
|
||||
|
||||
To avoid an infinite recursion, *DO NOT* pass `self.inputs` and
|
||||
*DO NOT* pass `inherit (self) inputs`, but pass the output function
|
||||
arguments as `inputs` like above.
|
||||
'';
|
||||
|
||||
flake-parts-lib = {
|
||||
evalFlakeModule =
|
||||
{ self
|
||||
args@
|
||||
{ inputs ? self.inputs
|
||||
, specialArgs ? { }
|
||||
}:
|
||||
module:
|
||||
|
||||
# legacy
|
||||
, self ? inputs.self or (throw ''
|
||||
When invoking flake-parts, you must pass all the flake output arguments,
|
||||
and not just `self.inputs`.
|
||||
|
||||
${errorExample}
|
||||
'')
|
||||
}:
|
||||
throwIf
|
||||
(!args?self && !args?inputs) ''
|
||||
When invoking flake-parts, you must pass in the flake output arguments.
|
||||
|
||||
${errorExample}
|
||||
''
|
||||
warnIf
|
||||
(!args?inputs) ''
|
||||
When invoking flake-parts, it is recommended to pass all the flake output
|
||||
arguments in the `inputs` parameter. If you only pass `self`, it's not
|
||||
possible to use the `inputs` module argument in the module `imports`.
|
||||
|
||||
Please pass the output function arguments. ${errorExample}
|
||||
''
|
||||
|
||||
(module:
|
||||
lib.evalModules {
|
||||
specialArgs = { inherit self flake-parts-lib; inherit (self) inputs; } // specialArgs;
|
||||
specialArgs = {
|
||||
inherit self flake-parts-lib;
|
||||
inputs = args.inputs or /* legacy, warned above */ self.inputs;
|
||||
} // specialArgs;
|
||||
modules = [ ./all-modules.nix module ];
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
mkFlake = args: module:
|
||||
(flake-parts-lib.evalFlakeModule args module).config.flake;
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
};
|
||||
|
||||
outputs = { self, flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit self; } {
|
||||
outputs = inputs@{ flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [
|
||||
# To import a flake module
|
||||
# 1. Add foo to inputs
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
};
|
||||
|
||||
outputs = { self, flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit self; } {
|
||||
outputs = inputs@{ flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [
|
||||
./hello/flake-module.nix
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue