Merge pull request #291 from hercules-ci/better-dogfooding

Add `flake-parts-lib.importAndPublish`
This commit is contained in:
Robert Hensing 2025-06-08 17:59:32 +02:00 committed by GitHub
commit 9305fe4e5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View file

@ -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";

14
lib.nix
View file

@ -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