diff --git a/dev/tests/eval-tests.nix b/dev/tests/eval-tests.nix index 5990332..355fca4 100644 --- a/dev/tests/eval-tests.nix +++ b/dev/tests/eval-tests.nix @@ -169,6 +169,22 @@ rec { partitionedAttrs.devShells = "dev"; }); + dogfoodProvider = mkFlake + { inputs.self = { }; } + ({ flake-parts-lib, ... }: { + imports = [ + (flake-parts-lib.importAndPublish "dogfood" { flake.marker = "dogfood"; }) + ]; + }); + + dogfoodConsumer = mkFlake + { inputs.self = { }; } + ({ flake-parts-lib, ... }: { + imports = [ + dogfoodProvider.modules.flake.dogfood + ]; + }); + runTests = ok: assert empty == { @@ -255,6 +271,9 @@ rec { assert builtins.isAttrs partitionWithoutExtraInputsFlake.devShells.x86_64-linux; + assert dogfoodProvider.marker == "dogfood"; + assert dogfoodConsumer.marker == "dogfood"; + ok; result = runTests "ok"; diff --git a/lib.nix b/lib.nix index 31cebeb..5031a46 100644 --- a/lib.nix +++ b/lib.nix @@ -221,6 +221,20 @@ let importApply = modulePath: staticArgs: lib.setDefaultModuleLocation modulePath (import modulePath staticArgs); + + /** + `importAndPublish name module` returns a module that both imports the `module`, and exposes it as flake attribute `modules.flake.${name}`. + + This also imports the optional [`modules`](https://flake.parts/options/flake-parts-modules.html) module to support that. + */ + importAndPublish = name: module: { lib, ... }: { + _class = "flake"; + imports = [ + module + ./extras/modules.nix + ]; + flake.modules.flake.${name} = module; + }; }; # A best effort, lenient estimate. Please use a recent nixpkgs lib if you