mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 08:00:06 +01:00
feat: add file module
This commit is contained in:
parent
76b8053b27
commit
ddfdd8d090
2 changed files with 74 additions and 0 deletions
|
|
@ -4,6 +4,7 @@
|
|||
submodules = ./submodules.nix;
|
||||
submodule = ./submodule.nix;
|
||||
helm = ./helm.nix;
|
||||
files = ./files.nix;
|
||||
docker = ./docker.nix;
|
||||
testing = ./testing;
|
||||
test = ./testing/test-options.nix;
|
||||
|
|
|
|||
73
modules/files.nix
Normal file
73
modules/files.nix
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
with lib; let
|
||||
cfg = config.kubernetes.files;
|
||||
|
||||
importMultiDocumentYAML = path:
|
||||
importJSON (pkgs.runCommand "yaml-to-json" { } ''
|
||||
${pkgs.yq}/bin/yq -Scs . ${path} > $out
|
||||
'');
|
||||
|
||||
parseApiVersion = apiVersion:
|
||||
let
|
||||
splitted = splitString "/" apiVersion;
|
||||
in
|
||||
{
|
||||
group =
|
||||
if length splitted == 1
|
||||
then "core"
|
||||
else head splitted;
|
||||
version = last splitted;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.kubernetes.files = mkOption {
|
||||
description = "Attribute set of YAML files to import";
|
||||
type = types.attrsOf (types.submodule ({ config, name, ... }: {
|
||||
options = {
|
||||
name = mkOption {
|
||||
description = "Name of the file";
|
||||
type = types.str;
|
||||
default = name;
|
||||
};
|
||||
|
||||
src = mkOption {
|
||||
description = "File to use";
|
||||
type = types.package;
|
||||
};
|
||||
|
||||
overrides = mkOption {
|
||||
description = "Overrides to apply to all of the file's resources";
|
||||
type = types.listOf types.unspecified;
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
objects = mkOption {
|
||||
description = "Parsed kubernetes objects";
|
||||
type = types.listOf types.attrs;
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
config.objects = importMultiDocumentYAML config.src;
|
||||
}));
|
||||
default = { };
|
||||
};
|
||||
|
||||
config = {
|
||||
kubernetes.api.resources = mkMerge (flatten (mapAttrsToList
|
||||
(_: file: map
|
||||
(object:
|
||||
let
|
||||
apiVersion = parseApiVersion object.apiVersion;
|
||||
inherit (object.metadata) name;
|
||||
in
|
||||
{
|
||||
"${apiVersion.group}"."${apiVersion.version}".${object.kind}."${name}" = mkMerge ([
|
||||
object
|
||||
]
|
||||
++ file.overrides);
|
||||
})
|
||||
file.objects
|
||||
)
|
||||
cfg));
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue