feat: add secrets module

idea: have sops encrypted secret yamls, specify them in Nix, get all
secret yamls in a single directory to push into oci repo for flux to use
This commit is contained in:
technofab 2025-04-04 16:18:31 +02:00
parent 0b7f99f81e
commit b0c8d8b38e
2 changed files with 40 additions and 0 deletions

37
lib/secretsModule.nix Normal file
View file

@ -0,0 +1,37 @@
{
config,
pkgs,
lib,
...
}: let
inherit (lib) mkOption types;
in {
options.kubernetes = {
secrets = mkOption {
type = types.attrsOf types.path;
description = "sops encrypted secrets";
example = ''
{
"abc" = ./some-secret.sops.yaml;
}
'';
};
secretsCombined = mkOption {
internal = true;
type = types.package;
description = "All sops encrypted secret files in a directory";
};
};
config.kubernetes.secretsCombined = let
commands = builtins.concatStringsSep "\n" (
map (
secret: "ln -s ${builtins.getAttr secret config.kubernetes.secrets} $out/${secret}.yaml"
)
(builtins.attrNames config.kubernetes.secrets)
);
in
pkgs.runCommand "nixlets-secrets-combined" {} ''
mkdir -p $out
${commands}
'';
}