chore(buildClan): make buildClan and flake-parts return identical outputs
This commit is contained in:
@@ -11,9 +11,24 @@ let
|
|||||||
inherit (lib) types;
|
inherit (lib) types;
|
||||||
|
|
||||||
buildClanModule = clan-core.clanLib.buildClanModule;
|
buildClanModule = clan-core.clanLib.buildClanModule;
|
||||||
|
|
||||||
|
publicAttrs = import ../lib/build-clan/public.nix;
|
||||||
|
# Create output options only for listed attributes
|
||||||
|
outputModule = {
|
||||||
|
clan = lib.genAttrs publicAttrs.clan (
|
||||||
|
name:
|
||||||
|
config.clan.clanInternals.${name}
|
||||||
|
or (throw "Output: clanInternals.${name} not found. Check: ${config.file}")
|
||||||
|
);
|
||||||
|
topLevel = {
|
||||||
|
options = lib.genAttrs publicAttrs.topLevel (_: lib.mkOption { });
|
||||||
|
config = lib.genAttrs publicAttrs.topLevel (
|
||||||
|
name: config.clan.${name} or (throw "Output: clan.${name} not found. See: ${config.file}")
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
||||||
options.clan = lib.mkOption {
|
options.clan = lib.mkOption {
|
||||||
default = { };
|
default = { };
|
||||||
type = types.submoduleWith {
|
type = types.submoduleWith {
|
||||||
@@ -27,16 +42,16 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
options.flake = flake-parts-lib.mkSubmoduleOptions {
|
options.flake =
|
||||||
|
flake-parts-lib.mkSubmoduleOptions {
|
||||||
clan = lib.mkOption { type = types.raw; };
|
clan = lib.mkOption { type = types.raw; };
|
||||||
clanInternals = lib.mkOption { type = types.raw; };
|
}
|
||||||
};
|
// outputModule.topLevel.options;
|
||||||
config = {
|
config = {
|
||||||
flake.clan = {
|
flake = {
|
||||||
inherit (config.clan.clanInternals) templates;
|
clan = outputModule.clan;
|
||||||
};
|
} // outputModule.topLevel.config;
|
||||||
flake.clanInternals = config.clan.clanInternals;
|
|
||||||
flake.nixosConfigurations = config.clan.nixosConfigurations;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_file = __curPos.file;
|
_file = __curPos.file;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,7 @@
|
|||||||
lib,
|
lib,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
}:
|
}:
|
||||||
let
|
|
||||||
clanResultAttributes = [
|
|
||||||
"clanInternals"
|
|
||||||
"nixosConfigurations"
|
|
||||||
];
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
inherit clanResultAttributes;
|
|
||||||
flakePartsModule = {
|
flakePartsModule = {
|
||||||
imports = [
|
imports = [
|
||||||
./interface.nix
|
./interface.nix
|
||||||
@@ -25,6 +18,7 @@ in
|
|||||||
|
|
||||||
# Arguments of the first function
|
# Arguments of the first function
|
||||||
- clan-core: Self, provided by our flake-parts module
|
- clan-core: Self, provided by our flake-parts module
|
||||||
|
- publicAttrs: { clan :: List Str, topLevel :: List Str } Publicly exported attribute names
|
||||||
|
|
||||||
# Arguments of the second function (aka 'buildClan')
|
# Arguments of the second function (aka 'buildClan')
|
||||||
- self: Reference to the users flake
|
- self: Reference to the users flake
|
||||||
@@ -34,13 +28,13 @@ in
|
|||||||
|
|
||||||
# Returns
|
# Returns
|
||||||
|
|
||||||
A module evaluation containing '.config' and '.options'
|
Public attributes of buildClan. As specified in publicAttrs.
|
||||||
|
|
||||||
NOTE:
|
|
||||||
The result might export all kinds of options at the '.config' top level.
|
|
||||||
*/
|
*/
|
||||||
buildClanWith =
|
buildClanWith =
|
||||||
{ clan-core }:
|
{
|
||||||
|
clan-core,
|
||||||
|
publicAttrs ? import ./public.nix,
|
||||||
|
}:
|
||||||
{
|
{
|
||||||
## Inputs
|
## Inputs
|
||||||
self ? lib.warn "Argument: 'self' must be set when using 'buildClan'." null, # Reference to the current flake
|
self ? lib.warn "Argument: 'self' must be set when using 'buildClan'." null, # Reference to the current flake
|
||||||
@@ -65,12 +59,20 @@ in
|
|||||||
inherit specialArgs;
|
inherit specialArgs;
|
||||||
};
|
};
|
||||||
rest = builtins.removeAttrs attrs [ "specialArgs" ];
|
rest = builtins.removeAttrs attrs [ "specialArgs" ];
|
||||||
in
|
result = eval {
|
||||||
eval {
|
|
||||||
imports = [
|
imports = [
|
||||||
rest
|
rest
|
||||||
# implementation
|
# implementation
|
||||||
./module.nix
|
./module.nix
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
clan = lib.genAttrs publicAttrs.clan (
|
||||||
|
name:
|
||||||
|
result.clanInternals.${name}
|
||||||
|
or (throw "Output: clanInternals.${name} not found. Check: ${result.file}")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// lib.filterAttrs (name: _v: builtins.elem name publicAttrs.topLevel) result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ in
|
|||||||
# TODO: unify this interface
|
# TODO: unify this interface
|
||||||
# We should have only clan.modules. (consistent with clan.templates)
|
# We should have only clan.modules. (consistent with clan.templates)
|
||||||
inherit (clan-core) clanModules clanLib;
|
inherit (clan-core) clanModules clanLib;
|
||||||
modules = clan-core.modules;
|
modules = clan-core.clanModules;
|
||||||
|
|
||||||
inherit inventoryFile;
|
inherit inventoryFile;
|
||||||
inventoryValuesPrios =
|
inventoryValuesPrios =
|
||||||
|
|||||||
17
lib/build-clan/public.nix
Normal file
17
lib/build-clan/public.nix
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
Publicly exported attribute names
|
||||||
|
These are mapped from 'options.clan.{name}' into 'flake.{name}'
|
||||||
|
For example "clanInternals" will be exposed as "flake.clan.clanInternals"
|
||||||
|
This list is used to guarantee equivalent attribute sets for both flake-parts and buildClan users.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
# flake.clan.{name} <- clanInternals.{name}
|
||||||
|
clan = [
|
||||||
|
"templates"
|
||||||
|
];
|
||||||
|
# flake.{name} <- clan.{name}
|
||||||
|
topLevel = [
|
||||||
|
"clanInternals"
|
||||||
|
"nixosConfigurations"
|
||||||
|
];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user