mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 16:10:05 +01:00
Initial refactoring for kubenix 2.0
Implemented features: - Improved and reimplemented submodule system, independent of kubernetes module definitions - Pre-generated kubernetes module definitions with explicit API versioning support
This commit is contained in:
parent
7287c4ed9e
commit
3dc1e615c4
20 changed files with 207916 additions and 751 deletions
52
lib.nix
52
lib.nix
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
with lib;
|
||||
|
||||
rec {
|
||||
let
|
||||
in rec {
|
||||
mkOptionDefault = mkOverride 1001;
|
||||
|
||||
mkAllDefault = value: priority:
|
||||
if isAttrs value
|
||||
then mapAttrs (n: v: mkAllDefault v priority) value
|
||||
|
|
@ -12,12 +15,47 @@ rec {
|
|||
|
||||
else mkOverride priority value;
|
||||
|
||||
moduleToAttrs = value:
|
||||
if isAttrs value
|
||||
then mapAttrs (n: v: moduleToAttrs v) (filterAttrs (n: v: !(hasPrefix "_" n) && v != null) value)
|
||||
loadYAML = path: importJSON (pkgs.runCommand "yaml-to-json" {
|
||||
} "${pkgs.remarshal}/bin/remarshal -i ${path} -if yaml -of json > $out");
|
||||
|
||||
else if isList value
|
||||
then map (v: moduleToAttrs v) value
|
||||
toYAML = config: builtins.readFile (pkgs.runCommand "to-yaml" {
|
||||
buildInputs = [pkgs.remarshal];
|
||||
} ''
|
||||
remarshal -i ${pkgs.writeText "to-json" (builtins.toJSON config)} -if json -of yaml > $out
|
||||
'');
|
||||
|
||||
else value;
|
||||
toBase64 = value:
|
||||
builtins.readFile
|
||||
(pkgs.runCommand "value-to-b64" {} "echo -n '${value}' | ${pkgs.coreutils}/bin/base64 -w0 > $out");
|
||||
|
||||
exp = base: exp: foldr (value: acc: acc * base) 1 (range 1 exp);
|
||||
|
||||
octalToDecimal = value:
|
||||
(foldr (char: acc: {
|
||||
i = acc.i + 1;
|
||||
value = acc.value + (toInt char) * (exp 8 acc.i);
|
||||
}) {i = 0; value = 0;} (stringToCharacters value)).value;
|
||||
|
||||
importModule = {module ? null, modules ? [module], config}: let
|
||||
specialArgs = {
|
||||
kubenix = import ./. { inherit pkgs lib; };
|
||||
parentConfig = config;
|
||||
};
|
||||
|
||||
isModule = hasAttr "module" config;
|
||||
|
||||
moduleDefinition = (evalModules {
|
||||
inherit modules specialArgs;
|
||||
check = false;
|
||||
}).config.module.definition;
|
||||
in mkOption {
|
||||
description = "Module ${moduleDefinition.name} version ${moduleDefinition.version}";
|
||||
type = submoduleWithSpecialArgs ({name, ...}: let
|
||||
name' = if isModule then "${config.module.name}-${name}" else name;
|
||||
in {
|
||||
imports = modules;
|
||||
module.name = mkOptionDefault name';
|
||||
}) specialArgs;
|
||||
default = {};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue