mirror of
https://git.mediani.de/mirrors_public/oddlama_nixos-extra-modules.git
synced 2025-10-10 22:10:38 +02:00
feat: upstream node generation
This commit is contained in:
parent
f1a3f0303b
commit
93b08971cf
9 changed files with 268 additions and 48 deletions
74
flake-modules/globals.nix
Normal file
74
flake-modules/globals.nix
Normal file
|
@ -0,0 +1,74 @@
|
|||
{
|
||||
inputs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
options.globals = {
|
||||
optModules = mkOption {
|
||||
type = types.listOf types.deferredModule;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Modules defining global options.
|
||||
These should not include any config only option declaration.
|
||||
Will be included in the exported nixos Modules from this flake to be included
|
||||
into the host evaluation.
|
||||
'';
|
||||
};
|
||||
defModules = mkOption {
|
||||
type = types.listOf types.deferredModule;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Modules configuring global options.
|
||||
These should not include any option declaration use {option}`optModules` for that.
|
||||
Will not included in the exported nixos Modules.
|
||||
'';
|
||||
};
|
||||
attrkeys = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
The toplevel attrNames for your globals.
|
||||
Make sure the keys of this attrset are trivially evaluatable to avoid infinite recursion,
|
||||
therefore we inherit relevant attributes from the config.
|
||||
'';
|
||||
};
|
||||
};
|
||||
config.flake = flakeSubmod: {
|
||||
globals =
|
||||
let
|
||||
globalsSystem = lib.evalModules {
|
||||
prefix = [ "globals" ];
|
||||
specialArgs = {
|
||||
inherit (inputs.self.pkgs.x86_64-linux) lib;
|
||||
inherit inputs;
|
||||
inherit (flakeSubmod.config) nodes;
|
||||
};
|
||||
modules =
|
||||
config.globals.optModules
|
||||
++ config.globals.defModules
|
||||
++ [
|
||||
../modules/globals.nix
|
||||
(
|
||||
{ lib, ... }:
|
||||
{
|
||||
globals = lib.mkMerge (
|
||||
lib.concatLists (
|
||||
lib.flip lib.mapAttrsToList flakeSubmod.config.nodes (
|
||||
name: cfg:
|
||||
builtins.addErrorContext "while aggregating globals from nixosConfigurations.${name} into flake-level globals:" cfg.config._globalsDefs
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
)
|
||||
];
|
||||
};
|
||||
in
|
||||
lib.genAttrs config.globals.attrkeys (x: globalsSystem.config.globals.${x});
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue