Add the lib default output #4

Merged
dzu merged 1 commit from feat-output-lib into main 2026-11-25 15:03:49 +01:00
3 changed files with 70 additions and 0 deletions

View file

@ -1,6 +1,7 @@
args: { args: {
definition = import ./def.nix; definition = import ./def.nix;
defaultOutputs = { defaultOutputs = {
lib = import ./lib.nix;
apps = import ./apps.nix; apps = import ./apps.nix;
checks = import ./checks.nix args; checks = import ./checks.nix args;
devShells = import ./devShells.nix; devShells = import ./devShells.nix;

33
nix/output/lib.nix Normal file
View file

@ -0,0 +1,33 @@
{ lib, ... }:
with lib;
{
config.outputKinds = [
(_: {
options = {
lib = mkOption {
type = with types; anything;
description = ''
Exported from the flake at `.lib` and `.lib.<system>` respectively.
Arbitrary shape. Intended for use in "library" flakes, exporting the Nix
expressions.
'';
};
};
outputs =
{
config,
hasSystem,
system,
...
}:
if hasSystem then
{
lib.${system} = config.lib;
}
else
{
lib = config.lib;
};
})
];
}

36
tests/export-lib.nix Normal file
View file

@ -0,0 +1,36 @@
{
checkSystem,
modularFlake,
...
}:
let
noSystem = {
ans = 42;
str = "no system, no pkgs";
};
yesSystem = {
ans = 43;
str = "we have nixpkgs here";
};
in
{
outputs = with modularFlake.defaultOutputs; [ lib ];
modules = [
(
{
lib,
hasSystem,
...
}:
{
lib = if hasSystem then yesSystem else noSystem;
}
)
];
fails = false;
expectedOutput = {
lib = noSystem // {
${checkSystem} = yesSystem;
};
};
}